# Manipulating and Constraining Data

More complex links can be built with the Constraints tab. You can constrain the relationship between source and target nodes using the functionally of the Constraints tab.

The following table provides information on which features of the Constraints tab, you should use to depending on how you want to constraint or manipulate your data, as shown in the following table:

If You Want to Manipulate Your Data to . . . | As Shown in . . . | To Learn More, See . . .
--- | --- | ---
Combine the contents of two different schemas. Sub-elements of the repeating elements are not merged. | Figure: Combining Data From Different Schemas | Example: Combining Data From Different Schemas
Merge the contents of repeating elements. Sub-elements of repeating elements are merged. | Figure: Merging the Contents of Repeating Elements | Example: Merging the Contents of Repeating Elements
Combine sets of data of the same type (same schema) into larger sets of data. Sub-elements of the repeating elements are not merged. | Figure: Combining Sets of the Same Data | Example: Using the Union Option of the Constraints Tab
Combine data and repeating elements based on a passed in key value. | Figure: Merging Data Using a Key Value | Example: Using the Group by Key Fields Option of the Constraints Tab
Add a condition constraint which limits the repeating elements that are returned. TODO: Maybe make this a complex condtional constraint? or add another row? | Figure: Using a Conditional Constraint to Merge Data | Example: Creating a Conditional Constraint Using the Constraints Tab
Return a different value for target node based on the outcome of condition(s) in if-then-else(s). | Figure: If-Then-Else | Adding If-Then-Else Constructs to a Link
Convert data from a XML Schema simple type to a complext type. | Figure: Non-Repeating Target Element to Repeating Source Group | Example: Creating a Transformation Between a Non-Repeating Source Element and Repeating Target Group
Convert data from a XML Schema complex type to a simple type. | Figure: Repeating Source Group to Non-Repeating Target Element | Example: Creating a Transformation Between a Repeating Source Group and Non-Repeating Target Element
TODO: Recursive schemas |  | Example: Using Recursive Schemas in Transformations

### Example: Combining Data From Different Schemas

You can use 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 example describes how to create a transformation which combines the data from two different XML Schemas. This example shows how to combine the XML sample data shown in the preceding figure. In this example, the source data is not constrained or limited to produce the target data—a where clause was not added to the for loop iterating over the purchase-order/line-items/line-items using the Constraints tab.

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

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 pane, select the 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 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.

1. In the Source 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 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.

1. Create links between the second set of nodes:

1. In the Source pane, select the $customerDoc node and drag it to the $purchase-order/customer node in the Target pane. A structural link between the two nodes is created.
2. Right-click the structural link between the $customerDoc node and the $purchase-order/customer node and from the pull-down menu select Induce Map.

A data structural link between the $customerDoc/customer-id node and the $purchase-order/customer/customer-id node is created.

A data structural link between the $customerDoc/customer-name node and the $purchase-order/customer/customer-name node is created.

A data structural link between the $customerDoc/customer-address node and the $purchase-order/customer/customer-address node is created.

The map between the source and target elements is shown in the following figure.

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.

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.

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

4. 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. The XML result for this example is also displayed in Figure: Combining Data From Different Schemas.
5. 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.
6. Save the DTF and the XQ file. From the menu bar, choose File —> Save All.

### Example: Merging the Contents of Repeating Elements

You can use 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.

### Example: 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 Example: Merging the Contents of Repeating Elements, the contents of repeating elements are merged.

SP3+ idea from Frank: 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>

LIZ COMMENT: I made this change to the PO.xsd schema.

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 Input and Output 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\u

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

For this example, import the file: Ouput.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 Input Types and Available Output 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 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.

6. Select the output type for the transformation:

1. In the Available Output Type pane, expand the Order.xsd schema folder.
2. In the Available Input 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 Output 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.

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

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

In the Source 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 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 sub-elements 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.

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.

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.

3. 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 output data is displayed.

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

### Example: Using the Group by Key Fields Option of the Constraints Tab

You can use the Group by Key Fields option of the mapper functionality to group data based on a key value, as shown in the following figure:

Figure : Merging Data Using a Key Value

In the example shown in the preceding figure, the in-warehouse-id element is the key field that is used to group the output. Both the first and third instances of the in-line-item repeating element in the input document contain the same value of the in-warehouse-id element (Warehouse1), so these elements are grouped together in the output document.

