Skip to content

Instantly share code, notes, and snippets.

@pdaengeli
Last active June 23, 2016 14:42
Show Gist options
  • Save pdaengeli/14b8f9313c4a6215320883f167546749 to your computer and use it in GitHub Desktop.
Save pdaengeli/14b8f9313c4a6215320883f167546749 to your computer and use it in GitHub Desktop.
XSLT: monitoring conversions wrt attributes and unhandled elements
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/">
<!-- ATTRIBUTES IN USE -->
<xsl:variable name="root-node" select="."/>
<xsl:comment>
LIST OF ATTRIBUTE PROPERTIES
Take care when transforming
Attributes in input file: <xsl:value-of select="count(*//attribute::*)"/>
Distinct attributes in input file: <xsl:value-of select="distinct-values(*//attribute::*/name())"/>
Distinct attribute values in input file: <xsl:value-of select="distinct-values(*//attribute::*)"/>
Distinct attribute values by attribute:
<xsl:for-each select="distinct-values(*//attribute::*/name())">
<xsl:text>&#xa;- </xsl:text>
<xsl:value-of select="."/>
<xsl:text>: </xsl:text>
<xsl:value-of select="distinct-values($root-node//attribute::*[name()=current()])"/>
<xsl:text>&#xa;</xsl:text>
</xsl:for-each>
</xsl:comment>
<xsl:apply-templates/>
</xsl:template>
<!-- XSL Templates -->
<xsl:template match="*:elementA">
<ul><xsl:apply-templates/></ul>
</xsl:template>
<xsl:template match="*:elementB">
<li><xsl:value-of select="."/></li>
<xsl:apply-templates/>
</xsl:template>
<!-- Warnings (element based) -->
<xsl:template match="*">
<ERROR>
<xsl:comment>
<xsl:text>ERROR: element '</xsl:text>
<xsl:value-of select="local-name()"/>
<xsl:text>' not handled</xsl:text>
</xsl:comment>
<xsl:apply-templates/>
<xsl:comment>
<xsl:value-of select="local-name()"/>
</xsl:comment>
</ERROR>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment