Skip to main content
Version: 4.17.2

Creating XSLT's with MapForce

With Altova MapForce you can create XSLT files to transform your data from one XML format to another, in a visual manner.

Mapforce uses 'schemas' that represent the structure of your input files (called 'source schema') and/or output file (called 'target schema'). For example, you could use MapForce to transform EDI/EDIFACT messages to an XML format for your database.

You can use actual input or output (in XML format) for both the source or target schema, MapForce will create a schema from the given file. Mapforce offers several conversion functions for your mapping; those supported by XSLT2 to transform data.

Note As MapForce interprets a schema, there is always a change the interpreted schema does not reflect the actual data structure. When inspecting the properties of a schema, you can use the edit button to change the schema as needed.

Creating a new mapping file

  • Launch MapForce and choose New → Mapping
  • To place a source schema on the canvas choose Insert → XML Schema/File. You can choose either the Schema (.XSD) or an example .XML file as input.
  • When adding a source schema, also add an XML file. The XML file contains example data to test the mapping.
  • To place a target schema, repeat this action (Insert → XML Schema/File), but now select the target Schema (.XSD) file you want to create the mapping to.
  • Select XSLT2 as the mapping language in the toolbar
File Output Bar Schemas

Basic Mapping

Creating a mapping between the source and target schema is easy, just drag the arrow to the right of the source attribute to the left arrow of the target attribute (you can also drag to and from the names of the attributes). You've now created a connection.

Mapping

That's it! For most translations that's all you'll have to do!

XSLT2 Output

To see the generated XSLT by going to the 'XSLT2' view and the output of the mapping under the Output view.

Mapping tab

You can either copy and paste the XSLT code into a new file or select File → Generate Code in Selected Language to export an XSLT file.

XSLT Upload

Upload the new XSLT file to an XSLT component in Dovetail, using the Choose a file button, compile it and you're ready to use the new XSLT!

Testing

Output tab

To see how well your mapping performs, you can see the output of a transformation in the output tab. The output you see on this tab is created by using the Input XML file and transforming it according to your mapping. You can change the Input XML file by editing the properties of the source schema:

  • Right-click the source schema and click 'Properties'
  • Look for 'Input XML file' and click 'Browse'
  • Select a new file

When you go to the output tab now, it will use the new input file.

Advanced Mapping

If you need to do more than just copying values from you can use to actually change values.

To add a function, find it in the Library and drag-and-drop it onto the canvas. Then connect it by dragging to, or from, its connectors, just like you do with attributes.

A few functions are denoted in this documentation, for quick reference. The full list of functions can be found on the Altova website

  • concat concatenation usefull to merge two attributes into one
  • equal returns a boolean if the input values are equal
  • if-else propogate a value when the guard is true
  • date parse a string into a date format

Remarks

  • Have the messages window open. XSLT validation errors appear in this window and you can inspect them to get a notion of what goes wrong.
  • Hover over items, attributes or connecitons. It wil show some extra information, like the type and restrictions of an attribute.
  • Dovetail does not support all the MapForce constructors and functions. Read more about Unsupported XSLT here.

Copy value if it conforms to some condition:

Logical functions like equal return a boolean, not a value. You can use the following construction to copy the value when a guard is true

Copy value

Changing the type of an attribute

Component Settings

MapForce tries to interpret a schema from an Input XML File and sometimes it gets an attribute type wrong. Luckily, you can still change the schema, as follows:

  • Right click the schema and choose Properties
  • Click on the Edit button behind the Schema File

This opens up Altova XMLSpy, where you can click through the schema hierarchy, select an attribute and inspect it's properties.