I have an input XML as below
<testing>
<subject ref="yes">
<firstname>
tom
</firstname>
</subject>
<subject ref="no">
<firstname>
sam
</firstname>
</subject>
</testing>
I am expecting my output should be.
if the subject has ref as yes. I will get the name value. Else if the ref (no) i won’t get element
<testing>
<firstname>
tom
</firstname>
</testing>
Please guide me here.
This can be achieved by building on top of the identity transform. Firstly, you would need a template to ignore subject elements with a @ref of ‘no’
And for subject elements with a @ref of ‘yes’ you have another template to output just its children
In fact, if @ref could only ever be ‘yes’ or ‘no’ you could simplify this template match to just
<xsl:template match="subject">as this would match all elements which don’t have a @ref of ‘no’Here is the full XSLT
When applied to your sample XML, the following is output