heikkidoeleman
Programmer
Hello,
after seeing this thread426-1088712 old thread on removing empty elements, I think its solution is not ideal as it will remove empty elements that have non-empty attributes too.
A solution that does not remove empty elements that have non-empty attributes is the following:
For good measure I've treated whitespace-only values as if they are empty, too.
after seeing this thread426-1088712 old thread on removing empty elements, I think its solution is not ideal as it will remove empty elements that have non-empty attributes too.
A solution that does not remove empty elements that have non-empty attributes is the following:
Code:
<xsl:template match="node()">
<xsl:if test=". != '' or normalize-space(.//@*) != '' ">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="@*">
<xsl:if test="normalize-space(.) != '' ">
<xsl:variable name="attributeName" select="name()"/>
<xsl:attribute name="{$attributeName}" select="."/>
</xsl:if>
</xsl:template>
For good measure I've treated whitespace-only values as if they are empty, too.