Blogs

XI for Beginners - simple XSLT - Part 1
Peter Munt
Business Card
Company: SCC
Posted on May. 13, 2008 12:46 AM in SAP Exchange Infrastructure (XI)

Subscribe.Subscribe
Print. Print
Permalink Permalink

This blog will show you the basics of XI, XSLT and the Graphical mapping tool.  This should give the XI beginner a very basic idea of how to use the SLD, Repository, namespaces, data types and mappings.

If you are like me you are probably just itching to get your hands dirty.  So first up let's assume you have a XI userid - note that probably at first logon you will need to first logon to XI via SAPGUI to reset the password.  You'll also need Java version 1.4+ and Java webstart installed on your PC - get this from Sun website  http://java.sun.com/products/javawebstart/download.jsp

Then you can use the webinterface http://<yourXIserver>:50000/rep/start/index.jsp or fire it up via SAP GUI XI transaction SXMB_IFR.

XI Home

SLD

I will not be explaining the SLD in this blog, suffice to say that we just need some place to place the work we are going to do.

Assuming that your userid has the rights to add or even view components in the SLD you'll need to go to the SLD Software Catalog.  It is not usual for this to be locked out for developers and if so then you'll probably need to ask Basis to do this.  That will teach them for being so restrictive!.

SLD HomeNew Product

Click on Product and Select New Product

Then it will prompt for Software Unit Component - so type that in.

SW UnitSW Unit

And now add the Software Component - this will be the one imported into the Integration Builder.

SWCV

Integration Builder

Start the Integration Builder from the XI webpage menu.

Add the Software Component you just created to the list

Add SWCV to IB

Notice that it is empty to start with.  You need to add a namespace to it.  This allows you to group all your stuff under the namespace.  I prefer to use urn: rather than http: for my namespaces.

Adding the namespace

Quick XML guide

OK now we have set up a place for us to create something.   What we will do is create a very simple XSLT conversion.  An XML about Coffee will be converted by a XSLT into another XML.  

 

That is very easy to do if you have a reasonable idea of how XSLT works.  It will help you, even using the XI Graphic mapping, to understand the concepts - tree navigation, nodes, context etc.  I would recommend you go and buy XSLT for Dummies or one of the many teach yourself XSLT sites and study further on this subject see http://www.w3schools.com/Xsl/default.asp  

If you don't have one then get an XSLT editor.  E.g. Download this free tool -  http://xmlcooktop.com/   You can use Cooktop to quickly check any XSLT you prepare before diving into XI.

Here is some XML and XSLT for you to try - these are from the XSLT for Dummies book by Richard Wagner

The Source XML

<?xml version="1.0"?>
<coffees>
 <region name="Latin America">
  <coffee name="Guatemalan Express" origin="Guatemala">
    <taste>Mild and Bland</taste>
    <price>11.99</price>
    <availability>Year-round</availability>
    <bestwith>Breakfast</bestwith>
  </coffee>
  <coffee name="Costa Rican Deacon" origin="Costa Rica">
    <taste>Exotic and Untamed</taste>
    <price>12.99</price>
    <availability>Year-round</availability>
    <bestwith>Dessert</bestwith>
  </coffee>
 </region>
 <region name="Africa">
  <coffee name="Ethiopian Sunset Supremo" origin="Ethiopia">
    <taste>Exotic and Untamed</taste>
    <price>14.99</price>
    <availability>Limited</availability>
    <bestwith>Chocolate</bestwith>
  </coffee>
  <coffee name="Kenyan Elephantismo" origin="Kenya">
    <taste>Solid yet Understated</taste>
    <price>3.99</price>
    <availability>Year-round</availability>
    <bestwith>Elephant Ears</bestwith>
  </coffee>
  </region>
</coffees>

 

And it's assoiciated DTD

