Chapter 5. Kaoto DataMapper


The Kaoto DataMapper is a visual tool for creating data transformations in Apache Camel routes. It provides a graphical interface to map data between XML and JSON structures using drag-and-drop operations, eliminating the need to write complex XSLT code manually.

datamapper done

Whether you’re transforming XML to JSON, merging multiple data sources, or applying complex business logic to your data, the DataMapper helps you:

  1. Map data visually using drag-and-drop between source and target fields
  2. Work with schemas to visualize XML and JSON data structures
  3. Create conditional logic with if, choose-when-otherwise, and for-each mappings
  4. Build complex transformations using the XPath expression editor
  5. Test and validate your mappings in real-time

The DataMapper generates optimized XSLT 3.0 code that executes at runtime, giving you the power of XSLT without writing it manually.

5.1. Getting Started with Kaoto DataMapper

To use the DataMapper for creating data transformations, you need to add and configure a DataMapper step in your Camel route. This guide covers the essential steps to get started with the DataMapper interface.

5.2. Adding a DataMapper step

Now, add a DataMapper step to your Camel route. The DataMapper provides a visual interface for creating data transformations without writing XSLT code manually.

  1. Add a Kaoto DataMapper step in your Camel route. When you Append, Prepend, or Replace a step in the Kaoto Design view, you can find the Kaoto DataMapper step in the catalog.

    catalog datamapper tile
  2. Click the added Kaoto DataMapper step in the Kaoto Design to open the config form.

    kaoto datamapper step
  3. In the config form, click the Configure button, to open the visual DataMapper editor.

    datamapper configure button
  4. This will open the visual DataMapper editor where you can create your data mappings.

    datamapper blank

5.3. Understanding the Interface

The DataMapper editor is divided into two main sections that represent the data transformation flow:

datamapper source target

5.3.1. Source Section (Left Side)

The Source section represents where your data comes from - the input side of your mappings. This is where the DataMapper step reads the data from.

  1. Source Body - The incoming Camel Message Body (the main data payload)
  2. Source Parameters - Additional data from Camel Variables and Message Headers

Think of this as the input side of your transformation - the data you’re reading from.

5.3.2. Target Section (Right Side)

The Target section represents where your data goes to - the output side of your mappings. This is where the DataMapper step writes the transformed data.

  1. Target Body - The outgoing Camel Message Body (the transformed result)

Think of this as the output side of your transformation - the data structure you’re creating.

Note

You can adjust the font size in the DataMapper interface to match your preference. Use the + and - magnifier icons in the toolbar to make the text larger or smaller for better readability.

datamapper zoom

5.4. Working with Parameters

Parameters allow you to access Camel Variables and Message Headers in your mappings. This is useful when you need to combine data from multiple sources in your transformation.

5.4.1. Adding a Parameter

Follow the below steps to add a parameter:

  1. Click the plus + button on the right side of the Source Parameters title.

    datamapper add parameter
  2. Now type the parameter name and click the check button on the right.

    datamapper add parameter confirm
Note

When you have many parameters, you can improve readability by hiding them visually. Click the eye icon next to the Parameters section to toggle the visibility of the parameter list.

datamapper hide parameters
Note

While Camel Exchange Properties are also mapped to Parameters in current camel-xslt-saxon implementation, after the Camel Variables has been introduced, it is no longer recommended to store application data into Camel Exchange Properties. We encourage to use Camel Variables instead.

5.4.2. Deleting a parameter

  1. To remove a parameter, click the trash icon next to it and confirm the deletion.

    datamapper delete param trash
  2. You then have to confirm the deletion by clicking the Confirm button.

    datamapper delete param confirm
  3. The parameter is deleted.

    datamapper delete param done
Note

If the parameter is used in any mappings, those mappings will become invalid after deletion. Review your mappings before removing parameters.

5.4.3. Renaming the XSLT File

By default, the DataMapper generates an XSLT file with an auto-generated name. You can rename this file to give it a more meaningful name that reflects the transformation’s purpose.

Steps:

  1. Click the DataMapper step in the Kaoto Design view to open the config form
  2. Click the pencil icon next to the file name in the Document field to make it editable

    datamapper rename xslt
  3. Type the new name for your XSLT file
  4. Click the check button to confirm, or the cancel button to discard

    datamapper rename xslt confirm

5.5. Attaching Document schema files

Schemas define the structure of your data and enable the visual tree representation in the DataMapper. The DataMapper supports both XML Schema (XSD) and JSON Schema files for Source Body, Target Body, and Parameters.

Note

If the data is not structured and just a primitive value, you don’t need to attach a schema file.

Follow these steps to attach a schema file to Source Body, Target Body, or Parameters:

  1. Place schema file (.xsd or .json) in the workspace directory.
  2. Click Attach a schema button in one of the Source Body, Target Body or Parameters sections.

    datamapper attach schema
  3. In the Attach schema modal, click the file button.

    datamapper attach schema file btn
  4. Select the schema file to attach.

    datamapper select schema
    Note

    You can select and upload multiple schema files at once.

    datamapper attach multiple
  5. For XML schemas only: Choose the root element - Select which top-level element to use if your schema defines multiple.

    datamapper select root element
  6. Click Attach button.

    datamapper attach schema attach
  7. The document structure appears as a tree - The schema is parsed and rendered as an expandable tree view, showing all elements, attributes, and their hierarchical relationships. You can now navigate through the structure and create mappings by dragging fields between source and target sections.

    datamapper schema attached

5.6. Detaching a schema

Similar to attaching a schema you can also remove / detach a schema.

To remove a schema from Source Body, Target Body, or Parameters, click the Detach schema button Detach schema button and confirm the action.

datamapper detach button
Note

Detaching a schema will remove all mappings associated with that schema. This action cannot be undone.

5.7. Understanding JSON field labels

Note

Kaoto DataMapper uses XSLT 3.0 json-to-xml() and xml-to-json() functions to support JSON mappings. The field labels reflect this internal representation.

JSON schemas use type-based labels since fields can be anonymous:

LabelDescription

map

Object field

array

Array field

string

String field

number

Number field

5.7.1. Field Label Examples

JSON schema fields are rendered with type-based labels in the tree view. Here’s how different field types appear:

Understanding the labels:

  • Named fields display as type [@key = FieldName] - For example, string [@key = AccountId] represents a string field named "AccountId"
  • Anonymous fields show only the type - For example, map represents an unnamed object
  • Primitive types like string, number, boolean indicate the data type
  • Complex types like map (object) and array represent structured data

5.7.2. Array Fields and Collections

Important

For array fields, the children are the collection items, not the array itself. Collection fields are marked with a layer icon <img src="datamapper-collection-field.png" alt="Collection icon" style="display: inline; height: 1.2em; vertical-align: middle;">. The map type field (child of the array field) is the actual collection field that you’ll use in for-each mappings.

datamapper json array field

5.8. JSON Parameter References

When using structured JSON parameters, they’re internally converted to XML. Reference them with a -x suffix in XPath expressions:

  1. Parameter Account becomes $Account-x
  2. Parameter Cart becomes $Cart-x
datamapper json mappings all
Note

When creating mappings through drag and drop, Kaoto DataMapper automatically handles the -x suffix. You only need to remember this when editing XPath expressions manually.

5.9. Creating Mappings

Once you have schemas attached, you can create mappings between source and target fields.

The DataMapper offers two primary methods:

  1. drag-and-drop for quick mappings and
  2. XPath expressions for more control

5.10. Drag and Drop Mapping

The easiest way to create a mapping is by dragging a source field onto a target field. A line will be drawn between the fields to visualize the connection.

5.10.1. Map the Name Field

datamapper drag name
Note

Drag-and-drop is the fastest way to create simple field mappings. The DataMapper automatically generates the correct XPath expression for you.

5.11. Container Mappings

