
In this example, the different Person records are mapped to a nested structure. There can be multiple records for one person in the source structure where various telephone numbers are stored. In the target structure there is only ever one record for each person where all telephone numbers for this person are stored under the Telephones element.
The example assumes that the Person records of the source structure are ordered according to the ID field: Person records with the same ID are listed one after the other in the outbound message. If this were not so, you would have to sort the records according to ID using the sort function.
Solution
In the description of the individual target field mappings, [Root Context] is for the MapExampleFlatStructureMessage context of the source structure.
Target Field Mapping for Person :
ID [ Root C ontext] -> SplitByValue [Value Changed] -> CollapseContexts -> Person
A Person record must be created in the target structure for every record of the source structure where the same ID appears. Since the ID values are sorted, only the following steps are necessary:
Collect all the values in a context and add a contect switch ( SplitByValue ) to this context depending on the value switch.
You reduce the number of value for each context to the first value and then group all contexts in one ( CollapseContexts ).
In this way, exactly one Person node is created for each ID - even if it appears more than once.
Target Field Mapping for ID :
Id [R oot Context ] -> SplitByValue [Value Changed] -> CollapseContexts -> SplitByValue [Each Value] -> Id
This target field mapping is identical apart from the last use of SplitByValue : Since the number of contexts of the ID queue must be the same as the number of values of the superordinate Person queue, you have to add a context switch after every value using SplitByValue . More information: Enhanced User-Defined Functions .
Target Field Mapping for Name :
Name [R oot Context ] -> SplitByValue [Value Changed] -> CollapseContexts -> SplitByValue [Each Value] -> Name
This target mapping functions in the same way as the target field mapping for Id .
Target Field Mapping for TelephoneNumber :
All telephone numbers and IDs in each context are collected in this target field mapping. SplitByValue then adds a context switch to the list of IDs after every value switch. Since the list is sorted (see above), there are just as many values in the ID queue for each context as a person has telephone numbers. The IDs just have to be replaced by the corresponding telephone numbers and you would have the right results queue for TelephoneNumber . This conversion is executed by the standard function formatByExample .