Skip to Content

In this blog I want to show you the way of getting user-defined parameters within XSL transformation without using any custom java classes and Dynamic Configuration.

But first, I would like to thank Nikolay Yasinskiy very much, whos valuable suggestion threw the light on how the Operation mapping input parameters can be accessed directly using java extensions mechanism.

Described approach is based on using poorly documented input parameter “TransformationInput”, which is passed to XSL transformation among the other parameters.

So, in order to use this parameter we should add the line to our XSL stylesheet:

<xsl:param name="TransformationInput">

At next step we just get parameter value using java extensions mechanism and types casting possibilities.

Here is an example stylesheet demonstating the approach described above:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:ti="java:com.sap.aii.mapping.api.TransformationInput"
                xmlns:inpar="com.sap.aii.mapping.api.InputParameters"
                xmlns:xsltc="http://xml.apache.org/xalan/xsltc"
                exclude-result-prefixes="xs ti inpar xsltc"
    version="1.0">
    
    <xsl:param name="TransformationInput"/>
    
    <xsl:template match="/">
        <xsl:variable name="myparam" select="inpar:getValue(ti:getInputParameters(xsltc:cast('com.sap.aii.mapping.api.TransformationInput',$TransformationInput)),'MyParam')" />
        <ExampleMessage>
            <Param name="MyParam"><xsl:value-of select="$myparam"/></Param>
        </ExampleMessage>
    </xsl:template>

</xsl:stylesheet>

As you can see, neither custom java classes nor Dynamic Configuration as transport layer were involved.

Now we can define the needed parameters in Operation mapping editor and bind it to respective XSL mapping. That’s all.

Update: During further investigation I could find another parameter called “inputParameter”. Using it instead of “TransformationInput” parameter makes things even easier:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:inpar="com.sap.aii.mapping.api.InputParameters"
                xmlns:xsltc="http://xml.apache.org/xalan/xsltc"
                exclude-result-prefixes="xs inpar xsltc"
    version="1.0">
    
    <xsl:param name="inputParameter"/>
    
    <xsl:template match="/">
        <xsl:variable name="myparam" select="inpar:getValue(xsltc:cast('com.sap.aii.mapping.api.InputParameters',$inputParameter),'MyParam')" />
        
        <ExampleMessage>
            <Param name="MyParam"><xsl:value-of select="$myparam"/></Param>
        </ExampleMessage>
    </xsl:template>

</xsl:stylesheet>

Hope it helps!

Regards, Evgeniy.

To report this post you need to login first.

11 Comments

You must be Logged on to comment or reply to a post.

  1. Anurag Gupta

    Are these parameters ‘inputParameter’ or ‘TransformationInput’ predefined parameters which SAP PI operation mapping recognizes ?

    what if I defined a parameters whose name is of my choce ?

    (0) 
    1. Evgeniy Kolmakov Post author

      Hi Anurag!

      These are the parameters (actually, java class instances) which are passed to any mapping program by mapping runtime.

      When you define the parameter in Operation mapping, its name and actual value are added to InputParameters map before mapping program executing.

      If you have ever used java mapping classes, you would use the interface AbstractTransformation and its method transform(TransformationInput in, TransformationOutput out).

      Using this method’s parameters we can get access to InputParameters, OutputParameters, InputHeader, OutputHeader and so on, using respective getter and setter methods.

      Regards, Evgeniy.

      (0) 
      1. Anurag Gupta

        Okay, I understand. The Java code which you have posted as image, where have to taken it from ? PI internal ?

        So it is basically the map names like inputparam, TransformationInput, inputParameter and inputHeader. The mapping runtime sets all these map names.

        I also see from the java program that inputparam and inputHeader is more or less same and both of their existence is confusing. Though I get some reference of inputparam from this link on how to use in XSLTs

        https://help.sap.com/saphelp_nwpi71/helpdata/EN/43/bbb7fd90f5332ee10000000a11466f/frameset.htm

        Thanks anyways !

         

        (0) 
        1. Evgeniy Kolmakov Post author

          Hi Anurag!

          Yes, provided Java code was taken from internal classes used by mapping runtime.

          Frankly speaking, I’m not aware about the reasons why the mapping parameters are passed this way, for example, why the contents of InputHeader are passed again like separate parameters along with InputHeader itself. I guess there must be some reason for it, for example, if one uses external XSLT transformer – he wouldn’t be able to use java extensions or casting.

          Regards, Evgeniy.

          (0) 
  2. Piotr Radzki

    This is great Evgeniy!

    I was looking for such “clean” solution for some time.

    I have just implemented it in my WebService scenario for parametrization and it works like a dream.

    Thanks!

    BR,

    Piotr

    (0) 
  3. Eng Swee Yeoh

    Hi Evgeniy

     

    Thanks for sharing this approach which utilizes knowledge of how the internal PI classes work. It is a really valuable contribution to the community.

     

    I happen to have one such development few months back, and if only this was available back then, I wouldn’t have had to go through the whole Dynamic Configuration and additional Java helper class.

     

    Thanks!

    Eng Swee

     

     

    (1) 

Leave a Reply