Tuesday, 30 April 2013

Passing dynamic param to XSLT


There is no direct approach to it.However,looking into ora:XSLT signature,I found that we can pass BPEL variables as properties.Alternatively,one can pass multiple inputs in SOA 11g.

First things first,

                   1.>   params.xsd needs to be imported to project folder.The schema is structures as below:--

<?xml version="1.0" encoding="windows-1252" ?>
<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">
  <!-- Root Element for Parameters -->          
  <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>

2.> Define a variable of element type corresponding to above xsd. Let the name be parameterVar.

3    3.> Go to the composite.xml. Add the preference property as in the example below:--

  <component name="TestParams">
<implementation.bpel src="TestParams.bpel"/>
 <property name="bpel.preference.myPreference">HelloThere</property>
    </component>
4.                        
             4.>Go to the BPEL editor and drag a Assign activity. Following is how the resulting source code look like:--
                          <assign name="Assign_1">
            <copy>
                <from expression="indexName"/>
                <to variable=" parameterVar "
                    query="/ns4:parameters/ns4:item/ns4:name"/>
            </copy>
            <copy>
                <from expression="ora:getPreference('myPreference')"/>
                <to variable=" parameterVar "
                    query="/ns4:parameters/ns4:item/ns4:value"/>
            </copy>
        </assign>
5.                                                                                                                                                                                                                              

             5.> Drag a Transform activity. This will be the transformation from parameterVar to parameterVar. Map name to name and value to value inside transformation.
            <assign name="Transform_1">
            <bpelx:annotation>
                <bpelx:pattern>transformation</bpelx:pattern>
            </bpelx:annotation>
            <copy>
                <from expression="ora:processXSLT('xsl/Transformation_1.xsl',bpws:getVariableData(parameterVar))"/>
                <to variable=" parameterVar "/>
            </copy>
   </assign>
6.                                                                                                                                                                                                                                                                    

              6.>Once the above steps are completed. Next comes the passing of BPEL variable as third parameter in ora:XSLT signature. Inside the transformation, you need to add
 <xsl:param name=" indexName "/>. Note that indexname is same as assigned to name node of the  parameterVar.

Now this param can be used anywhere inside your XSLT by $indexName.


<assign name="MainXSLT">
            <bpelx:annotation>
                <bpelx:pattern>transformation</bpelx:pattern>
            </bpelx:annotation>
            <copy>
                <!-- Pass the additional Parameter <i> parameterVar </i> for the XSL Parameters -->
                <from expression="ora:processXSLT('TestParams.xsl',bpws:getVariableData('inputVariable','payload'),bpws:getVariableData(parameterVar))"/>
                <to variable="outputVariable" part="payload"/>
            </copy>
        </assign>

                     


Read more: http://www.soabyte.com

1 comment:

  1. Hi Sujan ,
    Your blog is so informative !
    I need your help . I have a bpel service , in which i invoke a db adapter and get some invoice ids . I have to take these invoice ids and add some parameters to it , and invoke a web service to get a detailed invoice corresponding to tht invoice id . i did thi susing an xml fragment in an assign activity . It is working fine , for one invoice id. But i need it ot work for multiple invoice ids returned by my db adapter . For this , am i supposed to add a transform activity instead of assign ? In that case how do i include tht xml fragment in xslt ? Please help me with a solution . Im really in need . Thank you

    ReplyDelete