1

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?

1 Answer 1

1

Use this:

<xsl:template match="*[not(child::node())]"/>
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
</xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.