If we run this map in BizTalk 2010 and watch for the output in Debug View we get the expected output
Also the map test succeeds in BizTalk 2010. As shown below:
Invoking component… F:ProjectsTestMapTestMapSomeMap.btm: The compilation is using the CustomXslt and CustomExtensionXml tags to generate the output. The map content is ignored. TestMap used the following file: <file:///C:UsersAdministratorAppDataLocalTempinputfile.xml> as input to the map. Test Map success for map file F:ProjectsTestMapTestMapSomeMap.btm. The output is stored in the following file: <file:///C:UsersAdministratorAppDataLocalTemp_MapDataTestMapSomeMap_output.xml> Component invocation succeeded.
Observed behavior BizTalk 2013
If we run this in BizTalk 2013 we get the following output.
C:ProjectsTestMap2013TestMapTestMapSomeMap.btm: The compilation is using the CustomXslt and CustomExtensionXml tags to generate the output. The map content is ignored. TestMap used the following file: <file:///C:UsersAdministratorAppDataLocalTempinputfile.xml> as input to the map. C:ProjectsTestMap2013TestMapTestMapSomeMap.btm: error btm1050: XSL transform error: Unable to write output instance to the following <file:///C:UsersAdministratorAppDataLocalTemp_MapDataTestMapSomeMap_output.xml>.
Exception has been thrown by the target of an invocation. An error occurred during a call to extension function ‘WriteNode’. See InnerException for a complete description of the error. Enumeration has not started. Call MoveNext. Test Map failure for map file <file:///C:ProjectsTestMap2013TestMapTestMapSomeMap.btm>. The output is stored in the following file: <file:///C:UsersAdministratorAppDataLocalTemp_MapDataTestMapSomeMap_output.xml> Component invocation succeeded.
So the map failed because the behavior of the compiled xslt is different from the interpreted xslt.
The behavior should be the same as in BizTalk 2010.
February 17, 2011 /Comments Off on XSLT Distinct another way to determine distinct in XSLT 1.0
I had a requirement to map a buyer only if it was the same buyer throughout the entire document. The reason for this was that in the source document the buyer was defined in a sub sub sub node of a document and in the destination it occurred only once. So I ended up with several choices.
Only map the first buyer
Only map if they were the same throughout the entire document
For sure the first option would be a bad thing. The second option would work for all parties involved (it’s an optional element in the output of the map) but the parties really want their buyer information if it’s there. The third option seemed the best solution. I quickly googled on XSLT and distinct and there were some results. So I told the customer implementing a distinct wouldn’t be too hard. (it already existed in XSLT). (I wish I looked a bit harder, cause then I would have seen that the distinct function of XSLT comes with XSLT 2.0 and sadly BizTalk is still using XSLT1.0)
After some thinking I got the following solution for this problem.
Perform a count of the number of buyers in a document
Get the first buyer (buyer is mandatory in the input document)
Perform a count of the numbers of buyers where buyer != buyer found in step2
If the number in step 3 is 0 then we know all the buyers are the same. Below is the XSLT I used to perform this different distinct approach.
August 16, 2010 /Comments Off on Using XSLT Templates in a map (reminder@self)
We all know that using XSLT inside a map can be very usefull to do stuff that’s very hard to do with the mapper itself. Sometimes using XSLT it is the only way things can be done. I find myself struggeling each time to figure out how specific tasks work with XSLT.
That’s why I write this post. So I wont have to figure it all out again the next time i need this functionality…. Below is some code used in an ‘Inline XSLT Call Template’ to calculate the number of segments in a message (UNT) and the message Message Reference number.
The input CurrentIndex is retrieved from an Iteration functoid that returns the current index of the transaction. This index is used to retrieve the correct values for the UNT segment of that transaction ( I am using the batched EDI schema’s).