Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to apply XSL to alphabetize an XML doc based on an element name?

Status
Not open for further replies.

MobyToby

Programmer
Jul 24, 2002
2
US
Hi there,

This seems like it would be fairly easy, but I can't figure it out. I want to take an XML doc, run it through an XSL transformation, and have the same XML doc on the other side, but just alphabetized on an element of my choosing.

So for instance:
Code:
<excellent>
  <person name=Bill/>
  <person name=Ted/>
  <person name=Abe/>
</excellent>

Should become (obviously):
Code:
<excellent>
  <person name=Abe/>
  <person name=Bill/>
  <person name=Ted/>
</excellent>

I know I can use the XSL element
Code:
<xsl:copy-of>
to get a copy of the whole tree, but how do I alphabetize it in the process? I've tried all flavors of
Code:
<xsl:sort>
but that is only valid after a
Code:
<xsl:for-each>
or
Code:
<xsl:apply-templates>
.

Thanks very much in advance!
-Toby
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top