Answered by:
XSLT Problem

Question
-
Hi,
I have an xml file:
<row>
<name>Adam</name>
<id>100</id>
<name>Sue</name>
<id>200</id>
</row>
and I need an XSLT to convert it to:
<people>
<person>
<name>Adam</name>
<id>100</id>
</person>
<person>
<name>Sue</name>
<id>200</id>
</person>
</people>
any ideas ???
Many thanks
Adam
Tuesday, November 24, 2009 1:48 PM
Answers
-
This is a very classic issue about sequence group mapping. The essential is: a sequence group isn't an actual *parent node*. It cannot be used in map to generate the parent element(<person> here) in destination.
Usually we will achieve this kind of scenarios with XSLT. However, actually it can still be done with biztalk mapping and built-in Iteration and Index functoids.
1. First you can use <name> in the source to generate <person> element(link them directly).
2. Use Iteration functoid to retrieve the current index of <name> element.
3. Use Index functoid to get source <id> with the same index value retrieved by Iteration funtoid and link it to destination <id> under <person> element.
And you've done. Quite easy, right? :)
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.- Marked as answer by Wen-Jun ZhangMicrosoft employee, Moderator Monday, November 30, 2009 9:42 AM
Monday, November 30, 2009 9:42 AMModerator
All replies
-
You can use the script below in your custom functoid (XSLT Template), replace the xpaths of the nodes from the source schema. I have pasted the template of the destination XML in the script. This will populate the person records in the destination schema. Just connect the custom script functoid to the people node in the destination schema.
<people>
<xsl:for-each select="xpath of row">
<person>
<name> <xsl:value-of select="xpath of name"/></name>
<id><xsl:value-of select="xpath of id"/></id>
</person>
</xsl:for-each>
Abdul Rafay http://abdulrafaysbiztalk.wordpress.com/ Please mark this as answer if it helpsTuesday, November 24, 2009 2:31 PM -
Abdul,
Your Xsl will only select one person from the row. You need to loop on name:
<xsl:element name="people"> <xsl:for-each select="name"> <xsl:element name="person"> <xsl:element name="name"> <xsl:value-of select="."/> </xsl:element> <xsl:element name="id"> <xsl:value-of select="following-sibling::*"/> </xsl:element> </xsl:element> </xsl:for-each> </xsl:element>
- Proposed as answer by Tariq Majeed Tuesday, November 24, 2009 6:52 PM
- Marked as answer by Wen-Jun ZhangMicrosoft employee, Moderator Monday, November 30, 2009 9:43 AM
- Unmarked as answer by AdamSmile Tuesday, December 1, 2009 9:57 AM
Tuesday, November 24, 2009 6:46 PMAnswerer -
Hi Greg,
Yes, if the Row is not a repeating record then you must select the name node if it is repeating in the for each loop.
Abdul Rafay http://abdulrafaysbiztalk.wordpress.com/ Please mark this as answer if it helpsTuesday, November 24, 2009 6:51 PM -
This is a very classic issue about sequence group mapping. The essential is: a sequence group isn't an actual *parent node*. It cannot be used in map to generate the parent element(<person> here) in destination.
Usually we will achieve this kind of scenarios with XSLT. However, actually it can still be done with biztalk mapping and built-in Iteration and Index functoids.
1. First you can use <name> in the source to generate <person> element(link them directly).
2. Use Iteration functoid to retrieve the current index of <name> element.
3. Use Index functoid to get source <id> with the same index value retrieved by Iteration funtoid and link it to destination <id> under <person> element.
And you've done. Quite easy, right? :)
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.- Marked as answer by Wen-Jun ZhangMicrosoft employee, Moderator Monday, November 30, 2009 9:42 AM
Monday, November 30, 2009 9:42 AMModerator