For each not working properly in XSLT for two loops over a single node
950426Oct 28 2012 — edited Oct 30 2012Hi All,
I'm trying to transform 2 input's to a single target using XSLT.Both the input's and target are of same schema and have the child element.
In the XSLT i have given this condition.
<xsl:for-each select="$Variable1.payload/ns1:BookStore/ns1:Books">
<xsl:for-each select="/ns1:BookStore/ns1:Books">
<xsl:if test="$Variable1.payload/ns1:BookStore/ns1:Books/ns3:BookId = ns3:Books/ns3:BookId">
My second for each is not working and in the target i'm getting double the elements.Please help.Here are two source xml's and the desired target xml.
Source 1 XML:
<BookStore>
<Books>
<Name>NAME1</Name>
<Author>AUTHOR1</Author>
<BookId>1</BookId>
<Quantity>2</Quantity>
<Price></Price>
<Status></Status>
<Books>
<Books>
<Name>NAME2</Name>
<Author>AUTHOR2</Author>
<BookId>2</BookId>
<Quantity>2</Quantity>
<Price></Price>
<Status></Status>
<Books>
<Books>
<Name>NAME3</Name>
<Author>AUTHOR3</Author>
<BookId>3</BookId>
<Quantity>2</Quantity>
<Price></Price>
<Status></Status>
<Books>
</BookStore>
Source 2 XML:
<BookStore>
<Books>
<Name></Name>
<Author></Author>
<Quantity></Quantity>
<BookId>1</BookId>
<Price>100</Price>
<Status>A</Status>
<Books>
<Books>
<Name></Name>
<Author></Author>
<Quantity></Quantity>
<BookId>2</BookId>
<Price>200</Price>
<Status>NA</Status>
<Books>
<Books>
<Name></Name>
<Author></Author>
<Quantity></Quantity>
<BookId>3</BookId>
<Price>300</Price>
<Status>A</Status>
<Books>
</BookStore>
Desired Target XML:
<BookStore>
<Books>
<Name>NAME1</Name>
<Author>AUTHOR1</Author>
<BookId>1</BookId>
<Quantity>2</Quantity>
<Price>100</Price>
<Status>A</Status>
<Books>
<Books>
<Name>NAME2</Name>
<Author>AUTHOR2</Author>
<BookId>2</BookId>
<Quantity>2</Quantity>
<Price>200</Price>
<Status>NA</Status>
<Books>
<Books>
<Name>NAME3</Name>
<Author>AUTHOR3</Author>
<BookId>3</BookId>
<Quantity>2</Quantity>
<Price>300</Price>
<Status>A</Status>
<Books>
</BookStore>
Thanks