|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Sort/Ordering Problems
I am having difficulty maintaining the hierarchy in my XML when I try and
reorder/sort the levels. I am convinced it is issues with both my XPath and my
inexperience with XSLT. Please advise.
My XML looks like:
<Entry>
<Entry name="A" importance="2">
<Entry name="B" importance="2">
<Entry name="C" importance="1"></Entry>
<Entry name="D" importance="2"></Entry>
</Entry>
<Entry name="E" importance="1">
<Entry name="F" importance="2"></Entry>
<Entry name="G" importance="1"></Entry>
</Entry>
</Entry>
<Entry name="H" importance="1">
<Entry name="I" importance="1">
<Entry name="J" importance="1"></Entry>
<Entry name="K" importance="2"></Entry>
</Entry>
<Entry name="L" importance="2">
<Entry name="M" importance="2"></Entry>
<Entry name="N" importance="1"></Entry>
</Entry>
</Entry>
</Entry>
I want to sort by importance with each "level" being sorted individually so that
the XML looks like:
<Entry>
<Entry name="H" importance="1">
<Entry name="I" importance="1">
<Entry name="J" importance="1"></Entry>
<Entry name="K" importance="2"></Entry>
</Entry>
<Entry name="L" importance="2">
<Entry name="N" importance="1"></Entry>
<Entry name="M" importance="2"></Entry>
</Entry>
</Entry>
<Entry name="A" importance="2">
<Entry name="E" importance="1">
<Entry name="G" importance="1"></Entry>
<Entry name="F" importance="2"></Entry>
</Entry>
<Entry name="B" importance="2">
<Entry name="C" importance="1"></Entry>
<Entry name="D" importance="2"></Entry>
</Entry>
</Entry>
</Entry>
When I run this XSLT I get:
<Entry version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:for-each select="//Entry">
<xsl:sort select="@importance" data-type="number" order="ascending"/>
<Entry name="{@name}" importance="{@importance}"/>
</xsl:for-each>
</Entry>
<Entry version="1.0">
<Entry name="" importance=""/>
<Entry name="C" importance="1"/>
<Entry name="E" importance="1"/>
<Entry name="G" importance="1"/>
<Entry name="H" importance="1"/>
<Entry name="I" importance="1"/>
<Entry name="J" importance="1"/>
<Entry name="N" importance="1"/>
<Entry name="A" importance="2"/>
<Entry name="B" importance="2"/>
<Entry name="D" importance="2"/>
<Entry name="F" importance="2"/>
<Entry name="K" importance="2"/>
<Entry name="L" importance="2"/>
<Entry name="M" importance="2"/>
</Entry>
I understand the XPath entry is wrong, and I haven't found a differnt path that
gives me the output I want. That more than likely means I have a problem with
my XSLT initially and no matter what path I insert it will be bad. Hope someone
can help.
Ben Woline
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