When you drag a container field (a field that contains other fields, such as an XML element with child elements or a JSON object with properties) onto another container field, the DataMapper automatically maps their matching children — you don’t need to connect each child field individually.

5.11.1. How Container Mapping Works

  1. Drag a container field from the source tree onto a matching container field in the target tree
  2. The DataMapper automatically pairs children by name and creates individual mappings for each match
  3. This works recursively — nested containers are also matched and mapped automatically
  4. Children that exist only on one side are skipped
datamapper container mapping

For XML schemas, children are matched by element name and namespace. For JSON schemas, children are matched by property key. When mapping between XML and JSON, children are matched by name.

5.11.2. Collection Mappings

When both the source and target fields are collections (marked with the collection icon), the DataMapper additionally wraps the mapping in a for-each loop that iterates over each item in the source collection.

datamapper collection mappings

5.11.3. Mapping Line Styles

After creating a container mapping, you’ll notice different line styles in the mapping view:

Regular — A solid gray line. A simple field-to-field mapping.

Copy-of — A double dark line. The source and target XML containers have identical structure (same name and namespace), so the DataMapper copies the entire subtree efficiently.

datamapper line style copy of

Complete — A dashed line with long dashes. All target children are mapped, and all nested containers among them use copy-of.

Partial — A dashed line with short dashes. Some target children are mapped, but not all have a matching source field, or nested containers are mapped field-by-field.

datamapper line styles
Tip

A partial mapping is not an error — it simply means some target fields don’t have a corresponding source field. You can add individual mappings for the remaining fields manually.

5.11.4. When Container Mapping Is Not Available

In some cases, the DataMapper will not allow a container-to-container mapping:

  • Mismatched field types: A container field can only be mapped to another container field. Dragging a container onto a leaf field (or vice versa) will be rejected.
  • No compatible children: If the source and target containers have no children with matching names, the mapping cannot be created.
  • JSON arrays: JSON array wrapper fields cannot be mapped directly — expand the array and map its children instead.
Tip

If a drop is rejected, try mapping the children individually instead of the parent container.

5.12. XPath Expression Mapping

For more control over your mappings, you can type XPath expressions directly.

5.12.1. Creating a Mapping with XPath

  1. Click the 3 dots context menu on the target field and select Add selector expression.

    datamapper add selector
  2. Then enter the XPath expression to define the mapping.

    datamapper type xpath
Note

XPath expressions give you full control over data transformation, including string manipulation, calculations, and conditional logic. For complex expressions, consider using the XPath Editor.

5.13. Comment on a Mapping

Once a mapping is created, you can also comment on it.

  1. Click the 3-dot menu on the target field

    datamapper add comment dropdown
  2. Add your comment

    datamapper add comment

5.14. Delete a Mapping

To delete a mapping, click the trash bin icon next to the target field and confirm the deletion.

datamapper delete mapping btn
datamapper delete mapping
datamapper delete mapping confirm
Warning

Deleting a mapping is permanent and cannot be undone. Make sure you want to remove the mapping before confirming.

5.15. Conditional Mappings

The DataMapper supports three types of conditional mappings to handle complex transformation logic:

  1. if - Execute mapping only when a condition is met
  2. choose-when-otherwise - Branch based on multiple conditions
  3. for-each - Iterate over collection fields (arrays)

5.15.1. Creating an if mapping

Create a mapping that only executes when a specific condition is true.

  1. Click the 3 dots context menu on the target section’s field. Then select wrap with "if" to create a mapping.

    datamapper if if
  2. Configure the if condition. You can drag the source field and drop it into the input field to build a condition, or alternatively type everything manually.

    datamapper if condition
  3. Create the mapping for when the condition is true.

    datamapper if mapping
Note

You can drag source fields into the condition input to quickly build expressions like $sourceField > 100 or $status = 'active'.

5.15.2. Creating a choose-when-otherwise mapping

