You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Cory Isaacson <ci...@capita2.com> on 2001/02/01 19:30:54 UTC
Dynamic Sort XSLT
We're trying to make a dynamic sort XSLT document, which is built as a DOM
on the fly. We start with a simple template document that looks like this:
<!-- Output the fw:dataSetData element.-->
<xsl:template match="/">
<fw:dataSetData>
<xsl:apply-templates select="/fw:dataSet/fw:dataSetData"/>
</fw:dataSetData>
</xsl:template>
<!-- Loop each row and sort.-->
<xsl:template match="fw:dataSet/fw:dataSetData">
<xsl:for-each select="./fw:row">
<!-- Place sort elements here.-->
<!-- Copy each row.-->
<xsl:copy>
<xsl:apply-templates select="@*|*|text()"/>
</xsl:copy>
</xsl:for-each>
</xsl:template>
<xsl:template match=".|@*|*|text()">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Then we parse it into a DOM, and insert the sort element using the Xerces
createElementNS method:
<xsl:for-each select="./fw:row">
<!-- Place sort elements here.-->
<xsl:sort order="ascending" data-type="number"
select="./fw:column[@index='5']"/>
....
When we test the final sort doc as a text file it works fine. When we do it
as a DOM above, it doesn't do the sort, and outputs the '<xsl:sort...>'
before each output element we are copying. So it appears that the <xsl:sort>
is being viewed as output text instead of an xsl command? When we print out
the XSLT from the DOM it looks just like our text document that works.
Any ideas?
Thanks,
Cory