Using the Group by Key Fields Option of the Constraints Tab

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

image

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

  1. Create a Transformation file and a method in the Transformation file. For instructions, see Creating a Transformation File and a Transformation Method.
  2. Import the XSD file that contains the XML Schema for the source and target types of the transformation. For instructions, see Selecting Source and Target Types.
  3. 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.)

  4. Select the source type(s) for the transformation:
    1. In the Available Source Types pane, expand the schema and element folders, until you find the desired element.
    2. In the Available Source Types pane, select the desired element.
    3. Click Add.

    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.

  5. Select the target type for the transformation:
    1. In the Available Target Type pane, expand the schema and element folders, until you find the desired element.
    2. For this example, expand the GroupKeyFldOut.xsd schema folder.

    3. In the Available Source Types pane, select the desired element.
    4. For this example, select the GroupKeyFldOut.xsd/out-inventory element.

    5. Click Add.
    6. The elements and attributes that make up the selected element are displayed in the Selected Target Type pane.

  6. Click Create Transformation.
  7. The Design View of the XQ file is displayed.

  8. Create all the data links.
  9. For this example, make the following links:

  10. Create a link between source repeating element and the inner-most target repeating element. (See Figure: Merging Data Using a Key Value for an example of an inner-most and outer-most repeating elements.) In the Source pane, drag the source repeating element to the inner-most target repeating element in the Target pane.
  11. 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:

    image

    To learn more about links, see Link Representations.

  12. In the Source pane, drag the source repeating element that contains the key field(s) to the outer-most target repeating element that will contain the key field(s) in the Target pane.
  13. 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:

    image

    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.

  14. In the bottom half of the Design View for the XQ file, in the Constraints tab select the Group by Key Fields option.
  15. In the Select Group Key pane, select the in-warehouse-id node and click Add.
  16. The following is displayed in the Design View as shown in the following figure:

    image

  17. Select the Test View tab.
  18. Import XML or non-XML files as source data for the transformation. For more information, see Creating Maps.
  19. 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.

  20. In the Result Data pane, click Test.
  21. 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.

  22. If the resulting data is XML data, in the Result Data pane you can view the resulting data as an XML document by selecting the XML Source View tab.
  23. If desired, you can validate the result data against the associated schema. In the the Result Data pane of the Test View, click Validate.
  24. Save the DTF and the XQ file. From the menu bar, choose File —> Save All.
Previous Document Next Document