The XSLT transformations

Using the assignments to copy data from one variable to another is useful. However, if we deal with complex XML schemas and have to copy several elements (sometimes, tens of elements), using the <copy> construct alone would be very time consuming. In such cases, a better approach would be to use XSLT transformations. XSLT transformations also simplify the BPEL code, as the transformation logic is separated in a dedicated XSLT file.

Note

Extensible Stylesheet Language for Transformations (XSLT) is not only a well-known language for transforming XML documents into other XML documents, but also to other formats, such as HTML, text or XSL Formatting Objects. XSLT can be used in most modern programming languages. For more information, please refer to http://www.w3schools.com/xsl/.

The <assign> activity provides support for XSLT transformations. We can invoke an XSLT transformation from an assignment using the bpel:doXslTransform() function. The bpel:doXslTransform() function is an XPath extension function. The syntax is listed below:

bpel:doXslTransform('style-sheet-URI', input, ['xslt-parameter-QName', parameter-value]*)

The first parameter is the URI that points to the XSLT style sheet. We have to provide a string literal and cannot use a variable here, because the BPEL process engine has to statically analyze the XSLT style sheet. The second parameter is the node set on which the XSLT transformation should be performed. Here we provide an XPath expression. In most cases, we will provide a variable. Optionally, we can specify XSLT parameters (if our XSLT style sheet requires parameters).

For example, instead of using the <assign> activity (as we did in the previous section), we can use an XSLT transformation to transform the data stored in the inputVariable variable and copy the result of the transformation to the AnotherBookstoreInputVariable variable:

<assign>
  <copy>
    <from>
    bpel:doXslTransform("http://packtpub.com/xslt/Bookstore.xsl", 
    $inputVariable)
    </from>
    <to>$AnotherBookstoreInputVariable<to/>
  </copy>
</assign>

Of course, we also need the XSLT transformation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset