Ben Runchey’s Integration Dev Blog

a.k.a Ben’s spot to put stuff he does not want to forget

Some XSLT for when you just can’t get the mapper to do what you want it to do

Update – Please see my subequent post titled “Finding out the mapper can do what I want it to do” which makes this “hack” not necessary any longer 

Recently I have been spending some (maybe too much) time on the msdn forums to see if I can help out anyone that is having a problem with BizTalk.  I figure since most of my knowledge comes from reading blog posts, I need to do something that gives back to the world. 

So on friday a post showed up about needing to map from one format with data in a non repeating header and moving it to a repeating element in a destination document.  You can read actual post here.  An example of the source and destination would be as follows

The source schema looks like:

SelectiveMappingSourceDocument

 And our destination schema looks like

SelectiveMappingDestinationDocument

So as you can see we need to take the PONum and ShippingDate attributes from the Header element of the source document and put them into two different MainLoop elements in our destination document.  Then take the repeating Item elements from the source and fill out the remaining MainLoop elements in the destination document. 

Getting the PONum and ShippingDate out proved to be a bit more challenging than I had orignally thought.   I did not want to write just straight XSLT and by pass the mapper.  That is always an option, but then I am not really using the tools available.    What I decided to do was use inline XSLT in a scripting functoid to copy the Source\Header\PONum and ShippingDate fields to the MainLoop.  So I came up first with a map that looked like this

 SelectiveMappingFirstAttempt

But the Xml was not what I wanted… (not even close!)

SelectiveMappingFirstAttemptResult

So when looking at the xslt the map was creating I realized that  getting a MainLoop element for both my PONum and ShippingDate field would require me to have an “empty” spot in my destination schema that I could push the XSLT from my two scripting functoids into.  So I created a temporary destination schema that contained a “PlaceHolder” for me to overwrite.

SelectiveMappingModifiedDestinationSchema

Now my map looks like this…

SelectiveMappingCorrectMap

Which produces the correct output…

SelectiveMappingDestinationDocument

Now I know, if this is a huge document, or I am doing lots of these throughout the day and performance is a very big consideration the straight XSLT approach would be more performant, but until I need to have the speed, I will take the maintainability.  You can download the project that demonstrates this here

 Mape1082 I hope this helps you somehow. 

 

Advertisements

February 19, 2008 - Posted by | BizTalk

1 Comment »

  1. […] Ben Runchey’s Integration Dev Blog a.k.a Ben’s spot to put stuff he does not want to forget « Some XSLT for when you just can’t get the mapper to do what you want it to do […]

    Pingback by Finding out the mapper can do what I want it to do « Ben Runchey’s Integration Dev Blog | February 19, 2008 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: