Skip to content

Instantly share code, notes, and snippets.

@jindrichmynarz
Created September 20, 2016 20:39
Show Gist options
  • Select an option

  • Save jindrichmynarz/dd4c458f65cd3b3bf7adefa10e9cea7c to your computer and use it in GitHub Desktop.

Select an option

Save jindrichmynarz/dd4c458f65cd3b3bf7adefa10e9cea7c to your computer and use it in GitHub Desktop.
Summarizes hierarchical structure of an XML document
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output encoding="UTF-8" indent="yes" method="xml" />
<xsl:template match="/*">
<xsl:element name="{name()}">
<xsl:call-template name="group"/>
</xsl:element>
</xsl:template>
<xsl:template name="group">
<xsl:for-each-group select="*" group-by="name()">
<xsl:sort select="current-grouping-key()"/>
<xsl:element name="{current-grouping-key()}">
<xsl:call-template name="group"/>
</xsl:element>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment