Altova MapForce 2023 Basic Edition

Example: Adding Custom XSLT Functions

Home Prev Top Next

This example illustrates how to import custom XSLT 1.0 functions into MapForce. The files needed for this example are available in the following folder: C:\Users\<username>\Documents\Altova\MapForce2023\MapForceExamples.

 

Name-splitter.xslt. This XSLT file defines a named template called tokenize with a single parameter string. The template works through an input string and separates capitalized characters with a space for each occurrence.

Name-splitter.xml (the source XML instance file to be processed)

Customers.xsd (the source XML schema)

CompletePO.xsd (the target XML schema)

To add a custom XSLT function:

 

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 or .xslt file that contains the named template you want to act as a function, in this case Name-splitter.xslt, and click Open. A message box appears informing you that a new library has been added, and the XSLT file name appears in the Libraries window, along with the functions defined as named templates (in this example, Name-splitter with the tokenize function).

mf_import_xslt_example_01

To use the XSLT function in your mapping:

1.Drag the tokenize function into the Mapping window and map the items as show below.

mf_import_xslt_example_02

2.Click the XSLT pane to see the generated XSLT code.

mf_import_xslt_example_03
Note:As soon as a named template is used in a mapping, the XSLT file containing the named template is included in the generated XSLT code (xsl:include href...), and is called using the command xsl:call-template.

 

3.Click the Output pane to see the result of the mapping.

To remove custom XSLT libraries from MapForce:

1.Click Add/Remove Libraries at the base of the Libraries window. The Manage Libraries window opens.

2.Click Delete Library mf_ic_delete_library next to the library that is to be deleted.

© 2017-2023 Altova GmbH