I need to get the final output structure xml as below for my project. but I'm facing few issues with this code.
<Endorsement>
<TL>STNDBY/CHG FEE/NO RFND/</TL>
<TL>CXL BY FLT DT/</TL>
</Endorsement>
<LText TopicId="MISCELLANEOUS">
<TL>01 NVB28JUL/NVA28JUL</TL>
</LText>
Here is the input xml file
<InfoMsg>
<AppNum>0</AppNum>
<MsgType>2</MsgType>
<Text>LAST DATE TO PURCHASE TICKET: 06JUN13</Text>
</InfoMsg>
<InfoMsg>
<UniqueKey>0001</UniqueKey>
<Lang>0</Lang>
<Text>E-TKT REQUIRED</Text>
</InfoMsg>..............
To achieve above output structure OI'musing the below piece of code
<xsl:for-each select="../InfoMsg">
<xsl:choose>
<xsl:when test="MsgType='01' or MsgType='1'">
<xsl:element name="Endorsement">
<xsl:element name="TL">
<xsl:value-of select="Text"/>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="LText">
<xsl:attribute name="TopicId">
<xsl:text>MISCELLANEOUS</xsl:text>
</xsl:attribute>
<xsl:element name="TL">
<xsl:value-of select="Text"/>
</xsl:element>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
Logic here is, for each Info Msg tag it should check if MSgType is eqaul to 01 or 1, if yes then it create Endorsement tag otherwise it should construct Ltext tag.Condition is The Msgtype used in Endorsement element should not get repeated in Ltext tag.
But it gives me below output
- <Endorsement>
<TL>STNDBY/CHG FEE/NO RFND/</TL>
</Endorsement>
- <Endorsement>
<TL>CXL BY FLT DT/</TL>
</Endorsement>
- <LText TopicId="MISCELLANEOUS">
<TL>01 NVB28JUL/NVA28JUL</TL>
</LText>
- <LText TopicId="MISCELLANEOUS">
<TL>02 NVB28JUL/NVA28JUL</TL>
</LText>
- <LText TopicId="MISCELLANEOUS">
<TL>LAST DATE TO PURCHASE TICKET: 26JUN13</TL>
</LText>
- <LText TopicId="MISCELLANEOUS">
<TL>E-TKT REQUIRED</TL>
</LText>
- <LText TopicId="MISCELLANEOUS">
<TL>ADDITIONAL TAXES, SURCHARGES, OR FEES MAY APPLY</TL>
</LText>
Here Endorsement tag is coming multiple times which is not necessary. It should come only once.
Pls suggest what changes can i make in my code to get it. Is there any alternate method or way of doing this.
Thanks Asma