Skip to content

Instantly share code, notes, and snippets.

@donatasnicequestion
Created August 24, 2012 12:03
Show Gist options
  • Save donatasnicequestion/3449847 to your computer and use it in GitHub Desktop.
Save donatasnicequestion/3449847 to your computer and use it in GitHub Desktop.
Count of elements in a document as desribed in http://www.dpawson.co.uk/xsl/sect2/N2018.html#d3308e250
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="gis" match="*" use="name()"/>
<xsl:template match="/">
<table>
<xsl:apply-templates/>
<xsl:message>done reading</xsl:message>
<xsl:for-each select="//*[generate-id(.)=generate-id(key('gis',name(.))[1])]">
<xsl:sort select="name()"/>
<tr>
<td><xsl:value-of select="name(.)"/></td>
<td><xsl:value-of select="count(key('gis',name(.)))"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment