Grouping XML Messages using custom XSLT- BizTalk 2010


{tocify} $title={Table of Contents}

Introduction



Thought of writing this post after seeing multiple questions being asked about it on MSDN Forums


Scenario


We receive Xml message which has details spread across multiple nodes and we want to Consolidate/Group the related details to single node.


Input:



Input Schema





Output:



output


What we need to achieve this



We need a map and in map we use custom XSLT.


custom xslt


No mapping/link is  visible on the mapping grid as its done in background  by XSLT which we provide.
We can do linking even after providing custom XSLT with no errors but the output will be based on the XSLT and not linking.
To tell map to apply XSLT we need to set a property Custom XSLT Path to the location where we have our XSLT.


custom xslt

Now lets have a look at the XSLT which we will apply here.

xslt

Grouping is done with the  help of key function  and generateId  function. It is also referred as Muenchian method.

In it we group all the Item records coming as an individual but having same Order Id.

In xslt we first create a key and initialize it, which holds the uniqueId which is generated and based on incoming first OrderID.

<xsl:key use="OrderID" match="/s0:Orders/Order1/Order" name="groups"/>

 And we compare this with the rest of the OrderId from incoming message .

<xsl:for-each select="Order1/Order[generate-id(.)=generate-id(key('groups',OrderID))]">

If match found then an output node is created with  Item records  having same OrderID. This will group all the items which belong to the same order.


<xsl:for-each select="key('groups',OrderID)">

If not then new uniqueId is created for that node  and again checked through all the incoming nodes.


Download sample 


Grouping XML using custom XSLT

Will keep on posting as an when I find something to share!!!!!!!!!!!!


If you have questions or suggestions, feel free to do in comments section below !!!


Do share if you find this helpful .......
 
                          Knowledge Sharing is Caring !!!!!!



Related Post 


Post a Comment

If you have any suggestions or questions or want to share something then please drop a comment

Previous Post Next Post