1

I am trying to remove the xml node which is having empty values below my code

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="node()|@*" >
    <xsl:copy>
         <xsl:apply-templates select="@*[.!='']" />
         <xsl:apply-templates select="node()" />
    </xsl:copy>
</xsl:template>

Input:

<Test><id value=""></id><name value="Test"></name></Test>

Output:

<Test><id /><name value="Test" /></Test>

Expected Output:

<Test><name value="Test" /></Test>

Here <id\> tag should remove. Please suggest where am missing. Please help me to solve the above problem.

1
  • Please be more precise about the conditions for dropping an element. For example "has at least one attribute whose value is zero length", "has at least one attribute and all attributes are zero length". Commented May 25, 2018 at 14:41

1 Answer 1

1

Your script skips only such empty attributes, not the whole containig element.

If you want to skip the whole element with at least one empty attribute, use an empty template, matching such elements:

<xsl:template match="*[@* = '']"/>

and an ordinary identity template.

To omit empty lines, that are left in places of these "deleted" elements, you may add <xsl:strip-space elements="*"/> to your script.

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.