Re: [xsl] muliple level sorting using xsl:sort

Subject: Re: [xsl] muliple level sorting using xsl:sort
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Mon, 05 Sep 2005 11:43:03 +0200

Tempore 11:19:01, die 09/05/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Aravind J <aravindjp@xxxxxxxxx>:

when i tried to sort the data using
 <xsl:for-each select="Part">
<xsl:sort data-type="number"
select="descendant-or-self::code/name"/> it is doing e
first level sorting correctly, ie data is sorted in
1,2,5 order (code/name) . but sub parts of <part> 5 ie
5-3 and 5-4 are not getting sorted , similarly for
children of 5-4 also.

Any idea how we can sort sub parts ie (child <Part> )
also in this case .

Somehow, you'd need to extract the last number of the 'n(-n)*' sequence, One possible solution is to rely on the fact that the sequence is the same as the previous level + '-n' :

"substring(code/name,string-length(ancestor::Part[1]/code/name) + 1 + boolean(ancestor::Part))"

e.g. this stylesheet:

<xsl:stylesheet xmlns:xsl=""; version="1.0">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="AAAA|child">
<xsl:for-each select="Part">
	<xsl:sort data-type="number"
	<xsl:copy-of select="code/name"/>
	<xsl:apply-templates select="child"/>


Will return this result:

regards, -- Joris Gillis ( Ceterum censeo XML omnibus esse utendum

Current Thread