Passing parameters to ora:processXSLT

When processing XML with XSLT you can easily pass values handled as global parameters to an XSLT script. The BPEL XPath extension function processXSLT offers the same kind of functionality, even though this is not obvious at first glance.

The BPEL Process Manager Developer’s Guide describes processXSLT as “a function that returns the result of an XSLT transformation” and defines the signature as

ora:processXSLT(template,input,properties?)

where template is the name of the XSLT file, input referes to the XML strcuture on which the transformation is run and properties are “The properties as defined in the bpel.xml file”.

That’s an information , isn’t it? I’m sure you’ve immediately understood what to do. Well, I was puzzled.

After some research I found out that properties conforms to name/value pairs complying to the following schema definition:

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://schemas.oracle.com/service/bpel/common"
            targetNamespace="http://schemas.oracle.com/service/bpel/common"
            elementFormDefault="qualified">
  <xsd:element name="parameters">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="item" minOccurs="1" maxOccurs="unbounded">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="name" type="xsd:string"/>
              <xsd:element name="value" type="xsd:string"/>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

You can put this definition into a file, name it for example “Parameters.xsd” and import it into your WSDL file to make it available to your BPEL process.

In your BPEL file you first define the namespace of the structure as part of the <process>-element, e.g. as xmlns:bco=”http://schemas.oracle.com/service/bpel/common&#8221; and declare a matching variable:

<variable name="Parameters" element="bco:parameters"/>

Then you fill the variable with an XML fragment that declares the parameters you want to pass to processXSLT. This way you can dynamically assign values to the items within the fragment in one of the upcoming steps.

Now that we’ve done all the basic preparation I’d like to show you how to proceed by example. First we simply create two parameters named ParamOne and ParamTwo and copy their einclosing XML fragment into the above defined variable Parameters.

<assign>
	<copy>
	  <from>
		<parameters xmlns="http://schemas.oracle.com/service/bpel/common">
		  <item>
			<name>ParamOne</name>
			<value/>
		  </item>
		  <item>
			<name>ParamTwo</name>
			<value/>
		  </item>
		</parameters>
	  </from>
	  <to variable="Parameters" query="/bco:parameters"/>
	</copy>
</assign>

Next we assign the current date and time to the first parameter (ParameterOne) and a value that we received (for example) from the invocation of a service to the second parameter (ParameterTwo).

<assign>
	<copy>
	  <from expression="ora:getCurrentDateTime()"/>
	  <to variable="Parameters"
		  query="/bco:parameters/bco:item[1]/bco:value"/>
	</copy>
	<copy>
	  <from expression="bpws:getVariableData('Invoke_callDummy_OutputVariable','payload',
                                                 '/ns17:callDummyResponseElem/ns17:Value')"/>
	  <to variable="Parameters"
		  query="/bco:parameters/bco:item[2]/bco:value"/>
	</copy>
</assign>

Now that we have filled our parameters with life, we can pass the data to the processXSLT call – let’s assume that myVar contains some kind of XML structure on which the transformation is executed.

<copy>
  <from expression="ora:processXSLT('myTransformation.xsl', bpws:getVariableData('myVar'),
                                    bpws:getVariableData('Parameters'))"/>
  <to variable="InputVariable_P" part="payload"
		  query="/loc:MyLocalElem"/>
</copy>

In order to access the passed information we simply declare two global parameters within myTransformation.xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xsl:param name="ParameterOne"/>
    <xsl:param name="ParameterTwo"/>

<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
...

Actually, that’s it. Now you can access the parameters with $ParameterOne and $ParameterTwo everywhere in your XSLT.

Advertisements
Posted in BPEL, SOA. 3 Comments »

3 Responses to “Passing parameters to ora:processXSLT”

  1. pavan Says:

    Hi,

    You explanation is very clear. Thanks for providing such a valuable information. I’m trying the same in my project and getting following error while deployment of composite.

    [scac] error: in XXX.bpel(68): XML element “{http://schemas.oracle.com/service/bpel/common/}parameters” of variable “Parameters” is not defined

    Could you please help me in this and also could you clarify me on the following

    1) If i access $ParameterOne in my xslt, will i get name-value pair or only value.
    2) If i get name-value pair, can i use $ParameterOne/name & $ParameterOne/value for getting the name & value.

    Thanks in advance.

    -Pavan

    • ake Says:

      Hi Pavan,

      I assume you are getting the error because you haven’t created a schema file with the type definitions (Parameters.xsd) and imported it into your WSDL.

      1) You’ll get the value. In the key/value-pair the key simply refers to the name of parameter as it is being used in the XSLT.
      2) $ParameterOne actually is the name of the key.

      I hope I could help you with my response.

      Cheers
      – Alex

  2. Jesús Says:

    Hi Alex,

    I really want to thank you your time for writing this article. Without a doubt, it has helped me a lot after spending more than 7h trying to develop such behaviour. However, once i came across with your post, I could solve my issue.
    As you said, the guide wasn’t clear at all, and I was puzzled too!!
    Thank you very much dude.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: