Example: Using the Union Constraint Type of the Constraints Tab

You can use the Union option of the mapper functionality 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 Example: Merging the Contents of Repeating Elements, the contents of repeating elements are merged.

SP3+ idea: While it has made for interesting test cases, having both line-items+ and line-item+ repeatable doesn't really make sense. All you would need to do is lop off the outer maxOccurs="unbounded" in PO.xsd:

<xs:choice maxOccurs="unbounded">

<xs:choice>

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 input and output types of the transformation. For instructions, see Selecting Input and Output 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 directory. The PO.xsd file is used as both the input and output type.

    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 Input Types and Available Output Type panes until build is complete.)

  4. Select the Transformation method from a Transformation file.
  5. 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.
  6. Select the input types for the transformation:
    1. In the Available Input Types pane, expand the schema and element folders, until you find the desired element.
    2. In the Available Input Types pane, select the desired element.
    3. Click Add.

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

    For this example, add the PO.xsd/purchase-order element twice.

  7. Select the output type for the transformation:
    1. In the Available Output Type pane, expand the schema and element folders, until you find the desired element.
    2. For this example, expand the PO.xsd schema folder.

    3. In the Available Input Types pane, select the desired element.
    4. For this example, select the PO.xsd/purchase-order element.

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

  8. Click Create Transformation.
  9. The Design View of the XQ file is displayed.

  10. Create links between the first set of repeating element nodes:
    1. In the Source Schema pane, select each of the sub-elements of the repeating element and drag them to the analogous sub-element of the repeating element in the Target Schema pane.
    2. A dashed line linking the two sub-elements is displayed. The dashed line with long dashes represents a data structural link—a data link that also links two structures. The dashed-line representation for a data structural link is shown in the following figure:

      image

      To learn more about the links, see Link Representations.

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

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

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

      purchase-order/line-items/line-item/line-no

      $_purchase_orderDoc1/line-items/line-item/quantity

      purchase-order/line-items/line-item/quantity

    3. In the Source Schema pane, select the repeating element and drag it to the repeating element in the Target Schema pane.
    4. 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.

      For this example, link the $_purchase_orderDoc1/line-items/line-item repeating element in the Source Schema pane to the purchase-order/line-items/line-item repeating element in the Target Schema pane.

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

  11. Create a structural link between the second set of repeating element nodes. In the Source Schema pane, select the repeating element and drag it to the repeating element in the Target Schema pane.
  12. In the Constraint Type pane, the Union option becomes active because the mapper induces that a union between the first and the second set of repeating elements is possible. A union is possible because the repeating elements contain the same set of sub-elements.

    For this example, link the $_purchase_orderDoc2/line-items/line-item repeating element in the Source Schema pane to the purchase-order/line-items/line-item repeating element in the Target Schema pane.

  13. In the Constraint Type pane of the Constraints tab, select the Union option.
  14. Data structural links between the second set of subelements is generated as shown in the following figure:

    image

IDEA for SP3+: Drawing the part-no and quantity data links first helps illustrate the implied links of the union here. However, in the future, I should help you come up with a case that actually needs the data links. Right now, the map could also (and more easily) be done by just the two structural links.

Moreover, the implied gray lines are dashed not because of the union but only because part-no and quantity are optional. One other tweak you could make is making them mandatory in PO.xsd:

<xs:element name="part-no" type="xs:string" minOccurs="0" />

<xs:element name="quantity" type="xs:string" minOccurs="0" />

<xs:element name="part-no" type="xs:string" />

<xs:element name="quantity" type="xs:string" />

This could help emphasize that the consequence of doing the union is the "grayness" and not the "dottedness".

  1. Select the Test View tab.
  2. Import XML or non-XML files as input data for the transformation. For more information, see Creating Maps.
  3. For this example, in the Source Data pane, select the $_purchase_orderDoc1 node and import the file: InputPO1.xml. In the Source Data pane, select the $_purchase_orderDoc2 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.

  4. In the Result Data pane, click Test.
  5. 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 output data is displayed.

  6. 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.
  7. If desired, you can validate the result data against the associated schema. In the the Result Data pane of the Test View, click Validate.
  8. Save the current Transformation file:
    1. In Application tab, select the folder that contains the Transformation file (ends in the .dtf extension). (If the Application tab is not visible in WebLogic Workshop, choose View —> Application from the menu bar.)
    2. Right-click the Transformation file and in the drop-down menu select Save file.dtf, where file represents the name of the current Transformation file.
  9. Save the current XQ file:
    1. In Application tab, select the folder that contains the XQ file. (If the Application tab is not visible in WebLogic Workshop, choose View —> Application from the menu bar.)
    2. Right-click the XQ file and in the drop-down menu select Save file.xq where file represents the name of the current XQ file.

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 output 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