I am trying to Add a variable to a list from XML using XSTL and create the merged tag but it is not happening.
Source XML.
<Result>
<Data>
<Pass>true</Pass>
<Data>
<account>
<accountNumber>1111</accountNumber>
</account>
<account>
<accountNumber>2222</accountNumber>
</account>
</Result>
Requirement is that the output tag should have the list with Pass tag value like below.
<Student>
<accountNumber>1111</accountNumber>
<Pass>true</Pass>
<Student>
<Student>
<accountNumber>2222</accountNumber>
<Pass>true</Pass>
<Student>
Current XSLT file is giving the list but I am unable to add Pass Tag.
<xsl:template match = "Root/Result">
<xsl:apply-templates select="account"/>
</xsl:template>
<xsl:template match = "account">
<Student>
<accountNumber><xsl:value-of select="accountNumber" /></accountNumber>
</Student>
</xsl:template>
>Solution :
Try this:
<xsl:template match = "account">
<Student>
<accountNumber><xsl:value-of select="accountNumber" /></accountNumber>
<xsl:copy-of select="preceding-sibling::Pass"/>
</Student>
</xsl:template>
Update. Since the source data changed this is what you then need:
<xsl:template match = "account">
<Student>
<accountNumber><xsl:value-of select="accountNumber" /></accountNumber>
<xsl:copy-of select="preceding-sibling::Data/Pass"/>
</Student>
</xsl:template>