Skip to main content Skip to complementary content

Mapping a loop to a non-looping element

Aggregate values from a loop into a non-looping element.

Before you begin

You have created a map with an input and output structure. This example uses the same map as in Mapping nested loops.

About this task

In this example, you want to configure the output TotalItems element to return the number of output PartNum elements in each Items loop, and the output TotalNotices element to return the number of output Num elements.

This map is available in Other Projects > Examples > Maps > Looping > LoopAggregate.

Procedure

  1. Optional: If you are using the map created in the previous example, drag the input PartNumber element to the output PartNum.
    Your map should look like this:
  2. Drag an AgCount function and drop it on the output TotalItems element.
  3. Drag the output PartNum on the AgCount.
    A loop expressions is required to provide context for the aggregation. In this case, a LoopCopy function is automatically added to indicate that this element should use the same looping as the PartNum element.
  4. Drag an AgCount function and drop it on the output TotalNotices element.
  5. Drag the output Num on the AgCount.
    A LoopCopy function is automatically added.

Results

The loops are aggregated, 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:
<Notices>
  <Notice>
    <Num>1</Num>
    <Name>Francis Upton</Name>
    <Items>
      <PartNum>1A45</PartNum>
    </Items>
    <Items>
      <PartNum>2</PartNum>
    </Items>
    <TotalItems>2</TotalItems>
  </Notice>
  <Notice>
    <Num>2</Num>
    <Name>Francis Upton</Name>
    <Items>
      <PartNum>5TTT9</PartNum>
    </Items>
    <Items>
      <PartNum>123</PartNum>
    </Items>
    <TotalItems>2</TotalItems>
  </Notice>
  <Notice>
    <Num>2</Num>
    <Name>Martha Lyman</Name>
    <Items>
      <PartNum>K4223</PartNum>
    </Items>
    <Items>
      <PartNum>K4552</PartNum>
    </Items>
    <TotalItems>2</TotalItems>
  </Notice>
  <TotalNotices>3</TotalNotices>
</Notices>

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!