BizTalk Mappings

posted on 2005-07-20 at 23:23:08 by Joel Ross

Last week, I finally had a chance to get into the mapper in BizTalk. I've done minor things with it to this point - dragging fields from one side to the other, using the simple functoids to concatenate strings, but nothing complex.

I was a little nervous to try something hard. I was warned by Jim (you need to blog more, Jim!), one of our BizTalk experts at NuSoft that the mapper was dangerous. He said don't use the mapper - use Xpath. I'm guessing anyone familiar with XML and XSL and XSLT and BizTalk would know what he was talking about - but I was only familiar with XML at the time. Since then, I'm much more familiar with BizTalk, but still didn't have any experience with Xpath or transformations.

Well, that's all changed. I used this tutorial to get started, and then went from there. I used a custom XSLT script functoid and…still ran into problems! I checked out XMLSpy, and still had issues. Then a colleague said one word: namespaces. I remember we added a namespace to our input message, but I still didn't really get it (I still don't quite get namespaces completely).

Well, first, I removed the namespace from my input message, and then tested it in XMLSpy again. Worked like a charm. So now what? I couldn't remove the namespace from my actual document, so I tried to search to figure it out. Not much help.

Then I remembered that I'd read somewhere that the map gets translated into an XSLT file - in fact, you could write your whole transform map as a custom XSLT file - which is exactly what Jim was talking about! Doing a little digging revealed that if you right click on the map and select "Validate Map" then you'll get the XSLT file spit out to the file system. From there, I could open the file and figure out how the namespace issues were handled. Worked like a charm!

For those wondering, you can't do the (what I call) easy Xpath queries:

/MyRoot/MyNode/text().

You have to do it a little bit different:

/*[local-name='MyRoot' and namespace-uri='http://schemas.rosscode.com/MyRoot/01']/*[local-name='MyNode' and namespace-uri='http://schemas.rosscode.com/MyRoot/01']/text().

It's definitely not as easy as the first, but once you know, it's not that bad to implement. Of course, you have to know first.

Categories: Development