« SOAP FAQ | Main | XSLT 2.0 »

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>

Comments (11)

yael:

hello
I dont understand how to declare the propertiesXMLVar.
can i download the bpel process code from somwhere?

Ramkumar Menon:

Please find the BPEL Project that illustrates the functionality at the following link.
http://blogs.oracle.com/ramkumarMenon/gems/TestXSLParams.zip

the variable propertiesXMLVar is defined in the params.xsd as mentioned in the project.

Joy:

Hi Ramkumar,

Actually when I tried the passing the parameters I skipped one of the step of populating the properties object and populated with a assign and was able to do that but that didn't work.

I even tried replacing the transformation of populating with a simple assign, in your TestXSLParams project and it dint work. Please suggest me more on this and if you want to verify the mistake I am doing please also suggest me a web-location/mailid to put my code there. Thankyou

Is this workaround still needed to be able to copy values from a known variable in the bpel-process in a transform-activity?

Why can't I just use the 'xpath-expression' function to get the value of a variable?

I should be able to reference all known variables within my bpel process inside a transform-activity and not only the attributes/values of the source.

Kind regards,
Nathalie

Ramkumar Menon:

BPEL variables are only available in the context of the BPEL process, and are not directly available in the context of XSLT.

shakram:

Hi Ram,

Thanks for the detailed example.

Is it possible to transform all my BPEL process variables into this params file so that i can send this and access all of my variables in the transformation

Thanks,
shakram

Ramkumar Menon:

You can only pass scalar content [strings] as parameters.

Hi Ram,

First I�ll give my scenario, please help me out.

1.xsd
<orders>
<crmorder>
<orderId>
<customerName>
<phoneNumber>
</crmorder>
<Billingorder>
<accNumber>
<billPlan>
<billType>
</Billingorder>
</orders>

2.xsd
<service>
<externalID>
<InternalID>
</service>

3.xsd
<Final>
<BillOrder>
<Account>
<orderId>
<customerName>
<phoneNumber>
<accNumber>
<billPlan>
<billType>
<externalID>
</Account>
<Service>
<InternalID>
<Status>
</Service>
</BillOrder>
</Final>
------------------------------
for 1.xsd, I mapped to requestmessageType and variable is var1
for 2.xsd, I created new MessageType and variable var2
for 3.xsd ,I created new MessageType and Variable var3
------------------------------

Now i need one Transformation,in that have to map both var1 and var2 to var3(1.xsd,2.xsd to 3.xsd)

for this I have to use multiple sources to transformation but it is not possible..

I tried ur sample processees but getting error in first transformation.

Thanks In Advance

Hi Ram,
Thanks for the example,it's very helpful.

Ed:

Great post. Keep up the great work !

HPN:

Hi,

I have a question about this method.

If you already have a source and target for the Transform activity (XSL), is it then possible to get these parameters available within the activity as well ?
I have tried to do so, but can't get it to work. Seems the problem is I can only have 1 source, so either the source will be the result of a DB-adapter or the parametersXSL, ref from expression below:

<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>


Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on May 7, 2007 9:10 PM.

The previous post in this blog was SOAP FAQ.

The next post in this blog is XSLT 2.0.

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

Powered by
Movable Type and Oracle