maandag 14 september 2009

Passing XML as parameter to an XSLT transformation, Oracle BPEL

In this document an example is given on how to import an XML parameter into a XSLT tranformation.

Step 1) Define the variable ‘XSLTParams’

Define a variable ‘XSLTParams’, based on the element {http://schemas.oracle.com/service/bpel/common}parameters

This is defined in an external xsd which will have to be imported upon making the variable.

The xsd looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<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>


Step 2) Assign the value and name to the XSLTParams:
<assign name="Assign_XSLTParams">
  <copy>
    <from expression="'AssignmentData'"/>
    <to variable="XSLTParams" query="/bpelcommon:parameters/bpelcommon:item/bpelcommon:name"/>
  </copy>
  <copy>
<!-- Replace the variable and namespace ns10 with your variable and namespace -->
    <from expression="ora:getContentAsString(bpws:getVariableData 'Invoke_GetAssignment_OutputVariable','payload','/ns10:EBO_GET_ASSIGNMENT_CIResponse'))"/>
    <to variable="XSLTParams" query="/bpelcommon:parameters/bpelcommon:item/bpelcommon:value"/>
  </copy>
</assign>


Step 3) Call the transformation WITH the property (parameter) XSLTParams:
<assign name="XForm_CombineInputForCheckAddressAndDistance">
  <bpelx:annotation>
    <bpelx:pattern>transformation</bpelx:pattern>
  </bpelx:annotation>
  <copy>
<!-- Replace the variable inputVariable and transformation xslt filename with your variable and file name -->
    <from expression="ora:processXSLT('XForm_CombineInputForCheckAddressAndDistance.xsl',bpws:getVariableData('inputVariable','payload'),bpws:getVariableData('XSLTParams'))"/>
    <to variable="Invoke_CheckAddressAndDistance_initiate_InputVariable" part="payload"/>
  </copy>
</assign>


Step 4) Add the parameter in the transformation:

Put the following code in your transformation, below the namespaces, above the first line of code:
<!-- import the parameter in the xslt transformation -->
<xsl:param name="AssignmentData"></xsl:param> 

<!-- replace ampersands to fix possible later issues in data exchange -->
<xsl:variable name="AmpersandReplacement">&amp;</xsl:variable>
<xsl:variable name="AssignmentData_fixed" select="str:replaceAll(string($AssignmentData),'\u0026(amp;)*+',$AmpersandReplacement)"/>
<xsl:variable name="AssignmentDataEBM"  select="orcl:parseEscapedXML($AssignmentData_fixed)"/>


Step 5) Use XML values from within the fixed parameter:
<eboupreq:ADDRESS>
  <xsl:value-of select="$AssignmentDataEBM/ns0:ADDRESS"/>
</eboupreq:ADDRESS>

Replace the namespaces, variable names, etc, where appropriate.

Geen opmerkingen:

Een reactie posten