Wednesday, June 10, 2009

Sort a Whole XML Document using XSL

This is a variation of an identity transformation that sorts all nodes and attributes alphabetically.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:output method="xml" omit-xml-declaration="no"/>

<xsl:template match="@*|node()" priority="1">
<xsl:copy>
<xsl:apply-templates select="@*|node()">
<xsl:sort select="name()" data-type="text" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

No comments:

Labels

Blog Archive

Contributors