« May 3, 2007 | Main | May 21, 2007 »

May 7, 2007 Archives

May 7, 2007

Passing BPEL Variable contents into XSLT as Parameters

Here is an interesting solution for passing content of BPEL variables into XSL Transformations as XSL Parameters.

XSL is executed using the XPath Extension Function ora:processXSLT. The two arguments for this extension function are as follows.

1) The XSL File Name
2) The source variable to be transformed [bpws:getVariableData(...)]

But there is one more argument that this XPath function can accept - 'properties'.
Note the signature of this function specified in xpath-functions.xml

Signature:  ora:processXSLT('template','input','properties'?).

These properties translate to XSL Parameters that can be accessed within the XSL Map using the construct
 <xsl:param name="<paramName>"/>

You can retrieve the value of this parameter within your XSLT in a way similar to the way used to extract data from XSL variables.

For e.g.  <Name><xsl:value-of select="$param1"/></Name>

 

 The "properties" argument of the XPath function is expected to be an XML Element that has the following structure.

Illustrated below is an example of such a properties XML.

<parameters xmlns:ns2="http://schemas.oracle.com/service/bpel/common" xmlns="http://schemas.oracle.com/service/bpel/common">
  <ns2:item>
    <ns2:name>userName</ns2:name>
    <ns2:value>ramkmeno</ns2:value>
  </ns2:item>
  <ns2:item>
    <ns2:name>location</ns2:name>
    <ns2:value>CA</ns2:value>
  </ns2:item>
</parameters>

Within the XSLT, the parameters are accessible through their names. [in this case, the parameter names are "userName" and "location", and their values are "ramkmeno" and "CA" respectively.

Approach

1) Declare a variable that is of the abovementioned dataType [see XML above.]
2) Populate the variable with the contents of the BPEL variable you wish to pass into the XSLT
3) Invoke processXSLT() with the XSL File, source variable, and the parameters variable.
4) Access the parameter contents within the XSLT

Example

BPEL Snippet

<!--Step 1: initialize the parameters variable from whatever BPEL variable whose information you need to access from within XSLT -->

<assign name="initializeXSLParameters">
    <bpelx:annotation>
      <bpelx:pattern>transformation</bpelx:pattern>
    </bpelx:annotation>
    <copy>
      <from expression="ora:processXSLT('SetParams.xsl',
                bpws:getVariableData('inputVariable','payload'))"/>
     <to variable="propertiesXMLVar"/>
   </copy>
</assign>

<!--Step 2: Invoke the XSLT with the parameters as the third argument -->

<assign name="executeXSLT">
    <bpelx:annotation>
      <bpelx:pattern>transformation</bpelx:pattern>
    </bpelx:annotation>
    <copy>
       <from expression="ora:processXSLT('TestXSLParams.xsl',
            bpws:getVariableData('inputVariable','payload'),
            bpws:getVariableData('propertiesXMLVar'))"/>
       <to variable="outputVariable" part="payload"/>
   </copy>
</assign>

XSLT Snippet

<xsl:stylesheet version="1.0" ....>

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

  <xsl:template match="/">
    <ns1:TestXSLParamsProcessResponse>
      <ns1:result>
        <xsl:value-of select="concat('User : ', $userName, ' Location : ',$location)"/>
      </ns1:result>
    </ns1:TestXSLParamsProcessResponse>
  </xsl:template>
</xsl:stylesheet>

Output

<TestXSLParamsProcessResponse xmlns:ns1="http://xmlns.oracle.com/TestXSLParams" xmlns="http://xmlns.oracle.com/TestXSLParams">
  <ns1:result>User : ramkmeno Location : CA</ns1:result>
</TestXSLParamsProcessResponse>

About May 2007

This page contains all entries posted to Ramkumar Menon's Blog in May 2007. They are listed from oldest to newest.

May 3, 2007 is the previous archive.

May 21, 2007 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle