Loop Mappings

Overview

Loop mappings iterate over a source collection and apply a set of field mappings to each item. The DataMapper supports two loop instructions:

  • for-each — Iterate over every item in a source collection and map its fields to the target
  • for-each-group — Group the items of a source collection by a key or pattern, then map each group

Collection fields are identified by the layer icon Layer icon in the document tree.


For-Each Mapping

Use xsl:for-each when you want to transform each item of a source collection into a corresponding target item.

Steps

  1. Identify the target collection field — Look for the layer icon Layer icon on the target field

  2. Click the ⋮ menu on the target collection field and select “Wrap with Instruction” → “Wrap with for-each”

    Select wrap with for-each
    Select wrap with for-each
    Select wrap with for-each

  3. Specify the source collection — Choose which source collection to iterate over

    Select source collection to iterate
    Select source collection to iterate
    Select source collection to iterate

  4. Map the collection item fields — Create mappings for individual fields within each collection item

    Map fields for each collection item
    Map fields for each collection item
    Map fields for each collection item

Important

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

Inner “for-each”

Use Inner “for-each” when the target field is always emitted (not a collection) but its content should be produced by iterating a source collection. Apply it to the target field instead of wrapping it:

  1. Click the ⋮ menu on the target field and select “Inner Instruction” → “Inner for-each”
  2. Enter the source collection XPath on the inner for-each node
  3. Map child fields inside the for-each scope

The outer target field is always written to the output; the for-each controls what is written inside it.


Sorting For-Each Results

Add xsl:sort to a for-each to control the output order.

Steps

  1. Create a for-each mapping as described above

  2. Click the ⋮ menu on the for-each node and select “Configure Sort”

    Select Configure Sort from the for-each context menu
    Select Configure Sort from the for-each context menu
    Select Configure Sort from the for-each context menu

  3. Configure sort keys — Enter the XPath expression for the field to sort by, or type ahead to select a field

    Configure Sort modal with sort key and options
    Configure Sort modal with sort key and options
    Configure Sort modal with sort key and options

  4. Add additional sort keys (optional) — Click “Add sort key” to add secondary sort criteria; items are sorted by each key in order

    Add sort key
    Add sort key
    Add sort key

  5. Configure Ascending/Descending (optional) — Toggle the direction per sort key

    Ascending/Descending toggle
    Ascending/Descending toggle
    Ascending/Descending toggle

  6. Re-order sort keys (optional) — Drag the handle to reorder

    Re-order sort keys by drag-and-drop
    Re-order sort keys by drag-and-drop
    Re-order sort keys by drag-and-drop

  7. Expand advanced properties (optional) — Click the slider button on a sort key for data-type and case-order options

    Sort key advanced properties
    Sort key advanced properties
    Sort key advanced properties
    Advanced properties expanded
    Advanced properties expanded
    Advanced properties expanded

  8. Click Save to apply

    Save sort configuration
    Save sort configuration
    Save sort configuration


Multiple For-Each Mappings

Merge multiple source collections into a single target collection by stacking multiple for-each mappings under the same target field.

Steps

  1. Create the first for-each mapping as described above

  2. Add another for-each — Click “Add Mapping Instruction” in the placeholder below the first mapping and select “Wrap with for-each”

    Add Mapping Instruction dropdown with 'Wrap with for-each' selected
    Add Mapping Instruction dropdown with 'Wrap with for-each' selected
    Add Mapping Instruction dropdown with 'Wrap with for-each' selected

  3. Configure the second collection — Select the source collection and map its fields

    Configure second collection and map its fields
    Configure second collection and map its fields
    Configure second collection and map its fields

Merging two source collections into a single target collection with multiple for-each mappings
Merging two source collections into a single target collection with multiple for-each mappings
Merging two source collections into a single target collection with multiple for-each mappings
Tip

This is useful for merging items from two different source arrays into a single output array.


For-Each-Group Mapping

Use xsl:for-each-group when you need to group items from a source collection before mapping them. Each group is processed as a unit — for example, grouping order lines by product category and emitting one summary element per category.

Grouping strategies

StrategyXSLT attributeDescription
Group Bygroup-byGroup items that produce the same value for the grouping expression. The most common strategy.
Group Adjacentgroup-adjacentGroup consecutive items that produce the same value. Resets when the value changes.
Group Starting Withgroup-starting-withStart a new group each time an item matches the XPath pattern.
Group Ending Withgroup-ending-withEnd the current group each time an item matches the XPath pattern.

Steps

  1. Click the ⋮ menu on the target collection field and select “Wrap with Instruction” → “Wrap with for-each-group”
Wrap with Instruction flyout — select 'Wrap with for-each-group'
Wrap with Instruction flyout — select 'Wrap with for-each-group'
Wrap with Instruction flyout — select 'Wrap with for-each-group'
  1. Enter the source collection XPath in the inline input — this is the population to group (the select attribute of xsl:for-each-group)

  2. Click the ⋮ menu on the for-each-group node and select “Configure for-each-group” to open the configuration modal

Configure for-each-group modal with strategy dropdown and grouping expression
Configure for-each-group modal with strategy dropdown and grouping expression
Configure for-each-group modal with strategy dropdown and grouping expression
  1. Choose a grouping strategy from the dropdown — select one of the four strategies described above

  2. Enter the grouping value — For Group By or Group Adjacent, enter an XPath expression that produces the grouping key (for example, Category to group by the Category child element). For Group Starting With or Group Ending With, enter an XPath pattern that matches group-boundary items. Use the fx icon to open the XPath Editor for complex expressions.

  3. Add sort keys (optional) — Sort the groups before processing using the Sort keys section, which works the same as Sorting For-Each Results above

  4. Click Save

  5. Map fields inside the group — Inside the for-each-group scope, map fields as normal. Field paths are relative to the current group’s context item.

  6. (Optional) Iterate the group members individually — Click the ⋮ menu on the for-each-group node and select “Inner Instruction” → “Inner for-each current-group()”. This inserts a for-each with select="current-group()" inside the group scope so you can map per-item fields.

Full for-each-group workflow: wrap → configure strategy → map fields inside the group
Full for-each-group workflow: wrap → configure strategy → map fields inside the group
Full for-each-group workflow: wrap → configure strategy → map fields inside the group

Inner “for-each-group”

When the target field is always emitted but its content should be produced by grouping a source collection, apply Inner “for-each-group” directly to the target field:

  1. Click the ⋮ menu on the target field and select “Inner Instruction” → “Inner for-each-group”
  2. Enter the source collection XPath on the inner for-each-group node
  3. Click the ⋮ menu on the for-each-group node and select “Configure for-each-group” to set the grouping strategy and expression
  4. Map fields inside the group scope

Next Steps

  1. Variables — use xsl:variable as mapping sources inside loops
  2. XPath Editor — write complex grouping and iteration expressions
docs