Reputation: 27
I am using below template to remove empty nodes from an XML, but it is also removing the class attribute from the non-empty nodes:
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
<xsl:template match="*[not(child::node())]"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
I don't want to remove attributes from the non-empty nodes. Please suggest?
Upvotes: 1
Views: 941
Reputation: 5432
Use this:
<xsl:template match="*[not(child::node())]"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
Upvotes: 1