How To create an XSLT mapping file
Document Information
XI Area:
Release:Mapping
XI 1.0
Keywords: XSLT Mapping
Problem Description
You need an XSLT mapping file to connect a proxy with an RFC call, but you have now knowledge about
XSLT.
Procedure
1. You need the XML file which matches with the inbound interface. If you have a proxy interface, you
may use report SPRX_TEST_INBOUND to create the XML file, if you have an RFC interface, you
receive the XML file that way: Use the test mode of transaction SE37, test the RFC function module
with destination of the RFC adapter (fill the interface with real life data). Now you can go to the XI
monitor in the XI system and get the XML out of the payload of the message.
Example
The function module BAPI_FLIGHT_CHECKAVAILIBILITY gives following payload for the request
message:
<rfc:BAPI_FLIGHT_CHECKAVAILIBILITY xmlns:rfc="urn:sap-
com:document:sap:rfc:functions">
<AIRLINEID>LH</AIRLINEID>
<CONNECTIONID>0400</CONNECTIONID>
<FLIGHTDATE>2002-09-01</FLIGHTDATE>
<RETURN />
</rfc:BAPI_FLIGHT_CHECKAVAILIBILITY>
2. You can create the XSLT file directly out of the XML file of the receiver interface, just add the XSLT
relevant tags around it.
Example
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="*">
<rfc:BAPI_FLIGHT_CHECKAVAILIBILITY xmlns:rfc="urn:sap-
com:document:sap:rfc:functions">
<AIRLINEID>LH</AIRLINEID>
<CONNECTIONID>0400</CONNECTIONID>
<FLIGHTDATE>2002-09-01</FLIGHTDATE>
<RETURN />
</rfc:BAPI_FLIGHT_CHECKAVAILIBILITY>
</xsl:template>
</xsl:stylesheet>
3. Now you need the source XML file. If you have a proxy interface, you have to send data with it,
so write a test program or use the test mode of transaction code SE24 for the method, which is
related to the proxy interface. You find the XML file in the monitor of the XI system.
Example
The interface Flight_CheckAvailability_Out gives that XML file:
<?xml version="1.0" encoding="utf-8" ?>
<ns1:Flight_CheckAvailability_In_Req xmlns:ns1="http://sap.com/xi/xidemo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AirlineID>LH</AirlineID>
<ConnectionID>0400</ConnectionID>
<FlightDate>2002-10-01</FlightDate>
</ns1>
4. Within XSLT file, you have already created, you replace the constant values with the xsl
command value-of and the corresponding tags in the source file (be aware of lower case/upper
case)
Example
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="*">
<rfc:BAPI_FLIGHT_CHECKAVAILIBILITY xmlns:rfc="urn:sap-
com:document:sap:rfc:functions">
<AIRLINEID>
<xsl:value-of select="AirlineID" />
</AIRLINEID>
<CONNECTIONID>
<xsl:value-of select="ConnectionID" />
</CONNECTIONID>
<FLIGHTDATE>
<xsl:value-of select="FlightDate" />
</FLIGHTDATE>
<RETURN />
</rfc:BAPI_FLIGHT_CHECKAVAILIBILITY>
</xsl:template>
</xsl:stylesheet>
Tables
If you want to send a specified structure several times (tables), you can use the xsl command for-each,
which you put before the first tag of the repeated structure
Example
Target:
<?xml version="1.0" encoding="utf-8" ?>
<rfc:PROXY_BAPI_FLIGHT_RESERVE xmlns:rfc="urn:sap-
com:document:sap:rfc:functions">
<PASSENGER_DATA>
<item>
<PASSNAME>Donald Duck</PASSNAME>
<PASSFORM>Mr</PASSFORM>
<PASSBIRTH>1978-04-03</PASSBIRTH>
</item>
<item>
<PASSNAME>Daisy Duck</PASSNAME>
<PASSFORM>Mrs</PASSFORM>
<PASSBIRTH>1982-06-05</PASSBIRTH>
</item>
</PASSENGER_DATA>
<RETURN />
</rfc:PROXY_BAPI_FLIGHT_RESERVE>
The tag item is the first, which has to be repeated.
Source:
<?xml version="1.0" encoding="utf-8" ?>
<ns1:FlightBooking_Reserve_Out_Req xmlns:ns1="http://sap.com/xi/xidemo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<PassengerData>
<PassengerName>Donald Duck</PassengerName>
<FormOfAddress>Mr</FormOfAddress>
<PassengerBirthDate>1978-04-03</PassengerBirthDate>
</PassengerData>
<PassengerData>
<PassengerName>Daisy Duck</PassengerName>
<FormOfAddress>Mrs</FormOfAddress>
<PassengerBirthDate>1982-06-05</PassengerBirthDate>
</PassengerData>
</ns1:FlightBooking_Reserve_Out_Req>
The tag PassengerData is the first to be repeated.
The XSLT file is like this:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="*">
<rfc:PROXY_BAPI_FLIGHT_RESERVE xmlns:rfc="urn:sap-
com:document:sap:rfc:functions">
<PASSENGER_DATA>
<xsl:for-each select="PassengerData">
<item>
<PASSNAME>
<xsl:value-of select="PassengerName"/>
</PASSNAME>
<PASSFORM>
<xsl:value-of select="FormOfAddress" />
</PASSFORM>
<PASSBIRTH>
<xsl:value-of select="PassengerBirthDate" />
</PASSBIRTH>
</item>
</xsl:for-each>
</PASSENGER_DATA>
<RETURN />
</rfc:PROXY_BAPI_FLIGHT_RESERVE>
</xsl:template>
</xsl:stylesheet>
Further Information
You find a very good introduction about XSLT here:
http://www.w3schools.com/xsl/xsl_transformation.asp