Altova MapForce 2023 Basic Edition

Import Custom XSLT Functions

Home Prev Top Next

You can extend the XSLT 1.0, XSLT 2.0, and XSLT 3.0 function libraries available in MapForce with your own custom functions, provided that your custom functions return simple types.

 

Only custom functions that return simple data types (for example, strings) are supported.

To import functions from an XSLT file:

1.Click the Add/Remove Libraries button at the bottom of the Libraries window. The Manage Libraries window opens (see screenshot below).

mf_manage_libraries_window_empty

2.To import functions as a local library (in the scope of the current document only), click Add under the current mapping name. To import functions as a global library (at program level), click Add next to Global Library Imports. When you import a library locally, you can set the path of the library file to be relative to the mapping file. With globally imported libraries, the path of the imported library is always absolute.

 

3.Browse for the .xsl file that contains the functions, and click Open. A message box appears informing you that a new library has been added.

 

Imported XSLT files appear as libraries in the Libraries window, and display all named templates as functions below the library name. If you do not see the imported library, ensure you have selected XSLT as a transformation language. See also Managing Function Libraries.

 

Note the following:

 

To be eligible for import into MapForce, functions must be declared as named templates conforming to the XSLT specification in the XSLT file. You can also import functions that occur in an XSLT 2.0 document in the form <xsl:function name="MyFunction">. If the imported XSLT file imports or includes other XSLT files, then these XSLT files and functions will be imported as well.

The mappable input connectors of imported custom functions depends on the number of parameters used in the template call; optional parameters are also supported.

Namespaces are supported.

If you make updates to XSLT files that you have already imported into MapForce, changes are detected automatically and MapForce prompts you to reload the files.

When writing named templates, make sure that the XPath statements used in the template are bound to the correct namespace(s). To see the namespace bindings of the mapping, preview the generated XSLT code.

 

Data types in XPath 2.0

If your XML document references an XML Schema and is valid according to it, you must explicitly construct or cast datatypes that are not implicitly converted to the required datatype by an operation.

 

In the XPath 2.0 Data Model used by the Altova XSLT 2.0 Engine, all atomized node values from the XML document are assigned the xs:untypedAtomic datatype. The xs:untypedAtomic type works well with implicit type conversions.

 

For example,

 

the expression xs:untypedAtomic("1") + 1 results in a value of 2 because the xdt:untypedAtomic value is implicitly promoted to xs:double by the addition operator.

Arithmetic operators implicitly promote operands to xs:double.

Value comparison operators promote operands to xs:string before comparing.

 

See also:

Example: Adding Custom XSLT Functions

Example: Summing Node Values

XSLT 1.0 engine implementation

XSLT 2.0 engine implementation

© 2017-2023 Altova GmbH