Re: [xsl] sibling sorting

Subject: Re: [xsl] sibling sorting
From: "Ganesh Babu N nbabuganesh@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 31 May 2018 13:10:11 -0000
Thanks Martin,

this worked like a charm.

Regards,
Ganesh

On Thu, May 31, 2018 at 6:19 PM, Martin Honnen martin.honnen@xxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> On 31.05.2018 14:41, Ganesh Babu N nbabuganesh@xxxxxxxxx wrote:
>
>> Dear All,
>>
>> Here is my XML:
>>                 <descriptor>
>>                    <mainterm weight="a">dexmedetomidine</mainterm>
>>                    <link>zdverse drug reaction - disease</link>
>>                    <sublink>xerostomia</sublink>
>>                    <sublink>nausea</sublink>
>>                    <link>drug therapy</link>
>>                    <sublink>respiration depression</sublink>
>>                  </descriptor>
>>
>> The required output is:
>>
>>                 <descriptor>
>>                    <mainterm weight="a">dexmedetomidine</mainterm>
>>                    <link>drug therapy</link>
>>                    <sublink>respiration depression</sublink>
>>                    <link>zdverse drug reaction - disease</link>
>>                    <sublink>nausea</sublink>
>>                    <sublink>xerostomia</sublink>
>>                  </descriptor>
>>
>> My XSLT:
>>
>>      <xsl:template match="ani:descriptor">
>>          <xsl:copy>
>>              <xsl:copy-of select="@*"/>
>>              <xsl:apply-templates>
>>                  <xsl:sort select="ani:link|ani:sublink"
>> order="ascending" data-type="text"/>
>>              </xsl:apply-templates>
>>          </xsl:copy>
>>      </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