Template correction in XSLT

JeoPardy

New Member
\[code\]<To> <Id>SERVICE</Id> <Role>Commuter</Role></To><BPD> <OrgNo>234</OrgNo> </BPD><BON>123</BON>\[/code\]I have this Input XML in which I want to check whether \[code\]//To/Id\[/code\] contains SERVICE or not.If it contains SERVICE then a element should be added after \[code\]<BPD>\[/code\] naming \[code\]<BON>SERVICE</BON>\[/code\].Also I want to check if my Input XML already contains \[code\]<BON>\[/code\] element then its value should bereplaced by SERVICE which is in \[code\]<Id>\[/code\] element.I have created a template for this ->\[code\]<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>\[/code\]This template is checking whether exists or not. If it doesn't exist then it creates \[code\]<BON>\[/code\]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.
 
Back
Top