Sunday, September 18, 2011

SOA 10g - Passing multiple inputs to XSLT in BPEL


BPEL and XSLT - ora:processXSLT

XSLT is processed in BPEL using the method: ora:processXSLT categorized under BPEL XPath Extension Functions.
The input parameters (signature) for the method is as defined by Oracle:

Signature:

processXSLT('template','input','properties'?)

Arguments:

  • template - The XSLT template


  • input - The input data to be transformed

  • properties - The properties as defined in the bpel.xml file


The parameter template is the XSLT that is being used to transform the message content. So this is nothing but the . eg ora:processXSLT('Transform_DummyBloggingStuff.xsl',.....)

The input is the message part whose values needs to taken as an input for completion of the transformation. eg ora:processXSLT('Transform_DummyBloggingStuff.xsl','bpws:getVariableData('dummyBlogger')')

In day to day operation. we come across situation where the output expected from the transformation may require multiple inputs, much like creating "joins"

query.

XSLT engine by default supports multiple input parameters. BPEL development, using JDev does not provide an inbuilt feature of providing multiple inputs to the XSLT operation. But, it provides an optional element called 'properties' in the method signature of the XSLT framework. This optional element is by often overlooked but can be used to a greater extent during code development.


Let us demonstrate:

The properties translated into parameter constructs of the XSLT and can be referenced within the XSLT scope. The property needs to be defined in a specific structure as mentioned.

The definition of the schema contains for the following details:

xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:p="http://schemas.oracle.com/service/bpel/common" xmlns="http://schemas.oracle.com/service/bpel/common" targetNamespace="http://schemas.oracle.com/service/bpel/common" elementFormDefault="qualified"

<?xml version="1.0" encoding="windows-1252"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:p="http://schemas.oracle.com/service/bpel/common" 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>


Consider this schema structure for any variable. A variable will always have a name and a value. eg. a variable x = 100. In case the name of the variable is "x" and the value is "100".

So the parameter variable needs to be set for all the variables which needs to be passed to the XSLT.

Define the XSD in your BPEL project. Create a variable of type global in the BPEL project with name "params" (the name can be anything of your choice)

Let us now consider a situation where in, in one variable "user" we have the username and in another variable "password" we have the password for an account stored. The final payload needs to be constructed which should have both the values. (This is a very trivial example but can be extended to any huge extent depending upon the requirement)

In your BPEL, create a copy operation and provide an expression to the "name" element of the variable "params". May be use the expression builder to assign a value of "userName" to the element "name". Then you can provide a xpath expression to assign the value of userName to the element "value" of the variable "params".

Similarly assign "passwordValue" to the element "name" of the "params" variable and the xpath expression to the value to instantiate the value of the params element.

Now, come down to the XSLT where these elements needs to be accessed. Use XSLT construct to define the param as depicted below:

  <xsl:param name="userName"/>
<xsl:param name="passwordValue"/>

Now the values of the variables can be accessed using a simple expression "$userName" and "$passwordValue"

The job is almost done, but not yet complete.

How does XSLT know what are the values for these variables or param construct?
Of course BPEL has to tell XSLT using the "property" argument of processXSLT operation.

So along with the xslt file template name and input variable in the signature we need to pass the "params" variable as an argument to the processXSLT method in the bpel.xml

So the snippet of the the signature would appear as mentioned below:

ora:processXSLT('Transform_DummyBloggingStuff.xsl',
'bpws:getVariableData('dummyBlogger')',
'bpws:getVariableData('params')')


JOB Done!!!!

For further queries please do not hesitate to contact me : souvik17.9@gmail.com