# Examples of Using the Repeatability/Join Constraint Type of the Constraints Tab

This section describes how to use the Repeatability/Join option of the mapper functionality to combine data. This section contains the following topics:

- Example: Combining Data From Different Schemas
- Example: Merging the Contents of Repeating Elements

### Example: Combining Data From Different Schemas

You can use the Repeatability/Join option of the mapper functionality to combine the contents of two different schemas, as shown in the following figure:

Figure : Combining Data From Different Schemas

In this case, the customer information is merged with the line-items repeating element to form one combined XML document.

This section describes how to create a transformation which combines the data from two different XML Schemas using the Repeatability/Join option. This section shows how to combine the example XML data shown in the preceding figure.

To Combine Data From Different Schemas

1. Import the two XSD files that contain the XML Schemas for the input types of the transformation. For instructions, see Selecting Input and Output Types.

For this example, import the files: CustInfo.xsd and PO.xsd files. 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\dataDiffSchemas directory.

2. Import the XSD file that contains the XML Schema for the output type of the transformation. For instructions, see Selecting Input and Output Types.

For this example, import the file: POCustInfo.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\dataDiffSchemas directory.

Importing schemas files triggers a build of the current Schemas project folder. Wait until the current Schemas project 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.)

Comment from Frank in SP2 time frame: SP3+ idea: We could combine all the elements into a single XSD to simplify the import procedure and cut down on the chances of someone screwing up. I'm not sure we should for this case because this section is about combining data from different schemas?

1. Create a Transformation file and a method in the Transformation file. For instructions, see Creating a Transformation File and a Transformation Method.
2. 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.

3. 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, select and add the CustInfo.xsd/customer and PO.xsd/purchase-order nodes.

4. Select the output type for the transformation:

1. In the Available Output Types pane, expand the schema and element folders, until you find the desired element.

For this example, expand the POCustInfo.xsd schema folder.

2. In the Available Input Types pane, select the desired element.

For this example, select the POCustInfo.xsd/purchase-order element.

3. Click Select.

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

5. Click Create Transformation.

The Design View of the XQ file is displayed.

6. Create links between repeating element nodes:

1. In the Source Schema pane, select the repeating element and drag it to the repeating element in the Target Schema pane.

For this example, link the $_purchase_orderDoc/line-items/line-item repeating element to the purchase-order/line-items/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.

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

For this example, link the $_purchase_orderDoc/line-items/line-item/part-no element to the purchase-order/line-items/line-item/part-no element. In addition, link the $_purchase_orderDoc/line-items/line-item/quantity element to the purchase-order/line-items/line-item/quantity element.

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:

To learn more about links, see Link Representations.

7. Create links between the second set of nodes.

In the Source Schema pane, select a source node drag it to the target node in the Target Schema pane.

For this example, select the $_customerDoc node and drag it to the $_purchase-order/customer node. A structural link between the two nodes is created.

For this example, the $_customerDoc/customer-id node and drag it to the $_purchase-order/customer/customer-id node. A data structural link between the two nodes is created.

For this example, the $_customerDoc/customer-name node and drag it to the $_purchase-order/customer/customer-name node. A data structural link between the two nodes is created.

For this example, the $_customerDoc/customer-address node and drag it to the $_purchase-order/customer/customer-address node. A data structural link between the two nodes is created.

For this example, the map between the source and target elements is shown in the following figure:

8. Select the Test View tab.
9. Import XML or non-XML files as input 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: InputPO.xml. In the Source Data pane, select the $_customerDoc node and import the file: InputCust.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\dataDiffSchemas\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\dataDiffSchemas\XML and then pressing enter.

10. 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, after the query is run a graphical representation of the output data is displayed.

11. If the output 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.
12. If desired, you can validate the result data against the associated schema. In the the Result Data pane of the Test View, click Validate. To learn more, see Validating During Design Time.
13. 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.

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

### Example: Merging the Contents of Repeating Elements

You can use the Repeatability/Join option of the mapper functionality to merge the contents of repeating elements, as shown in the following figure:

Figure : Merging the Contents of Repeating Elements

The join, shown in the preceding figure, merges the price and availability from the two input documents to one output document called Quote.xml. Specifically, the price (element: price) and widget Id (element: widgetId) for the widgets is supplied by the PriceQuote.xml document and the number of widgets available (element: requestedQuanity) is supplied by the AvailQuote.xml document. The widgetId and requestedQuanity elements are part of the availRequest repeating element and price element is part of the priceRequest repeating element. These subelements to repeating elements are merged into subelements of the quoteResponse repeating element.

For this example, a complete merge of the two sets of elements resulting in four elements as shown in Figure: Merging the Contents of Repeating Elements is not desired. Instead a conditional constraint is needed that will return the merged element only if the condition is true. To learn more, see Example: Creating a Conditional Constraint Using the Constraints Tab.

For a step-by-step walk through of using the mapping functionality to create a join with a conditional constraint, see Tutorial: Building Your First Data Transformation. Specifically, the join is created in Step 4: Mapping a Repeating Element (Join) in the Tutorial: Building Your First Data Transformation.