Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XSL + XML => sort nodes by ids

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 5/10/2009 6:58:00 PM
Nicopil@mi wrote:
> Hi everybody, i would like to sort alphabetically  the "rep" items by 
> their id parameter.
> Could you help me to make the xsl file please ?
> 
> <repertoires>
>   <rep id=nomdurep1>
>     <param .... />
>     <param .... />
>   </rep>
>   <rep id=nomdurep2>
>     <param .... />
>     <param .... />
>   </rep>
>   <rep id=nomdurep3>
>        <rep id=nomdusousrep1>
>          <param .... />
>          <param .... />
>       </rep>
>        <rep id=nomdusousrep2>
>          <param .... />
>          <param .... />
>       </rep>
>      <param .... />
>      <param .... />
>   </rep>
> </repertoires>

Consider to post well-formed snippets of XML, otherwise we can't test 
our solutions against your sample data.
So here is some untested suggestion:

   <xsl:template match="reportoires">
     <xsl:copy>
       <xsl:apply-templates select="rep">
         <xsl:sort select="@id"/>
       </xsl:apply-templates/>
     </xsl:copy>
   </xsl:template>

   <xsl:template match="rep">
     <xsl:copy>
       <xsl:copy-of select="@*"/>
       <xsl:apply-templates select="rep">
         <xsl:sort select="@id"/>
       </xsl:apply-templates/>
       <xsl:copy-of select="param"/>
     </xsl:copy>
   </xsl:template>

That solution assumes you want to sort the 'rep' children of the 
'repertoires' element by their 'id' attribute value and then assumes 
that you want sort the 'rep' children of each 'rep' element again by 
their 'id' attribute value.

You haven't really explained what you want to to with the nested 'rep' 
elements so the above is just an assumption of what you might want.

-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent