Skip Headers
Oracle® BPEL Process Manager Developer's Guide
10g Release 2 (10.1.2)
B14448-02
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

14 XSLT Mapper and Transformations

This chapter describes features of the XSLT Mapper and provides step-by-step instructions for mapping a sample purchase order schema to an invoice schema.

This chapter contains the following topics:

14.1 Use Case for Transformation

Transformation use is demonstrated in several Oracle BPEL Process Manager use cases.


See:


14.2 Creating a Transform Activity

A transform activity enables you to create a transformation using the XSLT Mapper tool. This tool enables you to map source elements to target elements. For example, you can map incoming source purchase order schema data to outgoing invoice schema data. To create a transformation with these mappings, you first drag and drop a transform activity from the Component Palette into your BPEL process diagram, as shown in Figure 14-1.

Figure 14-1 Invoking the Mapper from JDeveloper BPEL Designer

Description of Figure 14-1  follows
Description of "Figure 14-1 Invoking the Mapper from JDeveloper BPEL Designer"

Double-click the transform activity. Figure 14-2 shows the Transform window.

Figure 14-2 Transform Window

Description of Figure 14-2  follows
Description of "Figure 14-2 Transform Window"

Perform the following procedures

  1. Specify the following information:

    • Source variable from which to map elements

    • Source part of the variable (for example, a payload schema consisting of a purchase order request) from which to map

    • Target variable to which to map elements

    • Target part of the variable (for example, a payload schema consisting of an invoice) to which to map

  2. Specify a map file name or accept the default name in the Mapper File field. The map file is the file in which you create your mappings using the XSLT Mapper transformation tool.

    • If the map file already exists, click the flashlight icon (first icon) to browse mappings.

      If you select a file with a.xslt extension such as xform.xslt, it opens the mapper pane to create a new XSL file named xform.xslt.xsl, even though your intension was to use the existing xform.xslt file. A .xsl extension is appended to any file that does not already have a .xsl extension, and you must create the mappings in the new file. As a workaround, ensure that your files first have an extension of .xsl. If the XSL file has an extension of .xslt, then rename it to .xsl.

    • If the map file does not exist, enter a name for the map file in the Mapper File field and click the magic wand icon (second icon) to create a new mapping.

    • If the map file already exists and you want to edit it, click the note pad icon (third icon) to edit the mapping.


Note:

You can also create an XSL map file from an XSL stylesheet. Click New, then XML, then XSL Map From XSL Stylesheet from the File main menu in JDeveloper BPEL Designer.


See Also:

The online Help for the Transform window for detailed descriptions of the fields

14.3 The XSLT Mapper

You use the XSLT Mapper transformation tool to create the contents of a map file. Figure 14-3 shows the layout of the XSLT Mapper.

Figure 14-3 Layout of the XSLT Mapper

Description of Figure 14-3  follows
Description of "Figure 14-3 Layout of the XSLT Mapper"

The Source and the Target schemas are represented as trees and the nodes in the trees are represented using a variety of icons. The displayed icon reflects the schema or property of the node. For example:

The various properties of the element and attribute are displayed in the Property Inspector in the lower right of Figure 14-3 (for example, type, cardinality, and so on). The Functions Palette in the upper right of Figure 14-3 is the container for all functions provided by the XSLT Mapper. The mapper pane or canvas is the actual drawing area for dropping functions and connecting them to source and target nodes.

The XSLT Mapper provides three separate context sensitive menus:

Right-click in each of the three separate panels to see what the context menus look like. A full set of Undo Auto Map, Redo, Delete, and Delete All functions are also available.

14.3.1 Notes on the Mapper

  • A node in the target tree can be linked only once (that is, you cannot have two links connecting a node in the target tree).

  • An incomplete function and expression does not result in an XPath expression in the source view. If you switch from the design view to the source view with one or more incomplete expressions, the Mapper Messages window displays warning messages.

  • When you map duplicate elements in the XSLT Mapper, the style sheet becomes invalid and you cannot work in the Design view. The Log Window shows the following error messages when you map an element with a duplicate name:

    Error: This Node is Already Mapped  : 
    "/ns0:rulebase/for-each/ns0:if/ns0:atom/ns0:rel" 
      Error: This Node is Already Mapped  : 
    "/ns0:rulebase/for-each/ns0:if/ns0:atom/choice_1/ns0:ind" 
      Error: This Node is Already Mapped  : 
    "/ns0:rulebase/for-each/ns0:if/ns0:atom/choice_1/ns0:var"
    
    

    The workaround is to give each element a unique name.

14.4 Creating an XSL Map

The following steps provide a high level overview of how to create an XSL map using the po.xsd and invoice.xsd files in the Oracle_home\integration\orabpel\samples\demos\XSLMapper directory.

  1. In JDeveloper BPEL Designer, select the workspace project in which you want to create the new XSL map.

  2. Add the po.xsd and invoice.xsd files to the project.

  3. Right-click the selected project and select New.

    The New Gallery window appears.

  4. In the Categories tree, expand General and select XML.

  5. In the Items list, double-click XSL Map.

    The Create XSL Map File window appears. This window enables you to create an XSL map file that maps a root element of a source schema file or WSDL file to a root element of a target schema file or WSDL file.

      • Schema files that have been added to the project appear under Project Schema Files.

      • Schema files that are not part of the project can be imported using the Import Schema File facility. Click the Import Schema File icon (first icon to the right and above the list of schema files).

  6. Under Source, expand Project Schema Files, and then po.xsd. Select PurchaseOrder as the root element for the source.

  7. Under Target, expand Project Schema files, and then invoice.xsd. Select Invoice as the root element for the target.

    Description of transf_xslmap.gif follows
    Description of the illustration transf_xslmap.gif

  8. Click OK.

    A new XSL map is created.

14.5 Using the XSLT Mapper

The following sections describe how to use the XSLT Mapper:

14.5.1 Simple Copy by Linking Nodes

To copy an attribute or leaf-element in the source to an attribute or leaf-element in the target, drag and drop the source to the target. Copy the element PurchaseOrder/ID to Invoice/ID and the attribute PurchaseOrder/OrderDate to Invoice/InvoiceDate, as shown in Figure 14-4.

Figure 14-4 Linking Nodes

Linking Nodes
Description of "Figure 14-4 Linking Nodes"

14.5.2 Setting Constant Values

Perform the following steps to set a constant value.

  1. Select a node in the target tree.

  2. Invoke the context menu by right-clicking the mouse.

  3. Select the Set Text menu option.

  4. Enter text in the Set Text window (for example, Discount Applied, as shown in Figure 14-5).

  5. Click OK to save the text.

    A T icon is displayed next to the node that has text associated with it.

  6. If you want to remove the text associated with the node, right click the node to invoke the Set Text window again. Delete the contents and click OK.

Figure 14-5 Set Text Window

Set Text Dialog Box
Description of "Figure 14-5 Set Text Window"


See Also:

The online Help for the Set Text window for detailed information

14.5.3 Adding Functions

In addition to the standard XPath 1.0 functions, the Mapper provides a number of prebuilt extension functions and has the ability to support user-defined functions and named templates. The extension functions are prefixed with xp20 or orcl and mimic XPath 2.0 functions.

Perform the following steps to view function definitions and use a function:

  1. Select a category of functions (for example, String Functions) from the Component Palette.

  2. Right-click an individual function (for example, lower-case).

  3. Select Function Description. A window with a description of the function appears. You can also click a link at the bottom to access this function's description at the World Wide Web Consortium at www.w3.org.

    Description of funct_desc.gif follows
    Description of the illustration funct_desc.gif

  4. Drag a concat function into the mapper pane. This function enables you to connect the source parameters from the source tree to the function and the output of the function to the node on the target tree.

  5. Concatenate PurchaseOrder/ShipTo/Name/First and PurchaseOrder/ShipTo/Name/Last. Place the result in Invoice/ShippedTo/Name by dragging threads from the first and last names and dropping them on the left handle on the concat function. Also drag a thread from the ShippedTo name and connect it to the right handle on the concat function, as shown in Figure 14-6.

