Index Changes

Calling XSLT Transformation using the 'doXslTranform' function

The BPEL editor has an extension function called 'doXslTranform' in its mapper tool, which can be used in a BPEL 'Assign' activity to call a XSLT transformation.

Let us consider a trivial BPEL process example where we will use the 'doXSLTransform' function that takes an input message of 'shoe' and transforms it to an return message consisting of 'shoe{ShoeMart}' and a price of '$50.00' for the shoe.

The input variable '$InputVar' is defined by

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

The output variable '$OutputVar' is defined by

            <xsd:complexType name="returnType">
                <xsd:sequence>
                    <xsd:element name="product" type="xsd:string"/>
                    <xsd:element name="value" type="xsd:string"></xsd:element>
                </xsd:sequence>
            </xsd:complexType>

Clicking on the function name in the dropdown menu shown in the figure above will drop the functiod into the selected band in the mapper for the output message 'OutputVar'. The 'doXslTransform' functoid is as shown below.

Arguments to the function:

  • The first handle of the functoid namely 'String'(graphical representation of the first argument to the function) should be assigned a string literal of the name of the XSL transformation file which in this case is 'SimpleTransform.xsl'. The user will have to enter the string literal as shown.
Notice that the literal 'urn:stylesheets:' as to be appended to the name of the XSL file.
            urn:stylesheets:SimpleTransform.xsl
  • The Second argument 'Node Set' will be connected to the 'InputVar' variable that is the input to the XSL transform.
  • The other arguments in the functiod represents place holders to pass other arguments to the XSL transform if required, which is not used in our example.
  • The output 'Node' represents the output from the XSL transform that needs to be connected to the output variable 'OutputVar'.

We are ready to define the 'Assign' activity to call the XSLT transformation. The mapping using the 'doXslTransform' function is as shown.

The generated code for the mapping is as shown

              <assign name="doXslTranform">
                  <copy>
                      <from>ns1:doXslTransform('urn:stylesheets:SimpleTransform.xsl', 
                                                $InputVar.part1)
                      </from>
                         <to variable="OutputVar" part="part1"/>
                  </copy>
              </assign>

So with a few simple steps we are able to call an XSL transform from within a BPEL 'Assign' activity. Now cerate 'Composite Application' project, include the BPEL project in it and deploy it to the Glassfish integration server. See the Video - BPEL and Composite Application Authoring for how to deploy and run a test using the Composite Application project suite.

Create a test case in the composite application project and run it with the input file.

<soapenv:Envelope 
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:bran="http://j2ee.netbeans.org/wsdl/Brand">
  <soapenv:Body>
    <bran:inputString>shoe</bran:inputString>
  </soapenv:Body>
</soapenv:Envelope>

and notice the correct output after the XSL file transformation in the output file.

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope 
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
    <ns1:returnElem xmlns:ns1="http://j2ee.netbeans.org/wsdl/Brand">
      <product xmlns="">shoe[ShoeMart]</product>
      <value xmlns="">$50.00</value>
    </ns1:returnElem>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Attachments:

Working example:

  • BPEL project: cvs -d :pserver:guest@cvs.dev.java.net:/cvs co open-jbi-components/driver-tests/bpelse/xslt/DoXslTransformBPEL
  • Comp App project: cvs -d :pserver:guest@cvs.dev.java.net:/cvs co open-jbi-components/driver-tests/bpelse/xslt/DoXslTransformJBI

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This page (revision-14) was last changed on 20-Nov-08 19:11 PM, -0800 by Murali