![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I got a page that loads a xml file into a treeview control. I want it to sort the data before sending it to the treeview control is that possible? root level1 name="" src="" order="0" level1.2 .. order="5" level1.2 .. order="3" level1.2 .. order="2" level1 .. order="2" level1 .. order="1" I want first level1 nodes to be sorted accorded to the order column. Then i want all sub levels to be sorted, sor 1.2 should be sorted with only 1.2 and 1.3 should be sorte with only 1.3. |
utput method="xml" indent="yes" />
#3
| |||
| |||
|
| Patrick wrote: I got a page that loads a xml file into a treeview control. I want it to sort the data before sending it to the treeview control is that possible? root level1 name="" src="" order="0" level1.2 .. order="5" level1.2 .. order="3" level1.2 .. order="2" level1 .. order="2" level1 .. order="1" I want first level1 nodes to be sorted accorded to the order column. Then i want all sub levels to be sorted, sor 1.2 should be sorted with only 1.2 and 1.3 should be sorte with only 1.3. An XSLT stylesheet can sort XML documents, for instance if the input XML is e.g. root level1 name="" src="" order="0" level1.2 order="5" / level1.2 order="3" / level1.2 order="2" / /level1 level1 order="2" / level1 order="1" / /root then this stylesheet ?xml version="1.0" encoding="UTF-8"? xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xsl utput method="xml" indent="yes" /xsl:template match="root" xsl:copy xsl:apply-templates select="@*" / xsl:apply-templates select="level1" xsl:sort select="@order" data-type="number" order="ascending" / /xsl:apply-templates /xsl:copy /xsl:template xsl:template match="level1" xsl:copy xsl:apply-templates select="@*" / xsl:apply-templates select="level1.2" xsl:sort select="@order" data-type="number" order="ascending" / /xsl:apply-templates /xsl:copy /xsl:template xsl:template match="level1.2" xsl:copy xsl:apply-templates select="@*" / /xsl:copy /xsl:template xsl:template match="@*" xsl:copy / /xsl:template /xsl:stylesheet creates this sorted output ?xml version="1.0" encoding="UTF-8"? root level1 name="" src="" order="0" level1.2 order="2"/ level1.2 order="3"/ level1.2 order="5"/ /level1 level1 order="1"/ level1 order="2"/ /root -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |