I am trying to programmtically insert an appendTo() method with jquery. I have a formatting stylesheet which formats an xml sheet, but I do it in a third HTML document using jquery and javascript. My original xml is in this format:
<guitars>
<guitar>
<model>AStrat</model>
<year>1978</year>
<name>Strat</name>
<price>2500</price>
</guitar>
</guitars>
and my stylesheet is like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<table id="guitarTable" border="1" width="200">
<tr class="header">
<th>Model</th>
<th>Year</th>
<th>Name</th>
<th>Price</th>
</tr>
<xsl:apply-templates select="/guitars/guitar">
</xsl:apply-templates>
</table>
</xsl:template>
<xsl:template match="guitar">
<tr>
<td> <xsl:value-of select="model" /> </td>
<td> <xsl:value-of select="year" /> </td>
<td> <xsl:value-of select="name"/> </td>
<td> <xsl:value-of select="price" /> </td>
</tr>
</xsl:template>
</xsl:stylesheet>
And here is my javascript. stylesheet
is the stylesheet above imported via ajax and I've checked works correctly.
var nodeToAppend = '<xsl:sort select="model" data-type="text"/>'
$(nodeToAppend).appendTo( $(stylesheet)
.find("xsl\\:apply-templates, apply-templates")
.first() );
But this doesn't seem to want to take. Later on, I apply the XSL to the XML via an XSLT processor. Any ideas what I'm doing wrong? Basically I want this line:
<xsl:apply-templates select="/guitars/guitar">
</xsl:apply-templates>
to become:
<xsl:apply-templates select="/guitars/guitar">
<xsl:sort select="model" data-type="text"/>
</xsl:apply-templates>
Thanks!