Skip to main content Skip to complementary content
Close announcements banner

Aggregating nested loops into a simple loop

Convert an XML structure with nested loops into a flat CSV structure by aggregating nested loops.

Before you begin

You have created a map and added an input and an output structure.

About this task

This example uses the same input structure as in Combining nested loops into a simple loop. The goal of the transformation is to have a CSV file with a row for each Address element containing information about the delivery and the products.

The output structure contains multiple PartNumber and ProductName elements so that each row can contain all the products to be delivered to a specific address. It is defined as follows:
AddressesShipping
	Address (0:*)
		Name
		Street
		City
		State
		Zip
		Country
		DeliveryNotes
		PartNumber_1
		ProductName_1
		PartNumber_2
		ProductName_2
		PartNumber_3
		ProductName_3

Procedure

  1. Drag the following input elements to the corresponding output elements:
    • Name
    • Street
    • City
    • State
    • Zip
    • Country
    • DeliveryNotes
  2. Drag the input PartNumber element to the output PartNumber_1.
    Since the output structure is already looping on the input Address element, this causes a conflict.
  3. In the dialog box that opens, select Generate AgConcat value expression and click OK.
    With this option, all values for the PartNumber elements contained in each Address element are aggregated in a single field using an AgConcat function. If you want to have a single value per field, you need to use a filter.
  4. Drag a SingleIndex function to the Filter argument in the Value tab of the output PartNumber_1 element.
    To get the value of the first PartNumber element, you can leave the default value for the index.
  5. Drag the input PartNumber element to the output PartNumber_2 and PartNumber_3 elements, then select Generate AgConcat value expression in the dialog boxes that open and click OK.
    The filters are automatically configured based on the expression defined in PartNumber_1.
  6. Repeat the previous steps to map the input ProductName element to the output ProductName_1, ProductName_2 and ProductName_3 elements.

    Example

Results

Your mapping is configured. If you have a sample document, you can click Test Run to see the result. In this example, it should look like this:
Name,Street,City,State,Zip,Country,DeliveryNotes,PartNumber_1,ProductName_1,PartNumber_2,ProductName_2,PartNumber_3,ProductName_3
Deandre King,4894  Winding Way,Southfield,MI,48075,USA,Please leave packages in shed by driveway.,872-AA,Lawnmower,926-AA,Baby Monitor,,
Burl Clark,3807 Pointe Lane,Fort Lauderdale,FL,33308,USA,,356-KX,Gas canister,,,,

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 – let us know how we can improve!