Create branching logic with multiple conditions, similar to switch-case statements.

  1. Click the 3 dots context menu on the target section’s field. Then select wrap with "choose-when-otherwise" to create a mapping.

    datamapper choose choose
  2. Configure when and otherwise conditions - Similar to if mapping, configure the condition and create mappings for both when and otherwise branches

    datamapper choose otherwise mapping
  3. Add more when branches (optional) - If you need multiple conditions, click the 3-dot menu on the choose field and select “Add when” to create additional when branches. Each branch can have its own condition and mappings.

    datamapper choose add when
Note

The otherwise branch executes when none of the when conditions are satisfied, providing a default fallback.

5.15.3. Creating a for-each mapping

When working with arrays or repeating elements, use for-each mappings to transform each item in the collection. Collection fields are identified by a layer icon Layer icon in the document tree.

  1. Identify the target collection field - Look for fields marked with the layer icon Layer icon, indicating they contain multiple items.

    datamapper layer
  2. Create the for-each mapping - Click the 3 dots context menu on the target section’s collection field. Then select Wrap with "for-each" to create a mapping.

    datamapper for each for each
  3. Specify the source collection - Choose which source collection to iterate over. This determines what data will be processed for each target item.

    datamapper for each condition
  4. Map the collection item fields - Create mappings for individual fields within each collection item. These mappings will be applied to every item in the collection.

    datamapper for each mappings
Note

Inside a for-each mapping, field paths are relative to the collection item. For example, if iterating over Items, you reference Name instead of Items/Name.

5.15.4. Creating multiple for-each mappings

Merge multiple source collections into a single target collection by adding multiple for-each mappings.

  1. After creating a first for-each mapping by following previous section, click Add Conditional Mapping in the placeholder below the added for-each mapping

    datamapper add conditional mapping
  2. Click Wrap with "for-each"

    datamapper wrap with for each
  3. Configure the second collection mappings - Select the second source collection to iterate over, then create field mappings for each item. This allows you to merge data from multiple collections into a single target array, combining items from different sources.

    datamapper map 2nd for each children
  4. Here is a demo screencast for merging 2 source collection fields with multiple for-each mappings.

    dm multiplemappings
Note

This technique is useful for merging data from multiple sources, such as combining orders from different systems into a single output array.

5.16. XPath Editor

The XPath Editor provides a powerful way to create complex data transformations beyond simple field-to-field mappings. While drag-and-drop is great for basic mappings, the XPath Editor lets you combine fields, apply functions, perform calculations, and implement sophisticated business logic.

When to use the XPath Editor:

  1. Combining multiple source fields into one target field
  2. Applying string manipulation (concatenation, substring, case conversion)
  3. Performing mathematical calculations
  4. Using conditional expressions within a single mapping
  5. Applying XPath functions for date formatting, number formatting, and more
Note

The XPath Editor is under active development. Current features include drag-and-drop for fields and functions, with more syntax assistance planned for future releases.

5.16.1. Opening the XPath Editor

To edit or create complex XPath expressions, click the pencil icon next to a target field that has an existing mapping. This will launch the editor where you can modify and build the expression for that mapping.

datamapper xpath pencil

5.16.2. Building XPath Expressions

The XPath Editor interface provides two main areas: a palette on the left with fields and functions, and an expression editor on the right.

datamapper xpath editor

5.16.2.1. Adding Fields

You can add source fields to your expression by:

  1. Typing directly - Enter field paths manually using XPath syntax
  2. Drag and drop - Drag fields from the Fields tab and drop them into the editor

    datamapper xpath dnd fields

5.16.3. Using XPath Functions

The XPath Editor provides access to a comprehensive library of functions for data transformation:

String Functions:

  1. concat() - Combine multiple strings
  2. substring() - Extract part of a string
  3. upper-case(), lower-case() - Change text case
  4. normalize-space() - Remove extra whitespace

Numeric Functions:

  1. sum(), avg(), min(), max() - Aggregate calculations
  2. round(), floor(), ceiling() - Number rounding
  3. format-number() - Number formatting

