Subject: [xsl] Sort/Ordering Problems From: "Benjamin Richard Woline" <valjean@xxxxxxxxxxx> Date: Wed, 20 Jul 2005 11:35:34 -0500 (CDT) |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] "Debugging" XSLT? Experie, Mukul Gandhi | Thread | Re: [xsl] Sort/Ordering Problems, David Carlisle |
[xsl] "Debugging" XSLT? Experience, Karl Koch | Date | RE: [xsl] Saxon8 beginner questions, Michael Kay |
Month |