<To>
<Id>SERVICE</Id>
<Role>Commuter</Role>
</To>
<BPD>
<OrgNo>234</OrgNo>
</BPD>
<BON>123</BON>
I have this Input XML in which I want to check whether //To/Id
contains SERVICE or not.
If it contains SERVICE then a element should be added after <BPD>
naming <BON>SERVICE</BON>
.
Also I want to check if my Input XML already contains <BON>
element then its value should be
replaced by SERVICE which is in <Id>
element.
I have created a template for this ->
<xsl:template match="BPD">
<xsl:choose>
<xsl:when test="not(BON) and normalize-space(/To[Role='Commuter']/Id)='SERVICE'">
<BON>
<xsl:text>SERVICE</xsl:text>
</BON>
</xsl:when>
<xsl:when test="normalize-space(BON) and normalize-space(/To[Role='Commuter']/Id)='SERVICE'">
<BON>
<xsl:text>SERVICE</xsl:text>
</BON>
</xsl:when>
</xsl:choose>
</xsl:template>
This template is checking whether exists or not. If it doesn't exist then it creates <BON>
element and adds 'SERVICE' as value to it.
And if exists then it creates one more element which is not required.
I need to correct my second when situation.