Automatically Creating for-each Statements

You can automatically create for-each statements when mapping between repeatable source and target elements in the mapper.

To automatically create for-each statements:
  1. In the Source panel, identify the repeatable source and target elements to which to map. A repeatable element is identified by a special icon with two bars to the left of the name. When you place your cursor over these elements, the words Repeating Element are displayed. For this example, there are parent and child book and title repeatable elements in the Source panel and parent and child item and name repeatable elements in the Target panel.

  2. In the Source panel, map the child repeatable element to the child target repeatable element (for this example, the source repeatable element title is mapped to the target repeatable element name).

    In the Mapping column of the Target panel, a for-each statement is automatically created with a selectable value (for this example, named title).
  3. Click the for-each statement to access the Mapping Builder.
    A for-each statement with an absolute path is displayed.

  4. Click Close to exit the Mapping Builder.
  5. In the Source panel, identify the parent repeatable source and target elements to which to map (for this example, book and item).
  6. In the source data structure, map the parent repeatable element to the parent target repeatable element (for this example, the source repeatable element book is mapped to the target repeatable element item).

    The mapper creates a second for-each statement to loop through the book element and place the mapping into the item element. This statement does not include a value to select because parent elements do not typically contain attributes to map.
  7. Click the for-each function to access the Mapping Builder. The for-each statement is displayed. Note that the absolute path of the mapping is converted to a relative path.

  8. Click Close to exit the Mapping Builder.
  9. Map the source attribute to the target attribute (for this example, lang is mapped to lang).

  10. In the Mapping column, click the attribute to access the Mapping Builder.
  11. In the upper right corner, select Actions > Show Content to display the execution code.
    The first for-each selects the books and the second for-each selects the book titles.

  12. Click Close to exit the Mapping Builder.
  13. Click Test.
  14. Enter the source payload and click Execute. For this example, the payload includes two book titles. Each title is displayed in both English and Spanish.
    The titles in English and Spanish for both books are displayed in the Output panel..

For more information about repeatable elements, see Repeating a Target Element to Map to Different Sources.