Tuesday, July 21, 2020

12c SOA - BPEL dynamic XSLT

Here we will see how to do dynamic XSLT that means to dynamically choose an xslt to execute on runtime.

Logical steps:
  • Create a DVM for instance that contains a column on which you want to select, and a second column that lists the particular xslt to be executed.
  • Then create string variable 'varXSLT' and an assign before the transformation, in which you do an assign using the LookupDVM() to translate the selection code to the actual xslt file with the varXSLT variable as target.
  • From the source view move the copy rule of the transformation to the assign with the LookupDVM() function or in a different assign, remove the transformation activity. In the expression builder replace the reference to the xslt with the varXSLT variable. 
  • Use ora:processXSLT() function instead of using ora:doXSLTransformForDoc(). If you use ora:doXSLTransformForDoc() function, it will not allow you to map/use this varXSLT variable as it needs a string literal as input value.
  • Later, you can move the xsl files to MDS and use the oramds xpath to use the MDS reference xsl files dynamically. This way if you need to change anything in the xsl file , just change in MDS and no need to change in composite itself.

Note: If you create a transformation activity in BPEL, choose the sources and targets, create the xslt etc. then if you go to the source view, you will discover that it is actually an assign activity. The execution of the xslt is done through an xpath expression that references the particular xslt file.

 Implementation steps:

Create a SOA project.




Create a XSD



<?xml version="1.0" encoding="windows-1252" ?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org"

            targetNamespace="http://www.example.org" elementFormDefault="qualified">

  <xsd:element name="OrderRequest">

    <xsd:complexType>

      <xsd:sequence>

        <xsd:element name="OrderId" type="xsd:string"/>

        <xsd:element name="OrderType" type="xsd:string"/>

      </xsd:sequence>

    </xsd:complexType>

  </xsd:element>

    <xsd:element name="OrderResponse">

    <xsd:complexType>

      <xsd:sequence>

        <xsd:element name="Status" type="xsd:string"/>

      </xsd:sequence>

    </xsd:complexType>

  </xsd:element>

</xsd:schema>

Use this schema and create a Syn BPEL



Create a DVM

here i added two rows containing 2 xsl files.

Create a Variable varXSLT
Take a assign and Use dvm:lookupValue() function to fetch teh xsl names based on the orderType.
Take a Transformation activity and create 2 xslt files as defined in the dvm.


XSLT1
XSLT2

Use ora:processXSLT() instead of using ora:doXSLTransformForDoc() functions.


Testing:



We can push the xsl files to MDS and use them dynamically from MDS too.
First i have kept the xsl files in the SOA design time repository local files,
Publish the files to MDS



Use the oramds path to the ora:processXSLT() function like this and it works.

No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...