Created
July 23, 2013 14:02
-
-
Save alicraigmile/6062574 to your computer and use it in GitHub Desktop.
Get all unique elements in a document
This file contains hidden or 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"?> | |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | |
<xsl:output method="xml"/> | |
<xsl:key name="elements" match="*" use="name()"/> | |
<xsl:template match="/"> | |
<xsl:for-each select="//*[generate-id(.)=generate-id(key('elements',name())[1])]"> | |
<xsl:sort select="name()"/> | |
<xsl:for-each select="key('elements', name())"> | |
<xsl:if test="position()=1"> | |
<xsl:element name="element"> | |
<xsl:attribute name="name"> | |
<xsl:value-of select="name()"/> | |
</xsl:attribute> | |
<xsl:attribute name="count"> | |
<xsl:value-of select="count(//*[name()=name(current())])"/> | |
</xsl:attribute> | |
</xsl:element> | |
</xsl:if> | |
</xsl:for-each> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment