• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

riyaz.net

Tech Tips and Tutorials for SAP Professionals and Bloggers

  • Home
  • WordPress
  • Tips & Tricks
  • Internet
  • SAP
    • SAP PI
    • SAP ABAP
  • Personal Finance
  • Health & Fitness
  • Travel & Leisure
You are here: Home / SAP / XSLT Mapping – A Simple Example

XSLT Mapping – A Simple Example

May 16, 2010 by Riyaz

xslt-example

SAP PI supports four types of mappings like plain graphical mapping, Java mapping, ABAP mapping and XSLT mapping. In the previous article Beginner’s Guide to XSLT Mapping in SAP PI, we learnt the basics of XSLT mapping. We also discussed  the advantages and disadvantages of using XSLT in SAP PI. We briefly touched the situations where XSLT mapping can prove to be helpful and appropriate option.

In this article, we will implement a simple XSLT mapping program to understand it better.

Lets say we have a source XML as follows:

xslt mapping

and the desired target structure is as follows:

xslt mapping

Thus all we need to do is to concatenate 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.

Now let us look at the XSLT mapping program:

xslt mapping

<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 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 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. I have explained detailed steps of doing this in the article – Beginner’s Guide to XSLT Mapping in SAP PI.

There is another simple way of verifying the functionality of our XSLT program. Open the source XML file and add the following line immediately after the first line.

<?xml-stylesheet type="text/xsl" href="Persons_to_Persons.xsl"?>

Make sure the name of XSL file is correct. Save the file and open it in a browser. If everything goes well you should see the correctly transformed values in the browser. However, you will not be able to see the XML tags in the browser output. To see the XML tags you will need to test the program using one of the XSLT development tools like Altova XMLSpy, Altova MapForce, Stylus Studio etc or you can directly test the program in IR/ESR as explained earlier.

You can download the source XML file and XSLT Mapping program for testing. To download, right-click the download links and choose ‘Save target as…’ or ‘Save link as…’ option.

Filed Under: SAP Tagged With: SAP PI

About Riyaz

Riyaz Sayyad is the founder of Riz Labs. Learn more about him here.

Primary Sidebar

Popular Guides

  • Dropbox Tutorial
  • CDN Setup Guide
  • Blog Design Tips
  • Optimize RSS Feed
  • Create Twitter App
  • Short URLs
  • Password Protect Folders
  • Time Management
  • ALE IDocs Tutorial
  • SAP PI Starter Kit
  • SAP PI Tips
  • Ergonomics

Popular Topics

  • Home
  • WordPress
  • Tips & Tricks
  • Internet
  • SAP
    • SAP PI
    • SAP ABAP
  • Personal Finance
  • Health & Fitness
  • Travel & Leisure

About Riyaz

riyaz.net is a popular technology site with how-to guides, tips and tutorials on personal technology, blogging, social media, web apps, personal finance and SAP.

riyaz.net was launched way back in 2005 by web designer, blogger and SAP Consultant Riyaz Sayyad from Pune, India. Over the years the site has grown into a full featured online community with thousands of visitors daily from around the world. Read more.

Copyright © 2025 · riyaz.net