Using the Union Option of the Constraints Tab

You can use the Union option of the Constraints tab to combine sets of data of the same type into larger sets of data, as shown in the following figure.

Figure : Combining Sets of the Same Data

image

In this union, repeating elements of the same type are combined into a larger set but in the preceding join example in Merging the Contents of Repeating Elements, the contents of repeating elements are merged.

This section describes how to create a transformation which combines two sets of repeating elements using the Union option. This section shows how to combine the example XML data shown in the preceding figure.

To Combine Sets of Data of the Same Type

  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 type of the transformation. For instructions, see Selecting Source and Target Types.
  3. For this example, import the file: PO.xsd. 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\union

    Note: The PO.xsd file used in this example is identical to the PO.xsd file used in Combining Data From Different Schemas. If you have already imported the PO.xsd file for the Combining Data From Different Schemas example, you do not need to import it again.

  4. Import the XSD file that contains the XML Schema for the target type of the transformation. For instructions, see Selecting Source and Target Types.
  5. For this example, import the file: Order.xsd. 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\union 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.)

  6. Select the Transformation method from a Transformation file.
  7. To select an existing method, in the Design View of the Transformation file:

    1. Right-click the arrow representing the method.
    2. From the drop-down menu, select Configure XQuery Transformation Method.
  8. Select the source types 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, add the PO.xsd/purchase-order element twice.

  9. Select the target type for the transformation:
    1. In the Available Target Type pane, expand the Order.xsd schema folder.
    2. In the Available Source Types pane, select the Order.xsd/order element.
    3. Click Add.
    4. The elements and attributes that make up the selected element are displayed in the Selected Target Type pane.

  10. Click Create Transformation.
  11. The Design View of the XQ file is displayed.

  12. In the Source pane, select the first repeating element and drag it to the repeating element in the Target pane.
  13. For this example, link the $purchase_orderDoc/line-items/line-item repeating element in the Source pane to the order/items/item repeating element in the Target pane.

    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.

  14. In the Source pane, select the second repeating element and drag it to the repeating element in the Target pane.
  15. For this example, link the $purchase_orderDoc1/line-items/line-item repeating element in the Source pane to the order/items/item repeating element in the Target pane.

    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

    At this point, in the Constraint Type pane of the Constraints tab, the Repeatability/Join option is selected.

    Keep the last link selected for the next step.

  16. In the Constraint Type pane of the Constraints tab, select the Union option.
  17. Create data links from the first set of repeating element nodes.
  18. In the Source pane, select each of the subelements of the repeating element and drag them to the analogous subelement of the repeating element in the Target pane.

    For this example, link the nodes shown in the following table:

    Drag This Element From the Source Pane . . .
    To This Element in the Target Pane . . .

    $purchase_orderDoc/line-items/line-item/part-no

    order/items/item/line-number

    $purchase_orderDoc/line-items/line-item/quantity

    order/items/item/quantity-number

    Solid blue lines linking the two subelements are displayed. These solid lines represents a data link—a link that converts the value of the source node directly to the value of the target node The solid line representation for a data link is shown in the following figure.

    image

    Since the two structural links have the union constraint applied to them, a set of implied data links between the second set of subelements are generated as shown in the following figure.

    image

    The solid gray lines represents implied links.

  19. Select the Test View tab.
  20. Import XML or non-XML files as source data for the transformation. For more information, see Creating Maps.
  21. For this example, in the Source Data pane, select the $purchase_orderDoc node and import the file: InputPO1.xml. In the Source Data pane, select the $purchase_orderDoc1 node and import the file: InputPO2.xml. 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\union\XML directory.

    Note: You can cut and past directory paths into the Name field of the Open File to Test pane to jump to directory locations. If you installed WebLogic Platform in the c:\bea directory, you can jump to the directory that contains the XML files for this example, by pasting the following directory path into the Name field: c:\bea\weblogic81\workshop\help\doc\en\integration\reffiles\transform\union\XML and then pressing enter.

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

  24. 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. The XML result for this example is also displayed in Figure: Combining Sets of the Same Data.
  25. If desired, you can validate the result data against the associated schema. In the the Result Data pane of the Test View, click Validate.
  26. Save the DTF and the XQ file. From the menu bar, choose File —> Save All.

Note: The nodes are being joined in the union and not the data in the nodes. For example, if you are merging repeating elements in which the value of the part-no element is equal to 1, both part-no elements appear in the target data as shown in the following figure.

image

The query returns both repeating elements because it determines the repeating nodes are unique, even if the values of the part-no element are both equal to 1.

Previous Document Next Document