xsl-list
[Top] [All Lists]

Sorting XML Elements alphabetically

2004-02-13 05:02:54
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



<Prev in Thread] Current Thread [Next in Thread>