About Columns

Regular columns appear in this section. Regular columns include:

  • Notes - Notes from the field; practical advice, tips, and tricks based on real-world experience
  • Top X - A top 5, 10, or X listing - packed with practical, insightful information for those in a hurry
  • The Practice - Explores the practice of integration: politics, business, career development

Have an idea? Want to contribute? Contact the editor at articles {at} artofbabel [dot[ com

Home Columns Notes Complex Maps
Complex Maps
Columns - Notes
Written by Erik Westermann   
Wednesday, 28 January 2009 16:42

Some BizTalk maps can be very complex - often including conditions, mappings for special cases, and string manipulation. The BizTalk mapper has limitations so it is great for relatively simple maps; however, there is an easy way to address the mapper's limitations.

When you create a map using the BizTalk mapper, Visual Studio is actually generating the mapping using XSLT. XSLT is the Extensible Stylesheet Language for Transformations. An XSLT document is just another XML document that, in this case uses XSL to describe how to transform an XML document into another format.

When you save a BizTalk map, Visual Studio saves the XSLT in a file that has a BTM extension. The BTM file contains, among other information, the actual XSLT that Visual Studio generated. The great feature of the  BTM file is that it really does not care where the XSLT comes from.

So, when it comes to more advanced XSLT, you can write your own and add it into a BTM file without having to resort to fighting with the mapper. Here's a case where writing your own XSLT has a couple of benefits...

I am working on a BizTalk project that includes a lot of mapping/transforms. Although mapping in BizTalk is great, I find the mapper limited in many ways because it is difficult, or impossible to express certain functionality.

For example, if/then/else value mapping is very messy. Assume that you need to map from a value from schema A to schema B. Elements in schema A are optional (minOccurs=0) - mandatory in schema B (minOccurs=1, maxOccurs=1). As a result, elements must contain information in schema B, even if the source elements in schema A are absent or empty.

The mapping needs to implement simple decisions: if a value in schema A exists, then map it to schema B, else map using a default value.

Specifying a default values, in the schema or map's implementation, does not work in this case because the resulting document will always have the default value (because it is mandatory). I also tried using a number of functoids including ‘IsNil' and ‘Logical Existence', combined with the ‘Value Mapping (Flattening)' functoid.

While combining functoids works to a degree, it gets really messy when working with a lot of if/then/else mappings. Moreover I observed some inconsistent behaviour when elements in the source schema were completely absent (missing from the source document).

Being much more comfortable working directly with XSL than working with mapping tools, I ended up solving my problem by writing my own Inline XSLT Call Template transform to use with a scripting functoid. I tested the XSLT outside of BizTalk and, once I had it working as I wanted, I tried to add the XSLT to my map.

It seems that the tiny Configure Functoid Script window's editor has a limit of 30,000 characters. My transform occupies about 38,000 characters so it was incomplete when I pasted it into the window (With a slight twist on a more popular quote, I am sure the window's designer thought "30k is more than enough". Famous last words.).

The editor deceptively and silently dropped the remaining 8,000 characters and I found out that something was wrong the hard way when I tested my map.

I got around this limitation by editing the BTM file using everyone's favourite editor: notepad. Since Visual Studio stores the contents of a template in a CDATA section, I simply pasted all 38,000 characters into the CDATA section, saved, compiled, and tested. It works perfectly!

The downsides to this approach:

  • Future developers will have to remember to edit the map outside of BizTalk.
  • If you try to edit XSLT containing more than 30,000 characters using the editor, it only allows you to delete.


Bug or feature? You decide!

 

Newsflash

BizTalk 2006 R3 is now BizTalk Server 2009. Better alignment with Oslo, more predictable two-year release cycle. More details here.

RSS Feed

Sponsor

ArtOfBabel.com is supported by Erik Westermann's wWorkflow.net - BizTalk, SOA, ESB consulting & services.
Your tweets are yours, make Twitter yours too!
Custom Twitter Backgrounds

Search