Date/Time Functions:

  1. current-date(), current-time() - Get current date/time
  2. format-date(), format-time() - Format date/time values

Conditional Functions:

  1. if() - Inline conditional logic
  2. choose() - Multi-branch conditionals

To use functions:

  1. Switch to the Functions tab in the left palette.

    datamapper xpath functions
  2. Drag the function you need and drop it into the editor.

    datamapper xpath functions dnd
  3. Fill in the function parameters with field references or literal values

5.16.4. Saving Your Expression

  1. Once you’ve built your XPath expression, click the Close button to apply it to the mapping.

    datamapper xpath close
  2. The mapping will now appear in the tree view with your custom XPath expression.

    datamapper xpath done
Note

Start with simple expressions and test them before adding complexity. You can always reopen the XPath Editor to refine your expression.

5.17. Advanced Features

Once you’re comfortable with basic mappings and conditional logic, the DataMapper offers advanced features for handling complex transformation scenarios. This guide covers advanced capabilities for working with complex schemas:

  • Field Override - Change field types or substitute elements for complex schemas
  • Choice Support - Handle schema choice elements (xs:choice)

5.17.1. Field Override

Field override allows you to change how a schema field is interpreted in your transformation. The DataMapper supports two types of overrides, both accessed through the same modal dialog:

  • Override Type - Change a field’s type to a compatible derived type
  • Substitute Element - Replace an element with one from its substitution group
Important

Field override options depend on your schema definitions. To enable type overrides, your schema must define type extensions using xs:extension or xs:restriction.

For field substitutions, your schema must define substitution groups. You can attach additional schema files that extend your base schema to unlock these capabilities.

5.17.1.1. When to Use Field Override

Override Type:

  • The source data uses a derived type (e.g., SpecialAddress extends Address)
  • You need to access additional fields defined in a subtype
  • The actual runtime data differs from the base schema definition

Substitute Element:

  • Working with XML Schema substitution groups
  • Need to select a specific concrete element from a group of alternatives
  • Handling polymorphic data structures

5.17.1.2. Understanding the Override Modal

When you select "Field Override" from a field’s context menu, the DataMapper opens a modal dialog with radio buttons to switch between two override types:

  • Override Type - Lists compatible derived types within the type hierarchy
  • Substitute Element - Shows available substitution group members

Use the radio buttons to switch between override types. The modal displays only valid options based on the schema definition, ensuring type safety.

datamapper field override modal

5.17.1.3. Extending Schemas for Field Override

If the Field Override modal shows no available options, your schema may not define the necessary extensions or substitution groups. You can attach additional schema files that extend your base schema:

For Override Type: - Create or attach a schema that extends base types using xs:extension or xs:restriction - Example: A schema defining SpecialAddress that extends Address

For Substitute Element: - Create or attach a schema that defines substitution groups - Example: A schema defining Car, Truck, and Motorcycle as substitutes for Vehicle

Once you attach the extending schema file using the [schema attachment](../02-attaching-schemas/) process, the Field Override modal will display the newly available options.

Tip

You can attach multiple schema files to the same DataMapper step. This allows you to work with a base schema and one or more extension schemas that define derived types or substitution groups.

5.17.1.4. Applying an Override Type

Override Type changes a field’s type to a compatible type within the same type hierarchy. Fields with an active override type are marked with a special icon indicator in the document tree.

Steps:

  1. Right-click on the field you want to override (or use the 3-dot menu)
  2. Select "Override Field…​" from the menu
  3. Select the "Override Type" radio button in the modal (if not already selected)
  4. Choose a type from the list of compatible derived types
  5. The field tree updates to show the new type’s structure
  6. An icon appears next to the field indicating the override type is active
datamapper field override type selected
datamapper type override icon
Tip

Override Type preserves compatibility with the original schema by only allowing safe type substitutions within the type hierarchy.

5.17.1.5. Applying a Substitute Element

Substitute Element replaces a schema element with one of its designated substitution elements. Fields with an active substitution are marked with a special icon indicator in the document tree.

