Example: Adding Custom XSLT Functions
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\MapForce2024\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).
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).
To use the XSLT function in your mapping:
1.Drag the tokenize function into the Mapping window and map the items as show below.
2.Click the XSLT pane to see the generated XSLT code.
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 next to the library that is to be deleted.