Figure 14-6 Using the Concat Function

Using Functions
Description of "Figure 14-6 Using the Concat Function"


See Also:

The documentation for the XPath extension functions, which is described in Appendix G, "XPath Extension Functions" and is also accessible by clicking Manage BPEL Domain, and then XPath Library in Oracle BPEL Console

14.5.3.1 Editing Function Parameters

To edit the parameters of the concat function, double-click the function icon to launch the Edit Function - concat window. This window enables you to add, remove, and reorder parameters. If you want to add a new comma parameter so that the output of the concat function is Last, First, then click Add to add a comma and reorder the parameters to get this output.

Figure 14-7 Editing Function Parameters

Editing Function Parameters
Description of "Figure 14-7 Editing Function Parameters"


See Also:

The online Help for the Edit Function window by clicking the Help button to see how to add, remove, and reorder function parameters

14.5.3.2 Chaining Functions

Complex expressions can be built by chaining functions. To remove all leading and trailing spaces from the output of the above concat function, use the left-trim and right-trim functions and chain them as shown in the Figure 14-8.

The chaining function can also be defined by dragging and dropping the function to a connecting link.

Figure 14-8 Chaining Functions

Chaining Functions
Description of "Figure 14-8 Chaining Functions"

14.5.3.3 Named Templates

Some complicated mapping logic cannot be represented or achieved by visual mappings. For these situations, named templates are useful. Named templates enable you to share common mapping logic. You can define the common mapping logic as a named template and then use it as often as you want.

You define named templates in the source view, and they appear in the User Defined Named Templates list of the Component Palette. You can use named templates in almost the same way as you use other functions. The only difference is that you cannot link the output of a named template to a function or another named template; you can only link its output to a target node in the target tree.

To write named templates, you must be familiar with the XSLT language. See any XSLT book or visit the following URL for details about writing named templates:

http://www.w3.org/TR/xslt

14.5.3.4 Importing User-Defined Functions

You can import your own set of Java functions, which appear in the function palette under the User defined Extension Functions category. They can be used like any other function. To add functions, select Preferences, then XSL Maps from the Tools main menu.


See Also:

Oracle_home\integration\orabpel\samples\demos\XSLMapper\ExtensionFunctions\README.txt for detailed instructions

14.5.4 Editing XPath Expressions

To use an XPath expression in a transformation mapping, select Advanced Functions from the Component Palette and drag and drop xpath-expression from the list into the transformation window, as shown in Figure 14-9.

Figure 14-9 Editing XPath Expressions

Description of Figure 14-9  follows
Description of "Figure 14-9 Editing XPath Expressions"

When you double-click the icon, the Edit XPath Expression window appears, as shown in Figure 14-10. You can press the Ctrl key and then the spacebar to invoke the XPath Building Assistant.

Figure 14-10 Edit XPath Expression Window

Description of Figure 14-10  follows
Description of "Figure 14-10 Edit XPath Expression Window "

Figure 14-11 shows the XPath Building Assistant.

Figure 14-11 The XPath Building Assistant

Description of Figure 14-11  follows
Description of "Figure 14-11 The XPath Building Assistant"


See Also:

The online Help for the Edit XPath Expression window, which includes a link to instructions on using the XPath Building Assistant

14.5.5 Adding XSLT Constructs

While mapping complex schemas, it is sometimes essential to conditionally map a source node to a target or map an array of elements in the source to an array of elements in the target. The XSLT Mapper provides various XSLT constructs in the context sensitive menu of the target tree for the preceding scenarios. To add an XSLT element like for-each, if, or choose to a schema element, select the element in the target tree. Right-click and select Add XSL Node to bring up the context menu and choose the required XSLT element in the menu.


See Also:

Oracle BPEL Process Manager Order Booking Tutorial for an example of using a for-each node

