1.4.2008

How to use parameters for transformations in Oracle BPEL PM

 

From time to time you might need some other parameters in your transformation
together with incoming schema. Here's instructions how to do it:

  1. First you need schema for parameters. You can find it on below. Copy it to file and name
    the file as TransformParameters.xsd (or choose your own name) on your local drive:
    <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">
      <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. Import this schema file to your BPEL Process in JDeveloper
  3. Create variable on name TrasformParams (or something else) and define type as element and point it to TransformParameters.xsd and parameters element.
  4. Create Assign element to your process
  5. In the assign create "Copy" rule

    Map expression 'FIRST_PARAM' to first index of /parameters/item/name
    Map expression 'Hello ' to first index of /parameters/item/value
    Append TransformParams\parameters\Item to TrasformParams\parameters
    Map expression 'SECOND_PARAM' to second index of /parameters/item/name
    Map expression 'World' to second index of /parameters/item/value

    Example (notice that namespace prefix in your process might be different than ns1):

    <copy>
    <from expression="'FIRST_PARAM'"/>
    <to variable="TrasformParams" query="/ns1:parameters/ns1:item[1]/ns1:name"/>
    </copy>
    <copy>
    <from expression="'Hello '"/>
    <to variable="TrasformParams"       query="/ns1:parameters/ns1:item[1]/ns1:value"/>
    </copy>
    <bpelx:append>
    <bpelx:from variable="TrasformParams" query="/ns1:parameters/ns1:item"/>
    <bpelx:to variable="TrasformParams"query="/ns1:parameters"/>
    </bpelx:append>
    <copy>
    <from expression="'SECOND_PARAM'"/>
    <to variable="TrasformParams" query="/ns1:parameters/ns1:item[2]/ns1:name"/>
    </copy>
    <copy>
    <from expression="'World'"/>
    <to variable="TrasformParams" query="/ns1:parameters/ns1:item[2]/ns1:value"/>
    </copy>
  6. Create transformation. In this example we are using input variable for input and output variable for output.

    In your transformation define two new parameters with name FIRST_PARAM and SECOND_PARAM.

    Create concat function and use $FIRST_PARAM and $SECOND_PARAM for values. Connect the outcome of concat to result node on target.

    Here's the xslt:
       <xsl:param name="FIRST_PARAM"/>
       <xsl:param name="SECOND_PARAM"/>
       <xsl:template match="/">
         <ns1:BPEL_TransformsProcessResponse>
           <ns1:result>
             <xsl:value-of select="concat($FIRST_PARAM,$SECOND_PARAM)"/>
           </ns1:result>
         </ns1:BPEL_TransformsProcessResponse>
       </xsl:template>
    </xsl:stylesheet>

    Save and exit the transformation
  7. Modify your bpel code for transformation node by adding the parameter variable to it:

    ORIGINAL

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

    MODIFIED

    <assign name="Transform_1">
    <bpelx:annotation>
    <bpelx:pattern>transformation</bpelx:pattern>
    </bpelx:annotation>
    <copy>
    <from expression="ora:processXSLT('Transformation_1.xsl',bpws:getVariableData('inputVariable','payload'),bpws:getVariableData('TransParamVariables'))"/>
    <to variable="outputVariable" part="payload"/>
    </copy>
    </assign>
  8. Now save the bpel, deploy and test. You should see "Hello world" as output message from your process.