We receive Typed Polled message which has details spread across multiple nodes and we want to consolidate the related details to single node and then debatch/split those messages into single message. Input :
Grouping Output (Intermediate):
<?
xml
version
=
"1.0"
?><
br
>-<
ns1:Acks
xmlns:ns1
"http://orderprocess_schemas.acknowledgement/"
xmlns:ns0
"http://orderprocess_schemas.ack/"
>
<
ns0:Ack
doco
"1053"
OrderID
>DemoId_1</
OrderDate
>2013-07-31T00:00:00Z</
RequestedDate
>2013-08-15T00:00:00Z</
Currency
>INR</
BillTo
addressID
"Demo Bill Id "
Name
>Demo name</
City
>Demo City</
State
>Demo State</
PostalCode
>410010</
Country
>India</
</
ShipTo
"Demo Ship Id "
>Demo ship name</
>25647</
Item
ItemId
>ITM-378910-21</
Quantity
>7</
UnitOfMeasure
>EA</
UnitPrice
>5.00</
TaxableAmount
>279635.00</
TaxAmount
/>
Comment
>Demo Item</
...
"1051"
>DemoId_2</
"Demo Bill Id"
"Demo Ship Id"
>LNV-THkPD-45829173</
>3</
>90000.00</
><
>This is comment for line number 2</
>2</
>300.00</
>This is comment for line number 3</
>1</
>9000.00</
>This is comment for line number 4</
Step 1: Map which will group the message The source to map will be the TypedPolled Data and destination will be referring Envelope schema in which single messages are wrapped.
Custom XSLT is used in the map. And to perform grouping, help of key function and generateId function is utilized. It is also referred as Muenchian method. To include and apply Custom XSLT, the location path is to be provided and for that we click on the Map grid and go to properties tab. In properties tab the path is provided against the property "Custom XSLT Path"
In it we group all the Item records coming as a individual but having same Order Id. In the XSLT we first create a key and initialize it, which holds the uniqueId which is generated and based on incoming first OrderID.
xsl:key
name
"group-by-id"
match
"s0:TypedPollingResultSet0"
use
"s0:OrderID"
And we compare this with rest of the OrderId from incoming message.
xsl:apply-templates
select
"s0:TypedPollingResultSet0[generate-id(.)=generate-id(key('group-by-id',s0:OrderID)[1])]"
If match found then a output node is created with Item records having same OrderID .
xsl:for-each
"key('group-by-id',s0:OrderID)"
If not then new uniqueId is created for that node and again checked through all the incoming nodes.
encoding
"UTF-8"
?>
xsl:stylesheet
xmlns:xsl
"http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl
"urn:schemas-microsoft-com:xslt"
xmlns:var
"http://schemas.microsoft.com/BizTalk/2003/var"
exclude-result-prefixes
"msxsl var s0"
xmlns:s0
"http://schemas.microsoft.com/Sql/2008/05/TypedPolling/Ack"
"http://OrderProcess_Schemas.Ack"
"http://OrderProcess_Schemas.Acknowledgement"
xsl:output
omit-xml-declaration
"yes"
method
"xml"
xsl:template
"s0:TypedPolling/s0:TypedPollingResultSet0"
xsl:variable
"doco"
"s0:DOCO"
"{$doco}"
"billid"
"s0:BilltoID"
"shipid"
"s0:ShipToID"
xsl:value-of
"s0:OrderDate"
"s0:RequestDate"
"s0:Currency"
"{$billid}"
"s0:BillToName"
"s0:BillToCity"
"s0:BillToState"
"s0:BillToPostal"
"s0:BillToCountry"
"{$shipid}"
"s0:ShipToName"
"s0:ShipToCity"
"s0:ShipToState"
"s0:ShipToPostal"
"s0:ShipToCountry"
"s0:ItemID"
"s0:Quantity"
"s0:UnitOfMeasure"
"s0:UnitPrice"
"s0:TotalAmount"
"s0:TaxAmount"
"s0:LineComment"
GetPipelineOutput = Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteReceivePipeline(
typeof
(Microsoft.BizTalk.DefaultPipelines.XMLReceive), BatchAckMsg);
GetPipelineOutput.MoveNext()
AckOut =
null
;
GetPipelineOutput.GetCurrent(AckOut);