# 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="productType">
    	<xs:sequence>
    		<xs:element name="part-description" minOccurs="0" maxOccurs="unbounded" type="xs:string" />
    		<xs:element name="child-product" minOccurs="0" maxOccurs="unbounded" type="productType" />
    	</xs:sequence>
    </xs:complexType>
    <xs:element name="product" type="productType">
    </xs:element>
    </xs:schema>

In this example, the product element is a recursive element because it is of type: productType and productType contains a child-product element which is also of type productType (productType refers to itself) as shown in bold in the preceding code listing.

Figure : Non-Recursive Source Elements to 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 source type (step 4 in General Steps to Open or Create a Query in the Mapper.)

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

2. Select the Design View.

The product node is displayed with one level of the recursive child-product node expanded as shown in the following figure.

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

Another child node appears under the second-level child-product node as shown in the following figure.

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

7. Select the Test View tab.
8. Import XML files as source 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.

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

10. 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: Non-Recursive Source Elements to a Recursive Target Element.
11. Save the DTF and the XQ file. From the menu bar, choose File —> Save All.