Defining a parameter

This recipe explains how to a the parameter to the mapping file. Parameters are an important aspect of the transformation since they enable us to include some additional content into the transformation. In this recipe, we will show you how to add a parameter that will hold the generated UUID (universally unique identifier) information.

Getting ready

We will amend the example from the Using the xsl:for-each command recipe, by adding a parameter to the source part.

How to do it…

In the following steps, we will create a parameter and configure it to hold the generated UUID information:

  1. We right-click on the source side and select Add Parameter….
    How to do it…
  2. We enter the parameter name and check the Set default value option in order to initialize the parameter at the beginning of the transformation as shown in the following screenshot:
    How to do it…
  3. After that, we configure the conditions. We will utilize the parameter to set up the reference number in case the source node is empty or missing. We achieve this, by using the not equal XSLT function. The configuration of the function is trivial and consists only of checking, if the car reference number is empty. The final outlook of the mapping is as shown in the following screenshot:
    How to do it…
  4. Now, if we test the mapping, we see that the parameter is taking into account whether we have a missing or empty reference tag. In source, we have three cars, where the reference tags have the following values:
    • Car 1: <refNo>refNo5</refNo>
    • Car 2: <refNo></refNo>
    • Car 3: It contains no refNo tag
  5. The transformation of source presents the following results:
    • Car 1: <ns1:ref>refNo5</ns1:ref>
    • Car 2: <ns1:ref>36333838333930353933313438313534</ns1:ref>
    • Car 3: <ns1:ref>36333838333930353933313438313534</ns1:ref>

How it works…

The parameter in the transformation file is defined as the xsl:param tag as follows:

<xsl:param name = "test" select = "oraext:generate-guid()"/>

The parameter tag consists of the name and select attributes. We are also able to define the constant value of the parameter. The syntax is similar to the one preceding with a difference that we don't need to set the select part as follows:

<xsl:param name = "testConst">Constant value</xsl:param>

The function of the parameter is taking the values from the outside and using them inside the transformation file. We can also define the default values of the parameter as we saw in the previous recipe.

See also

  • The definition of variables is examined in the next recipe.
..................Content has been hidden....................

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