xsl-list
[Top] [All Lists]

Re: Sorting and re-ordering down a hierarchy

2003-07-18 08:45:54
Chris,
It may be possilble to do this. I am no expert in XSLT. My required output was a bit more complicated as well.
-d

Cole, Chris wrote:

Hello,
I'm struggling to re-organise my node tree.
My tree is something like this:

<input>
<node>
   <rank>2</rank>
   <node>
       <rank>88</rank>
   </node>
   <node>
       <rank>7</rank>
   </node>
   <node>
       <rank>66</rank>
   </node>
</node>
<node>
   <rank>1</rank>
   <node>
       <rank>3</rank>
   </node>
   <node>
       <rank>2</rank>
   </node>
   <node>
       <rank>1</rank>
   </node>
</node>
</input>

I need to reorganise the nodes so that they are organised in number order
down the nodes within their tree, so the output should be like this:
<output>
<node>
   <rank>1</rank>
   <node>
       <rank>7</rank>
   </node>
   <node>
       <rank>66</rank>
   </node>
   <node>
       <rank>88</rank>
   </node>
</node>
<node>
   <rank>2</rank>
   <node>
       <rank>1</rank>
   </node>
   <node>
       <rank>2</rank>
   </node>
   <node>
       <rank>3</rank>
   </node>
</node>
</output>
I can sort one level by using the code below, but I'm struggling to find a
way to re-order the second level within the first level (and the third level
later).

<xsl:template match="/input">
 <xsl:call-template name="ascending-numeric-sort-l1">
   <xsl:with-param name="seqnuml1" select="node/rank"/>
 </xsl:call-template>

</xsl:template>

<xsl:template name="ascending-numeric-sort-l1">
 <xsl:param name="seqnuml1"/>
 <xsl:for-each select="$seqnuml1">
   <xsl:sort select="." data-type="number" order="ascending"/>
   <xsl:copy-of select="parent::node()"/>
 </xsl:for-each>
</xsl:template>

Can anybody offer any advice please?
Thanks
Chris

XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list