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="{(_at_)name}" importance="{(_at_)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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--