File: Data.xml
<list>
<freezer>
<element>peas</element>
<element>green beans</element>
<element>pot pie</element>
<element>ice cream</element>
</freezer>
<bakery>
<element>rolls</element>
<element>jelly doughnuts</element>
<element>bread</element>
</bakery>
<produce>
<element>bananas</element>
<element>kumquats</element>
<element>apples</element>
</produce>
</list>
File: Transform.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="list">
<xsl:copy>
<xsl:apply-templates select="*">
<xsl:sort select="name()" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="element">
<xsl:sort />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="element">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<list>
<bakery>
<element>bread</element>
<element>jelly doughnuts</element>
<element>rolls</element>
</bakery>
<freezer>
<element>green beans</element>
<element>ice cream</element>
<element>peas</element>
<element>pot pie</element>
</freezer>
<produce>
<element>apples</element>
<element>bananas</element>
<element>kumquats</element>
</produce>
</list>
|