Defining a variable

This recipe will examine how to define a variable on the target side. Similar to the previous recipe, we will amend the example from the Using the xsl:for-each command recipe by adding a variable to the target part. The variables can be useful when we need a particular piece of information from a BPEL process or when we need to define a constant value which is then used in different places in the transformation. In this recipe, we will create a variable and assign a value to it. The content of the variable presents the rebate on the price of the available cars.

How to do it…

The following steps will describe how to add a variable to the transformation and assign a value to it. On the mapper pane, we right-click on the target side and select Add Variable…. A dialog box opens where we define the variable name and optionally its value as shown in the following screenshot:

How to do it…

Now that we have defined the variable and set its value, we calculate the rent price of the car and round the result. We define the multiply function in the following way:

How to do it…

How it works…

As opposed to parameters, it is not possible to set the values of variables from the outside. Rather, our variable is used for internal processing and as the information holder. We can define the following two types of variables:

  • global: This variable is defined as the child node of the transformation root element
  • local: The scope of this variable is limited to the scope of the element where the variable is defined
..................Content has been hidden....................

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