Académique Documents
Professionnel Documents
Culture Documents
Mapping in SAP PI
MAY 15, 2010 BY RIYAZ
When the required output is other than XML like text, html or
xhtml
When data is to be filtered based on certain fields
When data is to be sorted based on certain field
When data is to be grouped based on certain field
Now open source xml file in browser. This will show you
transformed output and not the actual source xml file. This method
however will not display the XML tags. You will only see the content
of the XML elements. To see XML tags you will need one of the
software listed above or similar ones.
Basics of XSLT
XSLT is used to transform an XML document into another XML or
other type of document that is recognized by a browser, like HTML
and XHTML. With XSLT you can add/remove elements and
attributes to or from the output file. You can also rearrange and sort
elements, perform tests and make decisions about which elements
to hide and display, and a lot more. Lets understand some
commonly used XSLT elements –
XSLT Transform
The root element that declares the document to be an XSL style
sheet is <xsl: stylesheet> or <xsl: transform>. The correct way to
declare an XSL style sheet according to the W3C XSLT
recommendation is –
or
XSLT <template>
An XSL style sheet consists of one or more set of rules that are
called templates. Each template contains rules to apply when a
specified node is matched. The <xsl: template> element is used to
build templates.
XSLT <value-of>
The <xsl:value-of> element can be used to extract the value of an
XML element and add it to the output stream of the transformation.
XSLT <for-each>
The <xsl:for-each> element allows you to do looping in XSLT. The
XSL <xsl:for-each> element can be used to select every XML
element of a specified node-set.
XSLT <sort>
The <xsl:sort> element is used to sort the output. To sort the output,
simply add an <xsl:sort> element inside the <xsl:for-each> element
in the XSL file.
XSLT <if>
The <xsl:if> element is used to put a conditional test against the
content of the XML file. To put a conditional if test against the
content of the XML file, add an <xsl:if> element to the XSL
document.
<xsl:if test="expression">
... ...
some output if the expression is true
... ...
</xsl:if>
XSLT <choose>
The <xsl:choose> element is used in conjunction with <xsl:when>
and <xsl:otherwise> to express multiple conditional tests.
<xsl:choose>
<xsl:when test="expression">
... some output ...
</xsl:when>
<xsl:otherwise>
... some output ....
</xsl:otherwise>
</xsl:choose>
XSLT Examples
W3Schools website has good examples to understand each of
these elements. Study these XSLT Examples to gain better
understanding.
Name of the XSL file would be visible under the Archive Program
section. Save and activate the changes.
Share Now:
XSLT Mapping – A Simple
Example
MAY 16, 2010 BY RIYAZ
<?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.
Pre-requisites
XSL – Extensible Style sheet Language
XSLT – XSL Transformations, the purpose of this is for transformation of XML documents
into other formats like XML, XHTML and etc.
XPATH – XSLT uses XPATH to find information in an XML document. XPATH is used to
navigate through elements and attributes in XML documents.
Steps required for developing XSLT Mapping
Create a source data type and a target data type
Create Message types for the source and target data types.
Create Message Interfaces includes Inbound Message interface and Outbound Message
interface.
XSLT Mapping does not require creation of Message mapping, so don’t create any Message
mapping.
Create an .XSL file which converts source data type into target data type.
Zip that .xsl file and import it into Integration Repository under Imported Archives.
In Interface Mapping choose mapping program as XSL and specify this zip program.
(Through search help you will get XSL Mapping programs that you imported under Imported
Archives, select your corresponding XSL Program)
Test this mapping program by navigating to Test tab.
By having look at above steps you can easily find out that this mapping is no where different from
other mapping programs, here the challenging lies in creating an XSLT file. If you spend couple
of minutes in studying XPATH tutorial you would be in ideal position to create an XSL
Transformation (.xsl extension).
If you still find difficulties in generating XSL Transformation, then you can make use of a tool
“Altova MapForce” which will create XSL file for you.
Here the target system expects the xml files in CIDX format, so XI system takes IDoc as an input
and converts it to an XML file adhering to CIDX naming standards.
SAP PI Interview Questions and SAP PI Tutorials
– Import needed IDoc structure into IR, in our scenario import IDocDESADV.DELVRY03
– Import corresponding XSD structure under External Definitions in IR. Here the
corresponding CIDX message is Load Tender Motor.
– Import ZIP file corresponding to XSLT under Imported Archives in IR, which can
transform source message to target structure.