transform to conditionally mask elements and attributes from input

jasculs

New Member
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 outputmy input xml\[code\]<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>\[/code\]my desired output(when flag is 1)\[code\]<Root><a ref="t"><s id="2">value</s></a></Root>\[/code\]xslt i tried\[code\]<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>\[/code\]
 
Back
Top