14.5.5.1 Conditional Processing with xsl:if

Note that HQAccount and BranchAccount are part of a choice in the PurchaseOrder schema; only one of them exists in an actual instance. To illustrate conditional mapping, copy PurchaseOrder/HQAccount/AccountNumber to Invoice/BilledToAccount/AccountNumber only if it exists. To do this:

  1. Select Invoice/BilledToAccount/AccountNumber in the target tree and right-click to bring up the context sensitive menu.

  2. Select Add XSL Node, and then if and connect PurchaseOrder/HQAccount/AccountNumber to Invoice/BilledToAccount/if.

  3. Connect PurchaseOrder/HQAccount/AccountNumber to Invoice/BilledToAccount/if/AccountNumber.

Figure 14-12 shows the results.

Figure 14-12 Conditional Processing with xsl:if

Conditional Processing
Description of "Figure 14-12 Conditional Processing with xsl:if"

14.5.5.2 Conditional Processing with xsl:choose

You can copy PurchaseOrder/HQAccount/AccountNumber to Invoice/BilledToAccount/AccountNumber, if it exists. Otherwise, copy PurchaseOrder/BranchAccount to Invoice/BilledToAccount/AccountNumber as follows:

  1. Select Invoice/BilledToAccount/AccountNumber in the target tree and right-click to bring up the context sensitive menu.

  2. Select Add XSL Node, and then choose and connect PurchaseOrder/HQAccount/AccountNumber to Invoice/BilledToAccount/choose/when to define the condition.

  3. Connect PurchaseOrder/HQAccount/AccountNumber to Invoice/BilledToAccount/choose/when/AccountNumber.

  4. Select XSL Add Node and then choose in the target tree and right-click to bring up the context sensitive menu.

  5. Select Add XSL node and then otherwise from the menu.

  6. Connect PurchaseOrder/BranchAccount/AccountNumber to Invoice/BilledToAccount/choose/otherwise/AccountNumber.

Figure 14-13 shows the results.

Figure 14-13 Conditional Processing with xsl:choose

Conditional Processing
Description of "Figure 14-13 Conditional Processing with xsl:choose"

14.5.5.3 Handling Repetition or Arrays

The XSLT Mapper allows repeating elements on the source to be copied to repeating elements on the target. For example, copy PurchaseOrder/Items/HighPriorityItems/Item to Invoice/ShippedItems/Item as follows:

  1. Select Invoice/ShippedItems/Item in the target tree and right-click to bring up the context sensitive menu.

  2. Select Add XSL Node, and then for-each and connect PurchaseOrder/Items/HighPriorityItems/Item to Invoice/ShippedItems/for-each to define the iteration.

  3. Connect PurchaseOrder/Items/HighPriorityItems/Item/ProductName to Invoice/ShippedItems/for-each/Item/ProductName.

  4. Connect PurchaseOrder/Items/HighPriorityItems/Item/Quantity to Invoice/ShippedItems/for-each/Item/Quantity.

  5. Connect PurchaseOrder/Items/HighPriorityItems/Item/USPrice to Invoice/ShippedItems/for-each/Item/PriceCharged.

Figure 14-14 shows the results.

Figure 14-14 Handling Repetition or Arrays

Handling Repetition or Arrays
Description of "Figure 14-14 Handling Repetition or Arrays"


Note:

Executing an auto map automatically inserts xsl:for-each. To see the auto map in use, drag and drop PurchaseOrder/Items/LowPriorityItems to Invoice/UnShippedItems; for-each is automatically created.

14.5.6 Automatically Mapping Nodes

Mapping nonleaf nodes starts the auto map feature. The system automatically tries to link all relevant nodes under the selected source and target. Try the auto map feature by mapping PurchaseOrder/ShipTo/Address to Invoice/ShippedTo/Address. All nodes under Address are automatically mapped, as shown in Figure 14-15.

Figure 14-15 Auto Mapping

Auto Mapping
Description of "Figure 14-15 Auto Mapping"

