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 targetfor-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
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
Identify the target collection field — Look for the layer icon
on the target fieldClick the
⋮menu on the target collection field and select “Wrap with Instruction” → “Wrap with for-each”
Select wrap with for-each Specify the source collection — Choose which source collection to iterate over

Select source collection to iterate Map the collection item fields — Create mappings for individual fields within each collection item

Map fields for each collection item
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:
- Click the
⋮menu on the target field and select “Inner Instruction” → “Inner for-each” - Enter the source collection XPath on the inner
for-eachnode - Map child fields inside the
for-eachscope
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
Create a for-each mapping as described above
Click the
⋮menu on thefor-eachnode and select “Configure Sort”
Select Configure Sort from the for-each context menu 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 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 Configure Ascending/Descending (optional) — Toggle the direction per sort key

Ascending/Descending toggle Re-order sort keys (optional) — Drag the handle to reorder

Re-order sort keys by drag-and-drop Expand advanced properties (optional) — Click the slider button on a sort key for data-type and case-order options

Sort key advanced properties 
Advanced properties expanded Click Save to apply

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
Create the first for-each mapping as described above
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 Configure the second collection — Select the source collection and map its fields

Configure second collection and map its fields

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
| Strategy | XSLT attribute | Description |
|---|---|---|
| Group By | group-by | Group items that produce the same value for the grouping expression. The most common strategy. |
| Group Adjacent | group-adjacent | Group consecutive items that produce the same value. Resets when the value changes. |
| Group Starting With | group-starting-with | Start a new group each time an item matches the XPath pattern. |
| Group Ending With | group-ending-with | End the current group each time an item matches the XPath pattern. |
Steps
- Click the
⋮menu on the target collection field and select “Wrap with Instruction” → “Wrap with for-each-group”

Enter the source collection XPath in the inline input — this is the population to group (the
selectattribute ofxsl:for-each-group)Click the
⋮menu on thefor-each-groupnode and select “Configure for-each-group” to open the configuration modal

Choose a grouping strategy from the dropdown — select one of the four strategies described above
Enter the grouping value — For Group By or Group Adjacent, enter an XPath expression that produces the grouping key (for example,
Categoryto group by theCategorychild 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.Add sort keys (optional) — Sort the groups before processing using the Sort keys section, which works the same as Sorting For-Each Results above
Click Save
Map fields inside the group — Inside the
for-each-groupscope, map fields as normal. Field paths are relative to the current group’s context item.(Optional) Iterate the group members individually — Click the
⋮menu on thefor-each-groupnode and select “Inner Instruction” → “Inner for-each current-group()”. This inserts afor-eachwithselect="current-group()"inside the group scope so you can map per-item fields.

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:
- Click the
⋮menu on the target field and select “Inner Instruction” → “Inner for-each-group” - Enter the source collection XPath on the inner
for-each-groupnode - Click the
⋮menu on thefor-each-groupnode and select “Configure for-each-group” to set the grouping strategy and expression - Map fields inside the group scope
Next Steps
- Variables — use
xsl:variableas mapping sources inside loops - XPath Editor — write complex grouping and iteration expressions