This is my xml input:
<root>
<node1/>
<node2/>
<node3/>
<node4/>
<othertags/>
</root>
The output should be:
<root>
<othertags/>
</root>
if any of the 4 nodes is non-zero, none of the tags should be removed.
example:
<root>
<node1/>
<node2/>
<node3/>
<node4>sample_text</node4>
<othertags/>
</root>
Then the output should be the same as the input xml file.
<root>
<node1/>
<node2/>
<node3/>
<node4>sample_text</node4>
<othertags/>
</root>
This is the XSL code I developed:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/root/node1[.='' and ../node2/.='' and ../node3/.='' and ../node4/.='']
|/root/node2[.='' and ../node1/.='' and ../node3/.='' and ../node4/.='']
|/root/node3[.='' and ../node1/.='' and ../node2/.='' and ../node4/.='']
|/root/node4[.='' and ../node1/.='' and ../node2/.='' and ../node3/.='']"/>
As you can see, the code takes more effort and becomes more cumbersome as the number of nodes increases. Is there an alternative way to overcome this bottleneck?
source
share