This section describes how to group data by a key field using the Group by Key Fields option. This section shows how to group the example XML data shown in the preceding figure.

To Group Sets of Data Based on a Key Field

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.

For this example, import the files: GroupKeyFldIn.xsd and GroupKeyFldOut.xsd. 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\groupKeyFields 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 Input Types and Available Output Type panes until build is complete.)

3. Select the input type(s) 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, complete this step for the GroupKeyFldIn.xsd/in-warehouse-inventory element.

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

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

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

For this example, select the GroupKeyFldOut.xsd/out-inventory element.

3. Click Add.

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

5. Click Create Transformation.

The Design View of the XQ file is displayed.

6. Create all the data links.

For this example, make the following links:

- From the Source pane, drag the $in_warehouse_inventoryDoc/in-line-item/in-warehouse-id element to the out-inventory/out-warehouse-inventory/out-warehouse-id repeating element in the Target pane.
- From the Source pane, drag the $in_warehouse_inventoryDoc/in-line-item/in-location-desc element to the out-inventory/out-warehouse-inventory/out-location-desc element in the Target pane.
- From the Source pane, drag the $in_warehouse_inventoryDoc/in-line-item/in-part-no element to the out-inventory/out-warehouse-inventory/out-line-item/out-part-no element in the Target pane.
- From the Source pane, drag the $in_warehouse_inventoryDoc/in-line-item/in-quality element to the out-inventory/out-warehouse-inventory/out-line-item/out-quantity element in the Target pane.

7. Create a link between input repeating element and the inner-most output repeating element. (See Figure: Merging Data Using a Key Value for an example of an inner-most and outer-most repeating elements.) In the Source pane, drag the input repeating element to the inner-most output 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.

For this example, link the $in_warehouse_inventoryDoc/in-line-item repeating element to the out-inventory/out-line-item repeating element.

8. In the Source pane, drag the input repeating element that contains the key field(s) to the outer-most output repeating element that will contain the key field(s) 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.

At this point, in the Constraint tab, the Constraint Type is Repeatability/Join but in a preceding step, the Constraint Type will be set to Group by Key Fields)

For this example, link the $in_warehouse_inventoryDoc/in-line-item repeating element to the out-inventory/out-warehouse-inventory repeating element.

Keep this link selected for the next step.

9. In the bottom half of the Design View for the XQ file, in the Constraints tab select the Group by Key Fields option.
10. In the Select Group Key pane, select the in-warehouse-id node and click Add.

The following is displayed in the Design View as shown in the following figure:

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.

For this example, in the Source Data pane, select the $in_warehouse_inventoryDoc node and import the file: GroupKeyFldIn.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\groupKeyFields\XML directory.

3. 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 output data is displayed.

4. 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.
5. If desired, you can validate the result data against the associated schema. In the the Result Data pane of the Test View, click Validate.
6. Save the DTF and the XQ file. From the menu bar, choose File —> Save All.

### Example: Creating a Conditional Constraint Using the Constraints Tab

TODO: Consider make this a complex conditional example. Can we reuse the if-then-else schemas? maybe have instructions to load tutorial and add another condition to the where clause.

In Merging the Contents of Repeating Elements, both of the input documents (PriceQuote.xml and AvailQuote.xml) share the common element widgetId. A constraint (as a condition) can be added to the join that specifies if the widgetId of the availRequest element is equal to the widgetId of the priceRequest element the merged repeating element quoteResponse be returned. Adding this constraint would change the resulting data as shown in Figure: Merging the Contents of Repeating Elements to the data shown in Figure: Using a Conditional Constraint to Merge Data.

Figure : Using a Conditional Constraint to Merge Data

For a step-by-step walk through of using the mapping functionality to create a join with a 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.

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

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

Figure : Non-Repeating Target Element to Repeating Source Group

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

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 Input and Output Types.

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

3. Import the XSD file that contains the XML Schema for the target type of the transformation. For instructions, see Selecting Input and Output 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\singleToRepeat 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 Input Types and Available Output 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 input type for the transformation:

1. In the Available Input Types pane, expand the PODate.xsd folder.
2. In the Available Input Types pane, 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 Input Types pane.

6. Select the output type for the transformation:

1. In the Available Output Type pane, expand the Dates.xsd folder.
2. In the Available Input Types pane, select the desired element.

For this example, select the Dates.xsd/date element.

3. Click Add.

The elements and attributes that make up the Dates.xsd/date element are displayed in the Selected Output Type pane.

