# 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

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.

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.

3. Import the XSD file that contains the XML Schema for the target type of the transformation. For instructions, see Selecting Source and Target Types.

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.)

4. Select the Transformation method from a Transformation file.

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.

5. 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.

6. 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.

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

7. Click Create Transformation.

The Design View of the XQ file is displayed.

8. In the Source pane, select the first repeating element and drag it to the repeating element in the Target pane.

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:

To learn more about links, see Link Representations.

9. In the Source pane, select the second repeating element and drag it to the repeating element in the Target pane.

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:

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.

10. In the Constraint Type pane of the Constraints tab, select the Union option.
11. Create data links from the first set of repeating element nodes.

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.

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.

The solid gray lines represents implied links.

12. Select the Test View tab.
13. Import XML or non-XML files as source data for the transformation. For more information, see Creating Maps.

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.

14. In the Result Data pane, click Test.

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.

15. 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.
16. If desired, you can validate the result data against the associated schema. In the the Result Data pane of the Test View, click Validate.
17. 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.

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.