Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Using Custom XSLT Transformations in BizTalk Server 2004 Mapper

0.00/5 (No votes)
28 Feb 2006 1  
This article uses the custom XSLT transformations in the BizTalk Server 2004 Mapper.

Introduction

During the development of complex maps using the BizTalk Mapper tool, one encounters several situations where custom mapping would be required in order to complete a transformation. This article will explain how to perform custom XSLT transformations using the BizTalk Mapper tool.

Background

Consider a Purchase Order (PO) request which would contain a main order request and a set of supplementary order requests. This would be similar to a Parent-Child relationship where a Parent PO would contain several Child POs for various items contained in the Parent PO.

The BizTalk Flat File Schema Solution - Input Schema

CBO-Sample-Schema

In this example, we will need to generate a baseline item (PARENT) data tag, and several subline data items (CHILD) which belong to the baseline data item. The input will contain several "POAckDetail" elements, each having several attributes.

  1. The attribute "ItemChildFlag" specifies whether the node is a "PARENT" or a "CHILD".
  2. The attribute "ParentLineNumber" specifies the parent which the "CHILD" node belongs to.
  3. The attribute "ParentLineNumber" must match with the "SellerLineNum" of the parent node.

InputXML

Notice the second POAckDetail element whose "ItemChildFlag" attribute value contains "CHILD". This element's parent would be the POAckDetail element with SellerLineNum="0003".

The BizTalk Mapper

XSLTMap

We would need to add a script functoid in order to do a custom XSLT transformation. A custom XSLT would contain a "template" tag where the XSLT mapping must be written. The input to the custom scriptoid would become a <xsl:param name="SellerLineNum" /> in the XSLT template.

The Functoid Map and the Custom XSLT Transformation Script

FunctoidScript

<xsl:template name="MyXsltConcatTemplate">
<xsl:param name="SellerLineNum" />

<xsl:for-each select="//POAckDetail/ItemCurrentInfo[@ItemChildFlag='CHILD' 
                         and @ParentLineNumber=$SellerLineNum]">

<ns0:SLN_Subline_Item_Detail_S117 
     xmlns:ns0="http://www.covast.com/schemas/EDI/Accelerator2004">
  <ns0:_380_Quantity_E4><xsl:value-of 
             select="../SellerLineNum" /></ns0:_380_Quantity_E4> 
  <ns0:_212_Unit_Price_E20><xsl:value-of 
             select="@UnitPrice" /></ns0:_212_Unit_Price_E20> 
  <ns0:_639_Basis_of_Unit_Price_Code_E21><xsl:value-of 
             select="@BasisOfUnitPriceTypeCode" />
  </ns0:_639_Basis_of_Unit_Price_Code_E21> 
</ns0:SLN_Subline_Item_Detail_S117>

</xsl:for-each>

</xsl:template>

Line 1: The XSL template declaration statement

Line 2: The XSL parameter, this will map to the input given to the script functoid.

Line 3: The XSL for-each statement that iterates over 'CHILD' POAck elements.

Lines 4-8: Creating the XML structure as required for the output.

Lines 9-10: Closing the tags.

Validating and Testing the Map Created

Once we have finished writing the map, we need to test the map.

Step 1: In the Solution Explorer, select the map "CBO-To-ASC_X12-Map.btm", and right-click and select "Properties". Specify the properties as shown in the image below...

Map Property Pages

Step 2: In the Solution Explorer, select the map "CBO-To-ASC_X12-Map.btm", and right-click and select "Test Schema". Observe the output window and you would notice a message starting with "Component invocation succeeded". Now, click on the link which starts with the message "Test Map success for map file..."

The XML output file would look like this...

XSLT_Map_Output

Quick Takeaways

  1. The BizTalk Mapper script functoid offers maximum flexibility during mapping, by using custom XSLT templates.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here