0

Input XML:

 <?xml version="1.0" encoding="UTF-8"?>
<dataset>
<TEST ID="1" DATA="DATE"/>
<TEST/>
<TEST2 ID="3" COLUMN="VALUE"/>
</dataset>

Desired Output:

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<TEST ID="1" DATA="DATE"/>
<TEST2 ID="3" COLUMN="VALUE"/>
</dataset>

Current applied XSLT:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*[not(child::node())]"/>
    <xsl:template match="node()|@*">
      <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Current Output:

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
</dataset>

What could be the condition to be applied, to achieve output without empty '<TEST/>' node in result.

2 Answers 2

3

Check following Code

<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>
Sign up to request clarification or add additional context in comments.

Comments

3

If you want to keep elements that have either child nodes or attributes, then change this:

<xsl:template match="*[not(child::node())]"/>

to:

<xsl:template match="*[not(node() or @*)]"/>

Note that child is the default axis, so child:: can be omitted.

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.