7. Click Create Transformation.

The Design View of the XQ file is displayed.

8. In the Source pane, select the element (PODateDoc/billing-date) and drag it the repeating element (dates/date) in the Target pane.

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.

1. In the Source pane, select the element (PODateDoc/delivery-date) and drag it the repeating element (dates/date) in the Target pane.

A dashed line (representing a structural link) between two elements is displayed and the two dates (PODateDoc/delivery-date and PODateDoc/billing-date) are automatically unioned together. In addition, the Structural Link variable PODate is automatically created and displayed in the Data Palette.

The following XQuery is code is generated:

    <ns1:dates>
    {
    	for $PODate in $PODateDoc/ns0:billing-date union 	$PODateDoc/ns0:delivery-date
    	return
    		<ns1:date/>
    }
    </ns1:dates>

$PODateDoc is the source or input variable to the transformation, while $PODate is the iteration variable for union of the elements: $PODateDoc/ns0:billing-date and $PODateDoc/ns0:delivery-date.

During run time, the for loop in the preceding XQuery code is executed twice. The first time the for loop is run, the iteration variable $PODate is equal to the first element in the union: $PODateDoc/ns0:billing-date and the second time the for loop is run the iteration variable $PODate is equal to the second element in the union: $PODateDoc/ns0:delivery-date. The XML data returned by the preceding query returns two empty elements: <ns1:date/>. The following steps will add the XQuery code to return the billing and delivery dates to the query.

2. In the Source pane, select the PODateDoc/billing-date element and drag it the dates/value element in the Target pane.

Two data links are created as shown in the following figure.

Since the structural links (PODateDoc/billing-date to dates/date) and (PODateDoc/delivery-date dates/date) are unioned together, when you created the link from the PODateDoc/billing-date element to the dates/value element (dates/value), a second data link between the PODateDoc/deilivery-date element and dates/value element is automatically created.

3. In the Source pane, select the PODateDoc/billing-date element and drag it the dates/type element in the Target pane.

Two data links are created.

Keep the PODateDoc/billing-date to dates/type link selected for the next step.

4. Select the Target Expression tab. (If the Expression Builder tab is not visible in WebLogic Workshop, choose View —> Windows —> Expression Builder from the menu bar.)
5. Select the If Then Else option.

The XQuery if-then-else construct is added to the link. For example, the following XQuery source code segment for the link is replaced:

    data($PODate)

By the following XQuery source code segment for the link:

    if (xf:boolean("true")) then
    	data($PODate)
    else
    	()

6. Click If Condition.

The If Condition pane appears.

7. In this step, you add a condtion to the if section of the if-then-else:

1. Select the Palette. (If the Palette is not visible in WebLogic Workshop, choose View —> Windows —> Palette from the menu bar.)
2. In the Palette, expand Node Functions.
3. Select the local-name function and drag it into the Left Hand Expression pane of the If Condition pane. Leave the $node-var argument selected.
4. Select the Data Palette. (If the Data Palette is not visible in WebLogic Workshop, choose View —> Windows —> Data Palette from the menu bar.)
5. From the Data Palette pane, drag and drop the PODate Structural Link variable over the $node-var argument of the local-name function in the If Condtion pane.
6. Select the operator: =.
7. In the Right Hand Expression section of the If Condition pane, enter: "billing-date" and click Add.

Note: You must enter double quotes around the "billing-date" string.

The condition is added to the if section of the if-then-else.

8. Click Then Expression.
9. In the Then Expression section, replace the existing text with the string: "BILLING".

Replace the following text:

    data($PODate)

With the following string:

    "BILLING"

Note: You must enter double quotes around the "BILLING" string.

10. Click Apply.
11. Click Else Expression.
12. In the Else Expression section, enter the string: "DELIVERY".

Note: You must enter double quotes around the "DELIVERY" string.

13. Click Apply.
14. Select the General option, to view the generated if-then-else XQuery source code.

The following XQuery code is displayed:

    if (xf:local-name($PODate) = "billing-date") then
    	"BILLING"
    else
    	"DELIVERY"

During run time, this if-then-else statement is executed twice by the XQuery for loop. The if part of the if-then-else executes the following conditon:

    xf:local-name($PODate) = "billing-date"

