You can use the Group by Key Fields option of the mapper functionality to group data based on a key value, as shown in the following figure:
Figure : Merging Data Using a Key Value
In the example shown in the preceding figure, the in-warehouse-id element is the key field that is used to group the output. Both the first and third instances of the in-line-item repeating element in the source document contain the same value of the in-warehouse-id element (Warehouse1), so these elements are grouped together in the target (output) document.
This section describes how to group data by a key field using the Group by Key Fields option. This section shows how to group the example XML data shown in the preceding figure.
To Group Sets of Data Based on a Key Field
For this example, import the files: GroupKeyFldIn.xsd and GroupKeyFldOut.xsd. If you installed WebLogic Platform in the c:\bea directory, import these files from the c:\bea\weblogic81\workshop\help\doc\en\integration\reffiles\transform\groupKeyFields directory.
Importing schemas files triggers a build of the current Schemas project folder. Wait until the current Schemas folder is built before proceeding to the next step. (The representations of the schemas will not be available in Available Source Types and Available Target Type panes until build is complete.)
The elements and attributes that make up the selected element are displayed in the Selected Source Types pane.
For this example, complete this step for the GroupKeyFldIn.xsd/in-warehouse-inventory element.
For this example, expand the GroupKeyFldOut.xsd schema folder.
For this example, select the GroupKeyFldOut.xsd/out-inventory element.
The elements and attributes that make up the selected element are displayed in the Selected Target Type pane.
The Design View of the XQ file is displayed.
For this example, make the following links:
For this example, link the $in_warehouse_inventoryDoc/in-line-item repeating element to the out-inventory/out-line-item repeating element.
A dashed line linking the two repeating elements is displayed. The dashed line with short dashes represents a structural link—a link between two parent structures that does not map data directly. The dashed-line representation for a structural link is shown in the following figure:
To learn more about links, see Link Representations.
For this example, link the $in_warehouse_inventoryDoc/in-line-item repeating element to the out-inventory/out-warehouse-inventory repeating element.
A dashed line linking the two repeating elements is displayed. The dashed line with short dashes represents a structural link—a link between two parent structures that does not map data directly. The dashed-line representation for a structural link is shown in the following figure:
To learn more about links, see Link Representations.
At this point, in the Constraint tab, the Constraint Type is Repeatability/Join but in a preceding step, the Constraint Type will be set to Group by Key Fields)
Keep this link selected for the next step.
The following is displayed in the Design View as shown in the following figure:
For this example, in the Source Data pane, select the $in_warehouse_inventoryDoc node and import the file: GroupKeyFldIn.xml. If you installed WebLogic Platform in the c:\bea directory, import this file from the c:\bea\weblogic81\workshop\help\doc\en\integration\reffiles\transform\groupKeyFields\XML directory.
If not currently running, the WebLogic Server for the current application will be started. In order for a query to run, the WebLogic Server for the current application must be running.
In the Result Data pane, a graphical representation of the target data is displayed. The XML result for this example is also displayed in Figure: Merging Data Using a Key Value.
![]() |
![]() |