The behavior of the auto map can be tuned by altering the settings in JDeveloper BPEL Designer preferences or by right-clicking the transformation window and selecting Auto Map Preferences. This displays the window shown in Figure 14-16.

Figure 14-16 Auto Map Preferences

Auto Map Preferences
Description of "Figure 14-16 Auto Map Preferences"

This window enables you to customize your auto mapping as follows:

  • Invoke the automatic mapping feature, which attempts to automatically link all relevant nodes under the selected source and target. When disabled, you must individually map relevant nodes.

  • Display and review all potential source-to-target mappings detected by the XSLT Mapper, and then confirm to create them.

  • Be prompted to customize the auto map preferences before the auto map is invoked.

  • Select the Basic or Advanced method for automatically mapping source and target nodes. This enables you to customize how the XSLT mapper attempts to automatically link all relevant nodes under the selected source and target.

  • Manage your dictionaries. The XSLT Mapper uses the rules defined in a dictionary when attempting to automatically map source and target elements.


See Also:

The online Help for the Auto Map Preferences window by clicking the Help button to see a description of the fields

To see potential source mapping candidates for a target node, right-click the target node, select Show Matches, and click OK in the Auto Map Preferences window. The Auto Map window appears, as shown in Figure 14-17.

Figure 14-17 Auto Mapping Candidates

Description of Figure 14-17  follows
Description of "Figure 14-17 Auto Mapping Candidates"


See Also:

The online Help for the Auto Map window by clicking the Help button to see a description of the fields

14.5.6.1 Auto Map with Confirmation

When the Confirm Auto Map Results check box shown in Figure 14-16 is selected, a confirmation window appears. If matches are found, the potential source-to-target mappings detected by the XSLT Mapper are displayed, as shown in Figure 14-18. The window enables you to filter one or more mappings.

Figure 14-18 Auto Map with Confirmation

Auto Map with Confirmation
Description of "Figure 14-18 Auto Map with Confirmation"


See Also:

The online Help for the Auto Map window by clicking the Help button to see a description of the fields

The auto map confirmation window can also be turned on or off with Confirm Auto Map Links in the context menu of the mapper pane, as shown in Figure 14-19.

Figure 14-19 Confirm Auto Map Links Selection

Confirm Auto Map Links Selection
Description of "Figure 14-19 Confirm Auto Map Links Selection"

14.5.7 Viewing Unmapped Target Nodes

You can view a list of target nodes that are currently unmapped to source nodes. Right click in the mapper pane and select Completion Status. This window provides statistics at the bottom about the number of unmapped target nodes. This window enables you to identify and correct any unmapped nodes before you test your transformation mapping logic on the Test XSL Map window. Select a target node in the list. The node is highlighted. A check mark indicates that the target node is required to be mapped. If not required, the check box is empty.

Figure 14-20 provides an example of the Completion Status window.

Figure 14-20 Completion Status

Description of Figure 14-20  follows
Description of "Figure 14-20 Completion Status"

14.5.8 Generating Dictionaries

A dictionary is an XML file that captures the synonyms for mappings. Right-click the mapper pane as shown in Figure 14-19 and select Generate Dictionary. This prompts you for the dictionary name and the directory in which to place the dictionary. The XSLT Mapper uses the rules defined in the dictionary when attempting to automatically map source and target elements. For example, you may want to map a purchase order to a purchase order acknowledgment, then reuse most of the map definitions later.

  1. Build all the mapping logic for the purchase order and purchase order acknowledgment.

  2. Generate a dictionary for the created map.

  3. Create a new map using a different purchase order and purchase order acknowledgment.

  4. Load the previously created dictionary by selecting Preferences, then XSL Maps, then Auto Map in the Tools main menu of JDeveloper BPEL Designer.

  5. Perform an automatic mapping from the purchase order to the purchase order acknowledgment.

14.5.9 Ignoring Elements in the XSLT Document

