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

RE: Sorting XML Elements alphabetically

Subject: RE: Sorting XML Elements alphabetically
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 13 Feb 2004 21:25:38 -0000
sorting xml
You want a variation of the identity template:

<xsl:template match="*">
 <xsl:copy>
 <xsl:copy-of select="@*"/>
 <xsl:apply-templates select="*">
   <xsl:sort select="name()"/>
 </xsl:apply-templates>
</xsl:template>

Not tested.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Peter Loh Yoon Chao
> Sent: 13 February 2004 12:03
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Sorting XML Elements alphabetically
> 
> 
> Hi,
> 
> I am a beginner to the world of XSL and related technologies. 
>  I have an XML document with an arbitrarily deep tree 
> structure where the elements are in random order, e.g.
> 
> <school>
>   <teacher>
>     <subject>maths</subject>
>     <name>tom hart</name>
>   </teacher>
>   <student>
>     <age>12</age>
>     <name>dick jones</name>
>     <gender>male</gender>
>   </student>
> </school>
> 
> I would like to produce XML output from this source where the 
> elements are sorted alphabetically at each level, i.e.
> 
> <school>
>     <student>
>       <age>12</age>
>       <gender>male</gender>
>       <name>dick jones</name>
>     </student>
>   <teacher>
>     <name>tom hart</name>
>     <subject>maths</subject>
>   </teacher>
> </school>
> 
> Is there an XSL transformation that can help me achieve this? 
>  I experimented with different ways of using <xsl:sort> but 
> so far, I seem to have been only sorting data rather than the 
> elements themselves.  Any help would be appreciated.  Thanks.
> 
> Peter
> 
> 
>  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.