26 April 2010

Using XSL Parameters in SOA 11g

In SOA 11 suite 11g , transformation activity comes with a added functionality which allows to add parameters from the JDeveloper GUI.

Steps are pretty simple :

1) Create a new composite with bpel and add a transform activity to it
2) Open the activity which looks like this :



3) Click the green plus symbol to add a variable
4) Here the first variable that is added becomes the source for the transformation activity.
One can also add more than one variable. These additional variables appear as parameters in the transform file.
5) After adding input variables, add the output variable and click apply to open the xsl mapper.
6) It can be seen that the additional variable(s) appear as parameters in the mapper activity automatically.
No code change is required as such and one can directly map the values from XSL Mapper.



In the source view for the transform file ,following points can be observed :

1) For each source variable , there is a entry in the oracle-xsl-mapper section of xsl file.



2) For the first variable, this entry gives schema location and root element name
3) For all other variables, this entry also specifies name of the parameter with with the variable is referred in the XSL map.
The parameter name follows the naming convention as VARIABLE_NAME.VARIABLE_PART_NAME
4) Also, as expected, each parameter is defined just after the xsl:stylesheet tag.
5) Child nodes in the parameters are accessed using syntax : $param_name+ + XPath expression for the node.


In the BPEL process source, normally, when we add a transform
the function used is ora:processXSLT. But in this case, a different extension function is used.
The function name is doXSLTransformForDoc and namespace is "http://schemas.oracle.com/xpath/extension" which
can be accessed using prefix 'ora'

This function (ora:doXSLTransformForDoc) has following signature :

ora:doXSLTransformForDoc('url_to_xslt',input,['paramQname',paramValue]*)
where
url_to_xslt - Specifies the XSL style sheet URL. (occurrence = 1)
input - Specifies the input variable name. (occurrence = 1)
paramQname - Specifies the parameter QName. (occurrence >= 1 )
paramValue - Specifies the value of the parameter. (occurrence >= 1 , same as paramQname )



More parameters can be added to this function after the transform is created.
This can be done by
1)Add the parameter name and value in the signature
2)Add source xsd details in the xsl top section along with param name
3)Add param defination after stylesheet element tag

Note that if there are no additional variables present at the time of creating the transform activity, then the
standard processXSLT funtion is used instead of doXSLTransformForDoc.


A simple POC for this can be found here


Adding source variables after the mapping is created   

If you  try to add a source variable to a transformation activity, after the mapping is created , the new variable is not displayed in the XSL mapper. To overcome this , there are two options :
1. Recreate the mapping
2. Edit the mapper file from back-end  to add the new variable

Recreating is  simpler option but if you have already number of variables present as the input , then this can mess up sometimes..

Editing the mapper file is a safe way to add new variables without touching the old mapping. Just do these steps:
1. Add the variable using the green plus symbol in the transform activity. Click Apply and then click pencil button to open the XSL Mapper.
2. Go to source view of mapper. Go to the top section where sources are defined in the oracle-xsl-mapper block.  In the "mapSources" element go to end and  add a entry for the newly added source variable. Entry looks like : 


 Things you need to modify are :
  • Source type : can be XSD or WSDL
  • Schema details : location,  root element name and namespace
  • Parameter name : follow naming convention as mentioned above.
3. Add the schema namespace to the list of referred namespaces in the stylesheet tag using xmlns tag. It will be something like :
xmlns:new="http://www.my.poc.in/br_input"

4. Add the parameter after the stylesheet tag and before the templates  :

<xsl:param name = "myVar.payload" /> 

5. Save , close and re-open the XSL mapper file. Go to design view and verify that the parameter is added correctly.










6 comments:

Kartik said...

Hi,

Can you post the PoC rar file for the reference, please?

The google group does link does not work.

Mahesh Upadhyay said...

Ketan,

Can you please send me this POC to below email address?

mahesh_con@hotmail.com

Thanks,
Mahesh

Karthikeyan P R said...

Ketan,

I have a case where a webservice is invoked twice from bpel. The output variables (same xsd since its a repeated call) as a result of these two invoke activities need to go through a trnaformation whose result variable is the same. Will the values of first transformation get overridden or appended to the second transformation. Do i need to use transformation twice or Can i achieve it by passing these two variables as parameters to the same transformation function?

Ketan said...

A transformation always overwrites the data in target variable. So a second transfrom would not help since it would overwrite any data that is mapped using first transformation. You would have to either use one transformation and then an assign activity or if the second transformation can be delayed then better use single transform with both variables as input.

Unknown said...

can anybody plz send me this POC?

vipul1990verma@gmail.com

Sanddy said...

Thank you. This blog helps me a lot.