In this step, you map source nodes to target nodes. The following figure shows the mapping of example XML data.
In the preceding figure, the source XML data has a different format than the target XML data. When building a query invoked by a Transformation method, you map the source nodes to target nodes as represented by the arrows. During run time, the transformation uses the mappings to convert the data from the source format to the target format. For example, the arrow labeled 1 represents the transformation of the priceQuote/customerName
element to the quote/name
element.
The mapping of the address data, is a more complex transformation, as represented by the arrow labeled 2 in the preceding figure. To transform the address information, all the attributes of the shipAddress
element (street
, city
, state
, and zip
) must be converted to a single string XML element called address
.
The source XML data is valid to a different XML Schema than the target XML data. As shown in the preceding figure, the example source XML document called PriceQuote.xml
is valid to the XML Schema in the PriceQuote.xsd
file. Additionally, the example source XML document called Quote.xml
is valid to the XML Schema in the Quote.xsd
file.
Note: | The PriceQuote.xml , AvailQuote.xml , QuoteRequest.xml files are located in the Tutorial_Process_ApplicationWeb/requestquote/testxml directory of the application. |
Note: | Figure 4-1 shows one source data type (priceQuote ). This is just one of the three sources to the myJoin method as described in
Step 2: Building the Transformation. In this step, the mappings between the XML Schema in the PriceQuote.xsd file to the XML Schema in the Quote.xsd file are discussed. In the
Step 4: Mapping Repeating Elements—Creating a Join, mappings between the other source types (AvailQuote.xsd and taxRate ) are discussed. |
Note: | The PriceQuote.xml , AvailQuote.xml , QuoteRequest_a.xml , QuoteRequest.xml , and Quote.xml files are provided as examples and are not used by the business process during run time. During run time, the business process constructs the source XML data, and passes it to the transformation as described in the
Introduction of this tutorial. |
Complete the following tasks to create, alter, and test mappings between the source and target data:
In this step, you map the XML string element called customerName from the source (PriceQuote.xsd
) to the XML string element called name in target (Quote.xsd
).
myJoin.xq
in the Design view:The Design view displays the a graphical representation of the selected sources in the Source pane, as shown in the following figure.
Note: | If the priceQuote1, availQuote1, and taxRate nodes are not displayed in your Source pane, follow the instructions in To Select the Source Types. |
The nodes displayed in the Source pane correspond to source parameters of the myJoin
method of the MyTutorialJoin Transformation file. The signature of the myJoin
method from the MyTutorialJoin.java
file is shown in the following Java code segment:
public abstract org.example.quote.QuoteDocument myJoin(org.example.price.PriceQuoteDocument priceQuote1, org.example.avail.AvailQuoteDocument availQuote1, float taxRate);
A solid line appears between the two elements. This solid line represents a data link between the two nodes—a link that converts the value of the source node directly to the value of the target.
This link corresponds to the mapping represented with an arrow (labeled with the number 1) in Figure 4-1.
In this step, you will map multiple attributes of one element to another single element.
The XML priceQuote1/shipAddress element contains the following attributes:
All these attributes will be mapped to the single XML quote/address element of type string. This mapping is represented by the arrow labeled 2 in Figure 4-1.
Link the multiple shipAddress attributes from the Source pane to the Target pane with drag-and-drop operations, as described in the following procedure:
Note: | You can also use the Shift key to select groups of nodes. |
Four new links are displayed, as shown in the following figure.
The links labeled with numbers in Figure 4-4, correspond to the mappings represented as arrows (label number 2) in Figure 4-1.
A query (in the XQuery language) is generated when you create mapping links from source elements and attributes to target elements and attributes.
myJoin.xq
file.The generated query is displayed as shown
Note: | The XQuery code labeled with numbers in Figure 4-1 correspond to the numbered mappings and links in Figure 4-4, respectively. |
Note: | Pressing Ctrl+S saves just the active file |
This section describes the steps necessary to test the query generated in the preceding section. In this section, you will enter source XML data, run that data against the query, and view the resulting target XML data.
myJoin.xq
file.PriceQuote.xml
as source data for the transformation:The Import File dialog box is displayed.
PriceQuote.xml
file.
A graphical representation of the PriceQuote.xml
file is displayed in the Source Data pane.
The source XML data in one format is transformed by the query to XML in the target format is displayed in the Result Data pane, as shown in the following figure.
To learn more about the transformation occurring in the query including a walk through of the generated XQuery code, see Understanding the Transformation.
Note: | In the XML document, the string: quot is the namespace prefix for the following namespace URI: xmlns:quot="http://www.example.org/quote". To learn more about namespace declarations and how this XML data was generated, see Understanding the Transformation. |
This section provides the steps for editing the generated query to add a delimiter between the street, city, state, and zip code fields of the address
element.
myJoin.xq
file.",",
between the address attribute parameters of the concat
function to delineate between the different address fields, as shown in the following listing:concat($priceQuote1/ns0:shipAddress/@street,",",
$priceQuote1/ns0:shipAddress/@city,",",
$priceQuote1/ns0:shipAddress/@state,",",
$priceQuote1/ns0:shipAddress/@zip)
The updated map is displayed as shown in the following figure.
In the proceeding step, you modified the links between shipAddress
attributes and the address
element in the query, which causes these links to change from direct data links (represented as blue lines) to implied links (represented as light gray lines) as show in the following figure. The mapper parses the XQuery code and determines that there are implied links between the target and source elements.
myJoin.xq
file and in the Result Data pane click Test.In the Result Data pane, the resulting XML data is displayed.
The street, city, state, and zip code fields of the address
element will be delineated by a commas, as shown in the following listing:
<address>12 Springs Rd,Morris Plains,nj,07960</address>
This section provides steps for converting the state
field to uppercase by calling a standard W3C XQuery function from the query.
myJoin.xq
file.state
attribute of the shipAddress
element and the quote/address
element.
In the Source pane, the state
attribute link gets highlighted in green.
In the General Expression pane of the Target Expression tab, the call to the concat
function is displayed.
$priceQuote1/ns0:shipAddress/@state
$priceQuote1/ns0:shipAddress/@state
attribute in the General Expression pane.The following is displayed in the General Expression pane, as shown in the following figure.
Leave $string-var
selected in the General Expression pane as shown in the preceding figure.
$string-var
parameter of the General Expression pane.In General Expression pane the following is displayed, as shown in the following figure.
In the XML Source tab of the Result Data pane, the state is displayed in uppercase characters, as shown in the following listing:
<address>12 Springs Rd,Morris Plains,NJ,07960</address>