I am suppose to test the presence of a tag and create a new node according to the result ..
This is the input XML :
<root>
<tag1>NS</tag1>
<tag2 id="8">NS</tag2>
<test>
<other_tag>text</other_tag>
<main>Y</main>
</test>
<test>
<other_tag>text</other_tag>
</test>
</root>
And the required output XML is :
<root>
<tag1>NS</tag1>
<tag2 id="8">NS</tag2>
<test>
<other_tag>text</other_tag>
<Main_Tag>Present</Main_Tag>
</test>
<test>
<other_tag>text</other_tag>
<Main_Tag>Absent</Main_Tag>
</test>
</root>
I know to test the value of the tag, but this is something new to me.
I tried using this Template : (which is not working as per the requirement)
<xsl:template match="test">
<xsl:element name="test">
<xsl:for-each select="/root/test/*">
<xsl:choose>
<xsl:when test="name()='bbb'">
<xsl:element name="Main_Tag">
<xsl:text>Present</xsl:text>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="Main_Tag">
<xsl:text>Absent</xsl:text>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:element>
</xsl:template>