XSLT Mapping in SAP PI

This blog will explain how to use XSLT mapping in SAP PI. We will implement a simple XSLT mapping program to understand it better.

Let’s say we have a requirement to concatenate the First Name & Last Name to Name Field.

Source XML structure.

XSLT mapping in sap pi

 

 

 

 

And the desired target structure is as follows:

XSLT mapping in SAP PI

 

 

 

Thus all we need to do is to concatenate the first and last name of the person to create a full name along with the birth date at the target. Although this could be easily achieved using plain graphical mapping, I am using this example just to keep it simple enough to understand.

I have covered more advanced XSLT mapping example here Sorting of data using XSLT mapping

Now let us look at the XSLT mapping program:

XSLT Mapping

 

 

 

 

 

 

 

 

 

 

XSLT Mapping explanation

<xsl:stylesheet> tag indicates that this is an XSL document

<xsl:template> tag is used to match “/” i.e. entire source document. So the rules within <xsl:template> and </xsl:template> will be used produce the target XML.

<xsl:for-each> tag is used to loop through all occurrences of the Person node. And the code within <xsl:for-each> and </xsl:for-each> is executed once for every occurrence of Person node occurring under Persons node.

<xsl:variable> tags are used to store the values of Name and Surname fields from the source document.

<xsl:value-of> tags are used to move individual XML field values to the target structure. The function concat() is used to concatenate current values of variables $fname and $lname separated by a space.

Testing the XSLT Mapping

You can test the mapping by compressing the XSL file into a ZIP archive and importing it into IR/ESR. You need to create appropriate IR objects and use the XSLT Program in your interface mapping.

SAP Reference XSLT Mapping

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.