Requirement

This tutorial will demonstrate how to add a new header segment to IDOC for SAP using MAP in BizTalk 2010 using XSLT.

Source Schema

XSLT-1

Destination IDOC Schema

XSLT-2

We need to generate header node Z1MISCDATA for each segment in IDOC with:

  • datetime=”2015-07-01T18:31:21+00:00″>Value of Type under VALUE_2
  • Value of Id under VALUE_1 if Id not equal to 1

Solution

1. Drag and drop the Scripting Functoid on the Map pane.

XSLT-3

2. Double click on Functoid to open properties. Select Inline XSLT from the “Select script type” dropdown under the “Script Functoid Configuration” tab.

XSLT-4

3. Copy and paste below XSLT under “Inline script” editor and click OK.

XSLT-5.jpg

 

<xsl:for-each select="/*[local-name()='SAPOrder' and namespace-uri()='urn:schemas-citrite-net:SAP:Order:1']/*[local-name()='Interface' and namespace-uri()='urn:schemas-citrite-net:SAP:Order:1']">
  <xsl:variable name="index" select="position()"/>
  <xsl:variable name="IdVal" select="string(/*[local-name()='SAPOrder' and namespace-uri()='urn:schemas-citrite-net:SAP:Order:1']/*[local-name()='Interface' and namespace-uri()='urn:schemas-citrite-net:SAP:Order:1'][$index]/*[local-name()='Id' and namespace-uri()='urn:schemas-citrite-net:SAP:Order:1'])"/>

  <Z1MISCDATA>
    <DATAHEADERREC>
      <SEGNAM>Z2MISCDATA000</SEGNAM>
      <MANDT></MANDT>
      <DOCNUM>1</DOCNUM>
      <SEGNUM></SEGNUM>
      <PSGNUM></PSGNUM>
      <HLEVEL></HLEVEL>
    </DATAHEADERREC>
    <FIELD_NAME>DETAILS</FIELD_NAME>
    <DESCRIPTION></DESCRIPTION>
    <LINE_ITEM></LINE_ITEM>
    <COUNTER></COUNTER>
    <VALUE_1>
      <xsl:value-of select="string(/*[local-name()='SAPOrder' and namespace-uri()='urn:schemas-citrite-net:SAP:Order:1']/*[local-name()='Interface' and namespace-uri()='urn:schemas-citrite-net:SAP:Order:1'][$index]/*[local-name()='Type' and namespace-uri()='urn:schemas-citrite-net:SAP:Order:1'])"/>
    </VALUE_1>
    <xsl:if test="not($IdVal='1')">
      <VALUE_2>
        <xsl:value-of select="$IdVal"/>
      </VALUE_2>
    </xsl:if>
    <xsl:if test="$IdVal='1'">
      <VALUE_2></VALUE_2>
    </xsl:if>
    <VALUE_3>
      <VALUE_3></VALUE_3>
    </VALUE_3>

    <SEGMENTPAD></SEGMENTPAD>
  </Z1MISCDATA>
</xsl:for-each>

In the above code, we are iterating each node of the source schema to get values of the Id and Type fields and are generating corresponding header segments.

Note: XPath for fields used in XSLT can be taken by right-clicking on the field and selecting “Copy XPath.”

XSLT-6

4. Connect Scripting Functoid to segment Z1MISCDATA.

XSLT-7