<!ELEMENT availability ( #PCDATA ) >
<!ELEMENT bestwith ( #PCDATA ) >
<!ELEMENT coffee ( taste, price, availability, bestwith ) >
<!ATTLIST coffee name CDATA #REQUIRED >
<!ATTLIST coffee origin CDATA #REQUIRED >
<!ELEMENT coffees ( region+ ) >
<!ELEMENT price ( #PCDATA ) >
<!ELEMENT region ( coffee+ ) >
<!ATTLIST region name CDATA #REQUIRED >
<!ELEMENT taste ( #PCDATA ) >

 

The XSL

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/">
    <coffeemerge>
      <xsl:apply-templates/>
    </coffeemerge>
  </xsl:template>
  <!-- Merge elements to create tagline element -->
  <xsl:template match="coffee">
    <coffee>
      <tagline>This Coffee Is <xsl:value-of select="taste"/> And Best Enjoyed With <xsl:value-of select="bestwith"/></tagline>
      <taste><xsl:value-of select="taste"/></taste>
      <price><xsl:value-of select="price"/></price>
      <availability><xsl:value-of select="availability"/></availability>
      <bestwith><xsl:value-of select="taste"/></bestwith>
    </coffee>
  </xsl:template>
</xsl:stylesheet>

 

And an associated DTD to describe the resulting XML.  Tip : If you don't have one but you have the XML you can use a convertor. You can use a online tool to import and create a DTD   http://www.hitsw.com/xml_utilites/

<!ELEMENT coffeemerge ( coffee+ ) >
<!ELEMENT availability ( #PCDATA ) >
<!ELEMENT bestwith ( #PCDATA ) >
<!ELEMENT coffee ( tagline, taste, price, availability, bestwith ) >
<!ELEMENT price ( #PCDATA ) >
<!ELEMENT tagline ( #PCDATA ) >
<!ELEMENT taste ( #PCDATA ) >


 

XSL Archive

OK got a handle on XML ?  Good now let's do it in XI.  

 

First Zip up the XSLs or ones that you might have created during your visit and learning in the world of XSLT.  Import them into XI  - as can only import these via a zip file.

 

Within the Integration Builder Designer - go to your Software Component Version and namespace you created before.  Expand it and expand Mapping Objects.  Right Click on Imported Archives. Create a new Imported Archive to hold all our XSL for this exercise

Import the zipped files

Edit Imported Archive

Save it.  Then on the left hand navigation pane it will appear.

 

External Definition

Create an external definition to hold the DTD for the Source XML file. With that created select the DTD category and in the Messages choose the First Element.  Import the DTD file and Save it.

Create another External Definition for the Target XML file.  Remember to choose Category DTD and Messages from First Element

Target DTD

 

 

Message Interface

Now we'll need to describe the message interfaces for both the Source and Target files.

 

Again within your SWC Interface Objects, right click on Message Interface - create a new one for the source file.  This is the source's outbound interface - so the category is Outbound.  Choose the corresponding DTD.

Source Message Interface

 

 

We create another for the Target file.  This is the target's inbound interface - so the category is Inbound.  Choose the corresponding DTD.  Leave the fault message type empty.

Target Message Interface

 

Interface Mapping

Create a interface mapping for the Source to the Target via the XSL.  In the left hand navigation pane,  Open the Mapping Objects, right click on Interface Mappings and create.

You can drag and drop or select the Source Interface

And for the Target Interface

Now choose the mapping program as XSL using the one you imported from the zip file you previously set up.

Interface Mapping

Select the Test Tab and click the xmlbutton to import the source XML file (via the XMLimport icon   ) or cut and paste the XML (via the src icon

Press the Test button   - Hopefully you will have a transformed document.

Test Result

So that is a very simple example that introduces some of the concepts of XSLT and XI - you may like to now try some more.

In my next blog I'll show you how to do this via the Graphical Mapping tool.

Peter Munt is a SAP Netweaver Consultant (XI/EP/ABAP/JAVA) for Supply Chain Consulting Australia


Add to: del.icio.us | Digg | Reddit


Comment on this article
Comment on this weblog
Showing messages 1 through 1 of 1.

Titles Only Main Topics Oldest First

  • Very helpful insight
    2008-06-07 04:35:35 Josef Schachinger Business Card [Reply]

    Hello Peter


    Many thanks for this great blog.
    Only some hints which very very helpful for me.
    For the source DTD I cut and past the line "<!ELEMENT coffees ( region+ ) >" to the first row because than the messages structure is shown in the right structure (coffees is the root element in this structure). If you do this it is necessary to update the Message Interfaces and Interface Mapping because XI will not do this by its own.


    Additionally I pad in the trap and named the mapping file with an extension xslt. As I tried to add this to the Interface Mapping I got the error "... has no program". As I reread your blog I found my mistake and renamed the mapping file to xsl and archived it once again and then everything was fine.


    For the target Message Interface is the wrong picture shown, as you mentioned it is a Inbound Interface.


    Many thanks once again for this I was very helpful to me.


    Josef


Showing messages 1 through 1 of 1.