In the left-hand expression of the if condtion, the iteration variable $PODate is passed into the local-name function as a parameter. The local-name function returns the name of the XML element. For example: if the $PODate iteration variable contains the XML element named billing-date, the string: billing-date is returned by the local-name function and therefore, the left-hand expression of the if condtion evaluates to the string: billing-date.

The right-hand expression of the if condition is equal to the string: "billing-date".

In the if condition, the left-hand expression is compared with the right-hand expression, and if the two strings are equal, the if condition evaluates to true and the string: "BILLING" is returned as the value of the target node: dates/date/type.

Note: For simplistly, in this example it is assumed that if $PODate does not equal "billing-date", it must equal "delivery-date".

15. Select the Test View tab.
16. Import XML files as input 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\singleToRepeat\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\singleToRepeat\XML and then pressing enter.

17. 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 output data is displayed.

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

### Example: 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 Input and Output 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.

3. Import the XSD file that contains the XML Schema for the target type of the transformation. For instructions, see Selecting Input and Output 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.

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.

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

1. In the Available Input Types pane, expand the Dates.xsd folder.
2. In the Available Input 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 Input Types pane.

6. Select the output type for the transformation:

1. In the Available Output Type pane, expand the PODate.xsd folder.
2. In the Available Input 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 Output 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.

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

1. 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 return data if during run time the constraint is equal to true.

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

2. In the Source pane, select the 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.

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

1. Clicking Add.

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

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

2. Select the Test View tab.
3. Import XML files as input 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.

4. 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 output data is displayed.

5. 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.
6. If desired, you can validate the result data against the associated schema. In the the Result Data pane of the Test View, click Validate.
7. Save the DTF and the XQ file. From the menu bar, choose File —> Save All.

### Example: Using Recursive Schemas in Transformations

This example shows how to create mappings with schemas that have recursive elements. A recursive element contains a child element of the same type as the parent as shown in the following example XML Schema listing:

    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"  targetNamespace="http://www.acme.org/Product" xmlns="http://www.acme.org/Product" elementFormDefault="qualified" attributeFormDefault="unqualified">
    	<xs:complexType name="product">
    		<xs:sequence>
    			<xs:element name="part-description" minOccurs="0" maxOccurs="unbounded" type="xs:string" />
    			<xs:element name="child-product" minOccurs="0" maxOccurs="unbounded" type="product" />
    		</xs:sequence>
    	</xs:complexType>
    </xs:schema>

In this example, the product element is a recursive because it contains a child-product element which is type product as shown in bold in the preceding code listing.

Figure : Transformation Between a Non-Recursive Source Elements and a Recursive Target Element

To Create and Run a Transformation Between a Non-Recursive Source Elements and a Recursive Target Element

1. Open a query in the mapper pane. For instructions see General Steps to Open or Create a Query in the Mapper.

For this example, import the files: SupplierAcme.xsd and Product.xsd files (step 2 in General Steps to Open or Create a Query in the Mapper.) 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\recursive directory.

For this example, select and add the SupplierAcme.xsd/supplier-acme node as an input type (step 4 in General Steps to Open or Create a Query in the Mapper.)

For this example, select and add the Product.xsd/Global Types/product node as an output type (step 4 in General Steps to Open or Create a Query in the Mapper.)

2. Select the Design View.
3. In the Target pane of the Design View, expand the child-product node by right-clicking the child-product node and from the drop-down menu selecting Expand Recursive Node.

A second parent node appears under the child-product node as shown in the following figure.

4. In the Target pane of the Design View, expand the second level child-product node by right-clicking the second-level or bottom child-product node and from the drop-down menu selecting Expand Recursive Node.

A third parent node appears under the second-level child-product node as shown in the following figure.

5. In the Design View, create a link by dragging-and-dropping the supplier_acmeDoc/part-description-00100 Source element over the top-level product/part-description Target node as shown in the following figure.
6. In the Design View, create a link by dragging-and-dropping the supplier_acmeDoc/part-description-00102 Source element over the second level product/part-description Target node as shown in the following figure.
7. In the Design View, create a link by dragging-and-dropping the supplier_acmeDoc/part-description-00103 Source element over the third level product/part-description Target node as shown in the following figure.

8. Select the Test View tab.
9. Import XML files as input data for the transformation.

For this example, in the Source Data pane, select the $supplier_acmeDoc node and import the file: InputRecursive.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\recursive\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\recursive\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, a graphical representation of the output data is displayed.

11. 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.
12. Save the DTF and the XQ file. From the menu bar, choose File —> Save All.