Merge two parallel loops into a single loop using an aggregation
function.
Before you begin
You have created a map with an input and output structure. For this example, you can
use
CustomerAddress as input and
CustomerCombinedAddresses as output. These structures can be
found under .
About this task
In this example, you have an input with two loops: Address
and
AddressDetail
, and you want to map their elements to a single
Address
loop in the output.
This map is available in .
Procedure
-
Drag the input
Address
loop to the corresponding output
loop.
The elements are mapped and a looping expression is added to the output
Address
.
-
Drag the input
Detail
element to the corresponding output.
-
In the dialog box that opens, click Yes.
An
AgConcat with a loop expression and context is
automatically created. If you test the map, the output
Detail
element will contain all the values in the input element, for every iteration of the
Address
element. If you want to have the value of only one
Detail
iteration, you need to use a filter.
-
Drag and drop a SingleIndex function the
Filter argument of the looping expression under the
NestedContext function.
-
Drag and drop a LoopIndex function on the
Index argument.
-
Drag and drop the output
Address
element on the Looping
Output Element argument.
This specifies that the
Detail
element should return only one
value per iteration, based on the index of the
Address
loop. For
example, for the first iteration of
Address
, the output
Details
returns the value of the input
Details
for the first iteration of
AddressDetails
.
Results
The elements are mapped, you can use the
Test
Run button to see the output based on the sample input file. In this
example, the output looks like
this:
<Customer>
<Address>
<Detail>Information about 123 Main Street</Detail>
<Street>123 Main Street</Street>
<City>Oakland</City>
<State>CA</State>
</Address>
<Address>
<Detail>Information about 456 Broadway Ave</Detail>
<Street>456 Broadway Ave</Street>
<City>Oakland</City>
<State>CA</State>
</Address>
<Address>
<Detail>Information about 67th Street</Detail>
<Street>912 67th Street</Street>
<City>Berkeley</City>
<State>CA</State>
</Address>
<Address>
<Detail>Information about 415 East Ave</Detail>
<Street>415 East Ave</Street>
<City>Oakland</City>
<State>CA</State>
</Address>
</Customer>