Steps:

  1. Right-click on a field that has available substitutions
  2. Select "Override Field…​" from the menu
  3. Select the "Substitute Element" radio button in the modal
  4. Choose a substitute element from the list of substitution group members
  5. The field updates to reflect the substituted element’s name and structure
  6. An icon appears next to the field indicating the substitution is active
datamapper field override substitution selected
datamapper field substitution icon
Note

Override Type and Substitute Element are mutually exclusive on the same field. The modal will show only the applicable options based on the field’s schema definition.

5.17.1.6. Working with Abstract Elements

Abstract elements are special schema elements that cannot be used directly in XML instances - they must be substituted with a concrete implementation. The DataMapper provides two approaches for working with abstract elements.

5.17.1.6.1. Viewing Available Implementations

The DataMapper automatically displays abstract elements with their substitution candidates as children in the document tree. You can create mappings directly to these substitution candidates without explicitly applying a substitution.

datamapper abstract elements
Important

You must either create a mapping on a substitution candidate under the abstract field, or apply field substitution.

Method 1: Using Substitute Element Modal

Explicitly select a concrete implementation using the Field Override modal:

Steps:

  1. Right-click on the abstract element
  2. Select "Override Field…​" from the context menu
  3. Select the "Substitute Element" radio button in the modal
  4. Choose a concrete implementation from the list of substitution candidates
  5. The field updates to show the selected concrete element
datamapper abstract field override

Method 2: Using Context Menu

For quick selection, you can use the context menu directly:

Steps:

  1. Right-click on the abstract element
  2. Select the concrete implementation directly from the context menu
  3. The field updates to show the selected element
datamapper abstract context menu
Tip

Use the Field Override modal for detailed selection or the context menu for quick selection. Once selected, the abstract element is replaced with the concrete implementation in the generated XSLT.

5.17.1.7. Identifying Overridden Fields

Fields with active overrides are easy to identify in the document tree:

  • Override Type - Marked with an override type icon indicator
  • Substitute Element - Marked with a substitution icon indicator

These visual indicators help you quickly see which fields have been modified from their original schema definitions.

5.17.1.8. Resetting a Field Override

To restore the original schema-defined field:

  1. Right-click on the overridden field (marked with an icon indicator)
  2. Select "Reset Override" from the context menu
  3. The field returns to its original type or element
  4. The icon indicator is removed
datamapper reset override
Note

Resetting a field override may invalidate mappings that reference fields only available in the overridden version.

5.17.2. Choice Support

5.17.2.1. Understanding xs:choice in Schemas

XML Schema xs:choice defines a set of element options where the behavior depends on the maxOccurs attribute:

  • maxOccurs=1 (default): Only one option can appear in a valid XML document
  • maxOccurs>1: Multiple instances can appear, potentially mixing different choice options

The DataMapper represents choices as expandable choice groups in the document tree. The mapping interface allows selecting one option at a time, regardless of the maxOccurs value.

5.17.2.2. Selecting a Choice Member

When the document tree contains a choice group, it appears as a collapsible node with the available options listed as children, similar to how abstract elements display their substitution candidates.

Steps:

  1. Expand the choice group in the document tree
  2. Right-click on the choice group to open the context menu
  3. Select the choice member you want to use from the menu
  4. The selected member expands, showing its child fields available for mapping
  5. Non-selected members are hidden from the tree
datamapper choice selection
Tip

You can change the selected choice member at any time. However, mappings to the previously selected member’s fields will remain in the XSLT and may need to be manually reviewed or removed.

5.17.2.3. Working with Nested Choices

The DataMapper supports nested choice elements. When multiple nested choices are selected, an indicator (e.g., ×2) appears next to the field showing how many choice wrapper levels have been collapsed.

datamapper choice nested indicator

5.17.2.4. Showing All Choice Options

To view all available choice options without a specific selection:

  1. Right-click on the choice group
  2. Select "Show All Choice Options"
  3. All choice members return to their default unselected state
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top