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

Re: sibling sorting

Subject: Re: sibling sorting
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 31 May 2018 12:48:53 -0000
Re:  sibling sorting
On 31.05.2018 14:41, Ganesh Babu N nbabuganesh@xxxxxxxxx wrote:
Dear All,

Here is my XML:
 B B B B B B B B B B B B B B  <descriptor>
 B B B B B B B B B B B B B B B B B  <mainterm weight="a">dexmedetomidine</mainterm>
 B B B B B B B B B B B B B B B B B  <link>zdverse drug reaction - disease</link>
 B B B B B B B B B B B B B B B B B  <sublink>xerostomia</sublink>
 B B B B B B B B B B B B B B B B B  <sublink>nausea</sublink>
 B B B B B B B B B B B B B B B B B  <link>drug therapy</link>
 B B B B B B B B B B B B B B B B B  <sublink>respiration depression</sublink>
 B B B B B B B B B B B B B B B  </descriptor>

The required output is:

 B B B B B B B B B B B B B B  <descriptor>
 B B B B B B B B B B B B B B B B B  <mainterm weight="a">dexmedetomidine</mainterm>
 B B B B B B B B B B B B B B B B B  <link>drug therapy</link>
 B B B B B B B B B B B B B B B B B  <sublink>respiration depression</sublink>
 B B B B B B B B B B B B B B B B B  <link>zdverse drug reaction - disease</link>
 B B B B B B B B B B B B B B B B B  <sublink>nausea</sublink>
 B B B B B B B B B B B B B B B B B  <sublink>xerostomia</sublink>
 B B B B B B B B B B B B B B B  </descriptor>

My XSLT:

B B B <xsl:template match="ani:descriptor">
B B B B B B <xsl:copy>
B B B B B B B B B <xsl:copy-of select="@*"/>
B B B B B B B B B <xsl:apply-templates>
B B B B B B B B B B B B <xsl:sort select="ani:link|ani:sublink" order="ascending" data-type="text"/>
B B B B B B B B B </xsl:apply-templates>
B B B B B B </xsl:copy>
B B B </xsl:template>


In the XML both the link and sublink elements are sibling to each other, first links have to sorted then sublink. With the above XSLT i am getting the output same as input. Help in this regard is appreciated.

Are there any possible other elements involved other than that "mainterm" element before the "link" and "sublink"? If not and if you can use XSLT 2 or 3 then use



<xsl:template match="ani:descriptor">
<xsl:copy>
<xsl:copy-of select="@*, ani:mainterm"/>
<xsl:for-each-group select="* except mainterm" group-starting-with="ani:link">
<xsl:sort select="."/>
<xsl:copy-of select="."/>
<xsl:perform-sort select="current-group() except .">
<xsl:sort select="."/>
</xsl:perform-sort>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>


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.