I suppose to check for the 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 XML output:
<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 check the value of the tag, but this is something new for me.
I tried using this template: (which does not work as per 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>
source
share