When the XSLT Mapper encounters any elements in the XSLT document that cannot be found in the source or target schema, it is unable to process them and displays an Invalid Source Node Path error. XSL map generation fails. You can create and import a file that directs the XSLT Mapper to ignore and preserve these specific elements during XSLT parsing by selecting Preferences, then XSL Maps in the Tools main menu of JDeveloper BPEL Designer.

For example, preprocessing may create elements named myElement and myOtherElementWithNS that you want the XSLT Mapper to ignore when it creates the graphical representation of the XSLT document. You create and import a file with these elements to ignore that includes the following syntax:

<elements-to-ignore>
   <element name="myElement"/>
   <element name="myOtherElementWithNS" namespace="NS"/>
</elements-to-ignore>

You must restart JDeveloper BPEL Designer after importing the file.

14.5.10 Replacing a Schema in the XSLT Mapper

You can replace the map source schema and map target schema that currently display in the XSLT Mapper. Right click in either the source or target panel and select Replace Schema. This opens the Select Source and Target Schema window, which enables you to select the new source or target schema to use.

14.6 Testing the Map

The XSLT Mapper provides a test utility to test the style sheet or map. The test tool can be invoked by selecting the Test menu item from the mapper pane context sensitive menu, as shown in Figure 14-21.

Figure 14-21 Invoking the Test Window

Invoking the Test Dialog
Description of "Figure 14-21 Invoking the Test Window"

14.6.1 Test Window

The Open button is used to load a sample XML instance file for testing. If you do not have a source file or if you prefer the system to generate a random source instance, you can click the Generate button. After you have a sample source instance, you can generate the result document by clicking Test, as shown in Figure 14-22. This enables the Target XML section to display the target XML.


Note:

By default, the Xalan XSL processor is used for testing XSL mappings, If you want to use the Oracle XSL Processor to test mappings, select Preferences, then XSL Maps in the Tools main menu of JDeveloper BPEL Designer to change this setting in the Preferences window.

14.6.2 Generating Reports

You can generate an HTML report with the following information:

  • XSL map file name, source and target schema file names, their root element names, and their root element namespaces

  • Target document mappings

  • Target fields not mapped (including mandatory fields)

  • Sample transformation map execution

To generate a report, right-click the transformation window and select Generate Report. The Generate Report window appears in the transformation window, as shown in Figure 14-23.

Figure 14-23 The Generate Report Window

Description of Figure 14-23  follows
Description of "Figure 14-23 The Generate Report Window"


See Also:

The online Help for the Generate Report window by clicking the Help button to see detailed information

14.6.2.1 Correcting Memory Errors When Generating Reports

If you attempt to generate a report and receive an out-of-memory error, increase the heap size of the JVM as follows:

  1. Open the Oracle_Home\integration\jdev\jdev\bin\jdev.conf file.

  2. Go to the following section:

    # Set the maximum heap to 512M
    #
    AddVMOption     -Xmx512M
    
    
  3. Increase the size of the heap as follows (for example, to 1024)

    AddVMOption     -Xmx1024M
    
    

In addition, you can also uncheck the Open Report option on the Generate Report window before generating the report.

14.6.3 Sample XML Generation

You can customize sample XML generation by specifying the following parameters. Select Preferences, then XSL Maps in the Tools main menu of JDeveloper BPEL Designer to display the Preferences window.

  • Number of repeating elements

    Specifies how many occurrences of an element are created if the element has the attribute maxOccurs set to a value greater than 1. If the specified value is greater than the value of the maxOccurs attribute for a particular element, the number of occurrences created for that particular element is the maxOccurs value, not the specified number.

  • Generate optional elements

    If selected, any optional element (its attribute minOccurs set to a value of 0) is generated the same way as any required element (its attribute minOccurs set to a value greater than 0).

  • Maximum depth

    To avoid the occurrence of recursion in sample XML generation caused by optional elements, specify a maximum depth in the XML document hierarchy tree beyond which no optional elements are generated.

14.7 Summary

This chapter describes features of the XSLT Mapper, such as:

This chapter shows these features by providing step-by-step instructions for mapping a sample purchase order schema to an invoice schema.