Define XSLT functions

XSLT contains a number of functions that enable you to manipulate strings and operate on numbers.

The following instructions were written for the Resource perspective, but they will also work in many other perspectives.

To define a function for a mapping,...

  1. Open your mapping in the XML to XML mapping editor.

  2. Select a target element or attribute you want to define an XSLT function for.

  3. Right-click it and click Define XSLT function from the pop-up menu.

  4. Select the type of function that you want to define.

  5. Click Next

  6. Fill in the fields in the next screen as necessary (they will vary depending on what you selected in step 4. See the Function Lists section below for more information).

  7. Click Finish. The XSLT function appears in the Overview pane next to the target element or attribute.

 

 

Function Lists

The following tables describe the functions that are available in the function list.

 

String functions

Function Definition
concat Returns the concatenation of its arguments
contains Returns true if the first argument string contains the second argument string, and otherwise returns false.
substring Creates the substring of the first argument starting at the position specified in the second argument with length specified in the third argument.
substring-before Creates the substring of the first argument string that precedes the first occurrence of the second argument string in the first argument string.
substring-after Creates the substring of the first argument string that follows the first occurrence of the second argument string in the first argument string.
string Converts any value to a string.
string-length Returns the number of characters in the string.
starts-with Returns true if the first argument string starts with the second argument string, and otherwise returns false.
translate Returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding position in the third argument string.

 

Numeric functions

Function Definition
ceiling Returns the smallest integer that is not less than the argument.
count Calculates the number of nodes in the argument node-set.
floor Returns the largest integer that is not greater than the argument.
number Converts the argument into a number
round Returns the integer that is closest to the argument.
sum Returns the sum of several arguments
+ Adds the arguments
- Subtracts the arguments
* Multiplies the arguments
div Divides the arguments

 

Boolean

Defines a function that will return a Boolean for the input values selected

Function Definition
boolean Converts the argument to a Boolean
not Returns true if its argument is false, and false otherwise
< Returns true if the first numeric argument is less than the second numeric argument
<= Returns true if the first numeric argument is less than or equal to the second numeric argument.
> Returns true if the first numeric argument is greater than the second numeric argument.
>= Returns true if the first numeric argument is greater than or equal to the second numeric argument.
= Returns true if the first numeric argument is equal to the second numeric argument.
!= Returns true if the first numeric argument is not equal to the second numeric argument.

 

XPath Expression

XPath is a subset of XSLT. On the XPath Expressions page, enter a value for the parameter or select one of the XPath expressions from the list.

Click the Advanced button to create your XPath expression using the XPath expression wizard.

 

Custom Java bean

The bean that you want to use must exist in a Java project in the workbench. Follow these steps to add a bean:

  1. Select a Java project from the Java project list.

  2. Select a Java bean from the Java bean list.

  3. Select a method from the Method list.

  4. Specify the input parameters:

    1. Click Add to add a parameter to the Input parameters list.

    2. Click Up and Down to scroll through the parameters in the list.

    3. Click Remove to remove a parameter from the list.

    4. Click Edit to open the Value dialog. You can type a new value, or edit the selected value.

 

Custom JavaScript

To add a JavaScript function:

  1. Specify the URI reference identifying the JavaScript resource.

  2. In the Function text field, type the name of the function from the resource you specified above.

  3. Specify the input parameters. Unlike XPath or Java, an argument for a JavaScript function is not automatically converted to the required type.

    1. Click Add to add a parameter to the Input parameters list.

    2. Click Up and Down to scroll through the parameters in the list.

    3. Click Remove to remove a parameter from the list.

    4. Click Edit to open the Value dialog. You can type a new value, or edit the selected value.

 

Parent topic

Editing an XML to XML mapping