Skip to Content
Author's profile photo Evgeniy Kolmakov

Getting user-defined Operation mapping parameters from XSL transformation

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.

Assigned Tags

      16 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Stanyslav Bobrovskiy
      Stanyslav Bobrovskiy

      Evgeniy, great blog!

      Thanks!

      Author's profile photo Evgeniy Kolmakov
      Evgeniy Kolmakov
      Blog Post Author

      Hi Stanyslav!

      Thank you very much for your positive feedback!

      Regards, Evgeniy.

      Author's profile photo Muni M
      Muni M

      Thanks Evgeniy for providing simplified approach. Quickly tested on my system and it works fine.

      Author's profile photo Evgeniy Kolmakov
      Evgeniy Kolmakov
      Blog Post Author

      Hi Muni!

      Glad if this helps.

      Regards, Evgeniy.

      Author's profile photo Anurag Gupta
      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 ?

      Author's profile photo Evgeniy Kolmakov
      Evgeniy Kolmakov
      Blog 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.

      Author's profile photo Anurag Gupta
      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 !

       

      Author's profile photo Evgeniy Kolmakov
      Evgeniy Kolmakov
      Blog 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.

      Author's profile photo Piotr Radzki
      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

      Author's profile photo Eng Swee Yeoh
      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

       

       

      Author's profile photo Evgeniy Kolmakov
      Evgeniy Kolmakov
      Blog Post Author

      Hi Eng Swee!

      Thank you very much for this feedback!

      Regards, Evgeniy

       

      Author's profile photo David Jira
      David Jira

      Hi Evgeniy,

       

      really great blog! Easily explained and clear!

      I was looking for just this solution for quite a long time.

       

      Regards

      David

      Author's profile photo Evgeniy Kolmakov
      Evgeniy Kolmakov
      Blog Post Author

      Hi David!

      Thank you very much for your feedback!

      Regards, Evgeniy.

      Author's profile photo Sesuraj P
      Sesuraj P

      Hi Evgeniy,

      I tried your code in my environment. I just created one parameter in my operation mapping and binding it my xslt mapping. I just copy and past your code in my xslt file. But i am getting following error. Please help to fix this. I will be more thankful.

      Error:

      javax.xml.transform.TransformerException: com.sap.engine.lib.xsl.xpath.XPathException: Illegal number of arguments or types of arguments in a call of function ‘inpar:getValue’.
      Author's profile photo Evgeniy Kolmakov
      Evgeniy Kolmakov
      Blog Post Author

      Hi Sesuraj!

      I hope that you changed parameter name in XSLT code after copying. Also check if you set parameter’s name in OM (and MM binding) exactly like in XSLT code. Parameter names are case-sensitive.

      If it all looks good - check if "Use SAP XML Toolkit" option is switched off in OM settings.

      Regards, Evgeniy.

      Author's profile photo ???? ???????
      ???? ???????

      Hi Evgeniy.

      This is solution not work in SAP PI 7.10. It is works only with SAP PI 7.11 and later.

      Notes 1731772, 1731853, 1731354.

      Regards, Ivan.