[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Sorting and re-ordering down a hierarchy

Subject: Re: Sorting and re-ordering down a hierarchy
From: David Ohlemacher <ohlemacher@xxxxxxx>
Date: Fri, 18 Jul 2003 11:45:54 -0400
ohlemacher david
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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.