Altova MobileTogether Designer

User-Defined XPath/XQuery Functions

Home Prev Top Next

You can create your own custom-made XPath/XQuery functions for individual projects, which you can then use in all XPath expressions in the project. The access point for creating and managing these user-defined functions is the XPath Functions dialog, accessed with the command, Project | XPath/XQuery Functions. The XPath Functions dialog (screenshot below) lists all the user-defined XPath functions in the project. You can add and delete functions using the corresponding icons in the toolbar of the dialog. To edit the definition of a function, click the function's Edit XPath Expression button.

MTXPathFunctionsDlg

The function list can be ordered by function name. Do this by clicking the header of the Function Name column. Each click cycles the ordering through the following ordering sequence: (i) ascending, (ii) descending, (iii) dialog order. The order in the dialog can be modified by dragging-and-dropping functions to other positions in the list. Note that, if you order the list in ascending/descending order and then move a function to a different position in the list, the newly created order becomes the new dialog order.

 

Add a new user-defined XPath function

Adding a new user-defined function involves two steps: (i) declaring the function, and (ii) defining the function.

 

To add a new function, do the following, click Add in the toolbar of the dialog (see screenshot above). This displays the New XPath Function dialog (screenshot below).

MTNewXPathFunction

In this dialog, you can declare the name of the function, specify the number of function parameters (arguments) and their types, and specify the return type of the function. In the screenshot above we have declared a function to convert a decimal number from Celsius to Fahrenheit. The function takes one parameter, which is the input Celsius value as a decimal. It will output a decimal value, the Fahrenheit temperature. What the function does is defined in the next step. After declaring the function (screenshot above), click OK. This displays the Edit Function dialog (screenshot below), which contains the template of the newly declared function and in which you can now define the function.

MTEditFunctionDlg

Enter the definition of the function within the braces. In the definition shown in the screenshot above, $a is the input parameter. Click OK. when done. The function will be added to the list of user-defined functions in the XPath Functions dialog and can be used in all XPath expressions in the project.

 

Note:User-defined XPath functions do not need to be placed in a separate namespace. Consequently, no namespace prefix is needed when defining or calling a user-defined function. The XPath default namespace is used for all XPath/XQuery functions, including extension functions and user-defined functions. In order to avoid ambiguities involving built-in functions, we recommend that you capitalize user-defined functions.

 

© 2018-2024 Altova GmbH