Tuesday 6 March 2012

XSL code erase empty nodes, trim spces and normalize strings

XSLT code snippet to trim all spaces, normalize strings and erase all empty nodes.

<xsl:template match="node()">
<xsl:if test="count(descendant::text()[string-length(normalize-space(.))>0]|@*)">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>

<xsl:template match="@*">
<xsl:copy/>
</xsl:template>

<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>

No comments:

Post a Comment