Building the Right Environment to Support AI, Machine Learning and Deep Learning
When working with BizTalk, one of the most straightforward tasks can be creating the data transformation using the BizTalk Mapper. But what about those times when your needs simply don't fit within the boundaries of the Mapper?
In previous versions, you would end up either doing multiple passes through BizTalk or perhaps using custom functionality. Now, you can take advantage of the custom map feature in BizTalk 2006.
When to Use a Custom Map
The most common item I have run into over the years where BizTalk Mapper needs help is when there is a strange parent/child or peer relationship between the source and destination document. For example, if there are two nodes that must be flattened, BizTalk Mapper will flatten the first node, but cannot properly map the second node.
For an example, look at the output of an error message from the Enterprise Library Exception Handling Application Block.
Figure 1: Sample output XML from application block
In this XML, there are two nodes that would need to be flattened using the Value Mapping (Flattening), the Exception and additional info nodes, for the destination XML as seen in Figure 2.
Figure 2: Destination XML
Writing the entire XSLT document can be a daunting task. BizTalk Mapper can help you create the XSLT. Not only is it a visual tool for mapping, but it outputs XSLT when it is compiled. To begin, create the map in BizTalk Mapper. I first created the links for the Exception node using two functoids, the equal logical functoid and then the Value Mapping (Flattening) functoid. In the equal value, I compare the property name to constant values and then send the output to the flattening functoid. The first stage of the map would look like what's shown in Figure 3.
Figure 3: BizTalk Mapper
Next, right-click on the map in the solution explorer, and then select Validate Map. In the output window, you now can select the XSLT output of the map. Take a look at the XSLT; you can see how the value mapping (flattening) functoid works.
Now, if you add in the value mapping for the additionalinfo node, you then can merge these two XSL documents or use the pattern and apply it to both. So now to create the map, simply select the source schema and the destination schema as you would when starting any map. In the properties, point the Custom XSL Path to the location of your saved file.
Figure 4: BizTalk Mapper document properties
Being able to use a custom XSL can help transform data in more ways. You also can get the full depth of the XSLT commands available to you. I also find it useful to view the XSLT when you create a map so that you can understand fully how BizTalk interprets the map you have created.
About the Author
Drew Block, MCSD, is a .NET Architect of enterprise integration and web applications. He is a Senior Manager at Crowe Chizek in Indianapolis, Indiana where he architects, designs, and manages the development of Microsoft-based solutions. You can reach Drew at email@example.com.