Time for action – using XSLT transformations

To demonstrate how we can use the XSLT transformation in our BookWarehousingBPEL process, let's add it to the process:

  1. Open the BookWarehousingBPEL.bpel window.
  2. To add a transformation instead of the <assign> activity for preparing the AnotherBookstoreRequest variable, we will first remove the <assign> activity from the third flow branch. It is located just before the <invoke> activity for the AnotherBookstoreBPEL process.
  3. Instead, we will drag-and-drop the XSLT Transform activity to the process. We can find the XSLT Transform activity under the Oracle Extensions part of the toolbar. The XSLT Transform activity needs to be dropped just above the invoke activity, that is, the invoke activity that invokes the AnotherBookstoreBPEL partner link.
  4. After double-clicking on the XSLT Transform activity, an Edit Transform dialog will appear. The Source for the transformation will be inputVariable. The Target Variable will be AnotherBookstoreRequest. In both cases, we will address the payload part of the message:
    Time for action – using XSLT transformations
  5. To create the XSLT transformation, we will click on the big green + sign, next to Mapper File. This will open a new window, where we can graphically (using drag-and-drop) map the various fields.

    Note

    Please note that, in this simple example, it might not be obvious why XSLT transformations are a better and more efficient way when transforming complex schemas. On a more complex schema, the advantages would become clearer. In addition to mapping, you can also do other data transformations.

  6. We will now map the fields. As the schema is simple and the mapping is obvious, this will be straightforward:
    Time for action – using XSLT transformations
  7. After saving both files, we have successfully finished the transformation.

What just happened?

We have created an XSLT transformation and used it in the <assign> activity to transform and map two different variables, each containing data based on its own schema. If we switch to source code, we can see that the following XSLT has been created:

What just happened?

Also, in the BPEL source code, we can see that the <assign> activity uses the created transformation:

What just happened?

Note that JDeveloper has added the <bpelx:annotation> activity, which could be omitted and is JDeveloper specific. Also note that JDeveloper uses ora:doXSLTransformationFromDoc(), which is a JDeveloper-specific function. However, as it follows the same syntax, it could be easily replaced with the BPEL standard bpel:doXslTransform() function. To make your code portable on different BPEL run time environments, avoid using vendor-specific syntaxes or functions.

Have a go hero – deploy and test the process

It's your turn now to deploy and test this process and compare the results with the previous implementation. Note that the results should be equal.

With this, we have concluded our discussion on variables and data manipulation.

Pop quiz: variables and data manipulation

Q1. Which activity do you use to declare a variable?

  1. <variables>
  2. <variable>

Q2. Which variable types are supported in BPEL?

Q3. Write the declaration of a message type variable named BookStoreWithLowestQuantity using the message type client:BookstoreBPELResponseMessage.

Q4. Write the code to copy BookstoreAResponse variable to the BookStoreWithLowestQuantity variable. Assume that both variables are of the same message type. Do not use expressions.

Q5. Which operator is used to access BPEL variables from expressions?

  1. /
  2. $
  3. .
  4. :

Q6. Which activity is used to validate variables?

  1. <validate>
  2. <validateVariable>
  3. <doValidate>

Q7. Which function in BPEL specification is used to invoke an XSLT transformation?

  1. ora:doXslTransform()
  2. bpel:doXslTransform()
  3. bpel:doXslTransformForDoc()
..................Content has been hidden....................

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