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 Source Element to Repeating Target Group
To Create and Run a Transformation Between a Non-Repeating Source Element and a Repeating Target Group
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\singleToRepeat directory.
Note: The PODate.xsd file used in this example is identical to the PODate.xsd file used in Creating a Transformation Between a Repeating Source Group and Non-Repeating Target Element. If you have already imported the PODate.xsd file for the Creating a Transformation Between a Repeating Source Group and Non-Repeating Target Element example, you do not need to import it again.
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.
Note: The Dates.xsd file used in this example is identical to the Dates.xsd file used in Creating a Transformation Between a Repeating Source Group and Non-Repeating Target Element. If you have already imported the Dates.xsd file for the Creating a Transformation Between a Repeating Source Group and Non-Repeating Target Element 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.)
To select an existing method, in the Design View of the Transformation file:
The elements and attributes that make up the PODate.xsd/PODate element are displayed in the Selected Source Types pane.
For this example, select the Dates.xsd/date element.
The elements and attributes that make up the Dates.xsd/date element are displayed in the Selected Target Types pane.
The Design View of the XQ file is displayed.
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.
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.
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.
Keep the PODateDoc/billing-date to dates/type link selected for the next step.
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 ()
The If Condition pane appears.
Note: You must enter double quotes around the "billing-date" string.
The condition is added to the if section of the if-then-else.
data($PODate)
"BILLING"
Note: You must enter double quotes around the "BILLING" string.
Note: You must enter double quotes around the "DELIVERY" string.
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 condition:
xf:local-name($PODate) = "billing-date"
In the left-hand expression of the if condition, 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 condition 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 simplicity, in this example it is assumed that if $PODate does not equal "billing-date", it must equal "delivery-date".
For this example, in the Source Data pane, select the $datesDoc node and import the file: PODateInput.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.
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.
![]() |
![]() |