Created
September 17, 2021 14:45
-
-
Save jdkirkwood/d5f50c38584cbcb278670afac33c75d0 to your computer and use it in GitHub Desktop.
XML sort template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- https://stackoverflow.com/a/16305113/7643972 --> | |
<!-- <?xml-stylesheet type="text/xsl" href="../../../sort-xml.xsl"?> --> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output indent="yes" /> | |
<xsl:strip-space elements="*"/> | |
<xsl:template match="text()[not(string-length(normalize-space()))]"/> | |
<xsl:template match="/*"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*" /> | |
<xsl:apply-templates> | |
<!-- sort key: "id" attribute on first level elements --> | |
<xsl:sort select="@id" /> | |
</xsl:apply-templates> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template match="@*|node()"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*|node()"/> | |
</xsl:copy> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment