i do have a treeview xml that i want to sort with xsl, but it seems i'm missing something:
The structure of my xml is something like this:
<treeview>
<treenode>
<caption>Directory Z</caption>
<nodes>
<treenode>
<caption>File B</caption>
</treenode>
<treenode>
<caption>File Z</caption>
</treenode>
<treenode>
<caption>File A</caption>
</treenode>
</nodes>
</treenode>
<treenode>
<caption>Directory G</caption>
<nodes>
<treenode>
<caption>File F</caption>
</treenode>
<treenode>
<caption>File O</caption>
</treenode>
<treenode>
<caption>File B</caption>
</treenode>
</nodes>
</treenode>
</treeview>
I tried the following xsl to perform a sorting:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/*">
<treeview>
<xsl:apply-templates select="treenode">
<xsl:sort select="caption" data-type="text" order="ascending"/>
<xsl:sort/>
</xsl:apply-templates>
</treeview>
</xsl:template>
<xsl:template match="treenode">
<xsl:copy-of select="."/>
<xsl:apply-templates select="nodes/treenode">
<xsl:sort select="caption" data-type="text" order="descending"/>
<xsl:sort/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
I end up with the files being added to the root node, but i want the directories to be sorted ascending and the files in each directory descending.
Thanks for your help :)
No comments:
Post a Comment