My output xml should be masked with some elements, based on a variable, flag.If the flag has a value of ‘1’, the output xml should have only the element ‘a'(include all its attributes and child elements). If the flag is 2, output xml should have elements a and b. If it is 3, all the elements and attributes present in the input should be present in the output
my input xml
<Root>
<a ref="t">
<s id="2">value</s>
</a>
<b ref="t">
<s id="2">value</s>
</b>
<c ref="t">
<s id="2">value</s>
</c>
</Root>
my desired output(when flag is 1)
<Root>
<a ref="t">
<s id="2">value</s>
</a>
</Root>
xslt i tried
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="flag" select="'1'"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:if test ="$flag ='1'">
<xsl:template match="b"></xsl:template>
<xsl:template match="c"></xsl:template>
</xsl:if>
</xsl:stylesheet>
The below xslt is working.