# Creating a Transformation Between a Repeating Source Group and Non-Repeating Target Element

This example shows how to map a XML Schema complex type (for example: a repeating element) to a XML Schema simple type (for example: a non-repeating single element). In this example, you will create a transformation that during run time will take a source repeating element and maps it to single target field using constraints as shown in the following figure.

Figure : Repeating Source Group to Non-Repeating Target Element

To Create and Run a Transformation Between a Repeating Source Group and a Non-Repeating Target Element

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: Dates.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\repeatToSingle directory.

Note: The Dates.xsd file used in this example is identical to the Dates.xsd file used in Creating a Transformation Between a Non-Repeating Source Element and Repeating Target Group. If you have already imported the Dates.xsd file for the Creating a Transformation Between a Non-Repeating Source Element and Repeating Target Group 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: PODate.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\repeatToSingle directory.

Note: The PODate.xsd file used in this example is identical to the PODate.xsd file used in Creating a Transformation Between a Non-Repeating Source Element and Repeating Target Group. If you have already imported the PODate.xsd file for the Creating a Transformation Between a Non-Repeating Source Element and Repeating Target Group example, you do not need to import it again.

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 type for the transformation:

1. In the Available Source Types pane, expand the Dates.xsd folder.
2. In the Available Source Types pane, select the Dates.xsd/dates element.
3. Click Add.

The elements and attributes that make up the Dates.xsd/dates element are displayed in the Selected Source Types pane.

6. Select the target type for the transformation:

1. In the Available Target Types pane, expand the PODate.xsd folder.
2. In the Available Target Types pane, select the desired element.

For this example, select the PoDate.xsd/PODate element.

3. Click Add.

The elements and attributes that make up the PoDate.xsd/PODate 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 repeating element (datesDoc/date) and drag it the first single element (PODate/billing-date) in the Target pane.

Keep this link selected for the next step.

A dashed line linking the two elements is displayed. The dashed line with short dashes represents a structural link—a link 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 this step, you add a constraint to the structural link created in the preceding step:

1. From the Source pane select the datesDoc/date/type node and drop it into the Left Hand Expression pane of the Where Clause Expression in the Constraints tab.
2. Select the operator: =.
3. In the Right Hand Expression pane of the Where Clause Expression in the Constraints tab, enter the following string: "BILLING".

Warning: You must enter the quotes around the string.

4. Clicking Add.

During run time, the constraint created in this step, just tests if constraint: datesDoc/date/type is equal to the string: "BILLING". The next step will add the XQuery code to the for loop to return data if during run time the constraint is equal to true.

10. In the Source pane, select the datesDoc/date/value element and drag it the PODate/billing-date element in the Target pane.

A data link is created.

During run time, this data link will return the value of datesDoc/date/value as the value of billing-date if the constraint: data($date/ns0:type) = "BILLING" evaluates to true.

11. In the Source pane, select the repeating element (datesDoc/date) and drag it the second single element (PODate/delivery-date) in the Target pane.

A dashed line linking the two elements is displayed.

Keep this link selected for the next step.

12. In this step, you add a constraint to the structural link created in the preceding step:

1. From the Source pane select the datesDoc/date/type node and drop it into the Left Hand Expression pane of the Where Clause Expression in the Constraints tab.
2. Select the operator: =.
3. In the Right Hand Expression pane of the Where Clause Expression in the Constraints tab, enter the following string: "DELIVERY". The next step will add the XQuery code to return data if during run time the constraint is equal to true.

Warning: You must enter the quotes around the string.

4. Clicking Add.

During run time, the constraint created in step, tests if datesDoc/date/type is equal to the string: "DELIVERY".

13. In the Source pane, select the datesDoc/date/value element and drag it the PODate/delivery-date element in the Target pane.

A data link is created.

During run time, this data link will return the value of datesDoc/date/value as the delivery-date if the constraint: data($date/ns0:type) = "DELIVERY" evaluates to true.

14. Select the Test View tab.
15. Import XML files as source data for the transformation.

For this example, in the Source Data pane, select the $datesDoc node and import the file: InputDates.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\repeatToSingle\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\repeatToSingle\XML and then pressing enter.

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

17. 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: Repeating Source Group to Non-Repeating Target Element.
18. If desired, you can validate the result data against the associated schema. In the Result Data pane of the Test View, click Validate.
19. Save the DTF and the XQ file. From the menu bar, choose File —> Save All.