Tuesday, May 12, 2009

Identity Transformation that Removes Empty Nodes

Sometimes its handy to remove XML nodes that have no content other than whitespace. The following XSL does exactly that.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:if test=". != '' or ./@* != ''">
<xsl:if test="not(contains(name(), 'temp'))">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

No comments:

Labels

Blog Archive

Contributors