20 Transforming Data with XSLT

This chapter provides an overview of eXtensible Stylesheet Language Transformation (XSLT) and how it is used in Service Bus services to map XML input to XML output. It also describes how to create XSLT maps in Service Bus projects.

This chapter includes the following sections:

For more in-depth information about the XSLT mapper in JDeveloper, see "Creating Transformations with the XSLT Map Editor" in Developing SOA Applications with Oracle SOA Suite.

20.1 Introduction to XSLT

Transformation maps describe the mapping between two data types. eXtensible Stylesheet Language Transformation (XSLT) maps describe mappings between XML documents with different schemas. Using XSLT, Service Bus can process XML documents and transform document data from one XML schema to another, enabling data interchange among applications that use different schemas. You can perform complex data manipulation and transformation using XSLT. For example, you can map an incoming purchase order schema to an outgoing invoice schema.

20.2 XSLT Editors and Mappers

JDeveloper provides both an Expression Builder, where you can script transformations using XQuery, and an XSLT Mapper, where you can create complex mappings. The Oracle Service Bus Console provides an editor for scripting transformations using XQuery. These editors provide options to define an XQuery expression, to specify an XSLT resource to execute, or to define an expression that evaluates at runtime to the name of an existing XSLT resource. For both JDeveloper and the console, you access the editors from an action in either a pipeline or split-join.

20.2.1 JDeveloper Editors and Mappers

The XSLT mapper in JDeveloper is a graphical tool that lets you define mappings between schema root elements, WSDL message parts, or WSDL messages. Schema root elements can come from XSD schema files or WSDL files, but only those WSDL messages that contain a single message part can be mapped directly. Once you create an XSLT mapping in JDeveloper, you can upload the .xsl file generated by the mapper to an XSLT resource in the Oracle Service Bus Console.

JDeveloper also includes a variety of Expression Builders, where you can create expressions that specify an existing XSLT resource to use. For more information about the mapper and editors in JDeveloper, see the following topics:

20.2.2 Oracle Service Bus Console Editors

In the Oracle Service Bus Console, the XQuery/XSLT Expression Editor lets you create expressions that specify an existing XSLT resource to use. Before you can reference an XSLT resource, you need to create the resource in the console and upload an existing XSL transformation to the resource. This feature allows you to create complex mappings in JDeveloper that you can then import and use in the console. You can reuse an XSL transformation in multiple pipelines and split-joins.

For information about the XQuery/XSLT Editor in the Oracle Service Bus Console, see Working With Expression Editors in Oracle Service Bus Console.

20.3 Creating XSLT Mappings in JDeveloper

You can create XSLT mappings in a Service Bus project in JDeveloper, and then use them in XQuery expressions in pipelines and split-joins to map objects between external systems.

20.3.1 How to Create XSLT Mappings in JDeveloper

When you create an XSLT mapping, you need to select the source XML schema elements or XML files to use for the source and target mappings.

To create an XSLT mapping in JDeveloper:

  1. In the Application Navigator in JDeveloper, right-click the Service Bus project or folder in which you want to create the mapping.

  2. In the menu that appears, point to New and select XSL Map.

    The Create XSL Map File dialog appears.

  3. In the File Name field, enter a unique name for the XSLT map file.

  4. Optionally enter a new directory location and a brief description for the cross reference.

    The location must be within the directory structure of the current application.

  5. To define the source schema, do the following:

    1. Select Use Source Schema.

    2. Click Browse next to the Primary Source field.

    3. On the Select Schema dialog, select whether to use an XML schema or to generate the source directly from an XML file.

    4. Click Browse in the section you chose above to navigate to and select the XML schema element or file to use.

      You can select an XML schema element from the current application. You can select an XML file from the file system.

    5. When you have selected the schema element or file, click OK on the Select Schema dialog.

    6. To select additional sources to use as parameters, click Add Schema above the Additional Sources table.

  6. To define the target schema, select Use target schema, and repeat the above steps on the Select Schema dialog to select the XML components to use.

  7. Click OK on the Create XSL Map File dialog.

    The XSLT Mapper appears with the source and target structures displayed.

  8. To define the mapping logic, see "Editing an XSLT Map in Map Mode" in Developing SOA Applications with Oracle SOA Suite.

20.4 Working with XSLT Resources in the Oracle Service Bus Console

In the Oracle Service Bus Console, XSLT maps are stored in XSLT resources, which can be reused in any pipelines and split-joins in the current session. You can upload existing XSLT maps into the XSLT resources, and use a text editor to edit them.

20.4.1 How to Create XSLT Resources in the Console

If you are using the Oracle Service Bus Console, you can add XSL transformations that you first create in JDeveloper and that you then import into a Service Bus project or upload into an XSL transformation resource. For information on importing, see Importing and Exporting Resources and Configurations . Use the procedure below to upload a mapping file into an XSL transformation resource.

Before you Begin

Create the XSL transformation mapping file as described in Creating XSLT Mappings in JDeveloper.

To create an XSLT resource in the console:

  1. In the Project Navigator, right-click the project or folder to contain the new XSL transformation, point to Create, and select XSLT.

    The Create Schema dialog appears.

  2. Do one of the following:

    • To create the resource from an existing XSL mapping file, click Browse next to the File Upload field and then navigate to and select the file you created in JDeveloper.

      The Resource Name field is automatically populated with the file name minus the file extension. You can change this name.

    • To create a new XSL transformation, enter a unique name for the transformation resource.

  3. Optionally, enter a brief description of the resource.

  4. Click Create.

    The XSLT parameters, if defined, appear in the XSLT Definition Editor.

  5. To modify the schema, do the following:

    1. Click Edit Source in the toolbar.

      The Edit Source dialog appears.

    2. To browse to and select a new mapping file to upload, click Browse.

    3. To modify the contents of the file, update the code directly in the Contents section of the dialog.

    4. Click Save.

  6. In the XSLT Definition Editor toolbar, click Save.

  7. To end the session and deploy the configuration to the runtime, click Activate.

20.4.2 How to Edit XSLT Resources in the Console

The Oracle Service Bus Console lets you edit an XSLT resource directly or update the contents by uploading a new or updated file.

To edit an XSL transformation in the console:

  1. In the Project Navigator, expand the project and folders containing the XSL transformation to edit.
  2. Right-click the XSL transformation name, and select Open.
  3. Click Edit Source in the toolbar.

    The Edit Source dialog appears.

  4. To browse to and select a new XSL transformation file to upload, click Browse.
  5. To modify the contents of the file, update the code directly in the Contents section of the dialog.
  6. Click Save.
  7. In the XSLT Definition Editor toolbar, click Save.
  8. To end the session and deploy the configuration to the runtime, click Activate.

20.5 How to Delete an XSLT Resource

If any resources reference the XSLT resource you want to delete, remove those references before deleting the resource. In the Oracle Service Bus Console, open the XSLT resource in the XSLT Definition Editor and click the References icon in the upper right to find out whether it has any references. In JDeveloper, right-click the XSLT resource and select Explore Dependencies.

You can delete the transformation even if it is referenced by other resources, though this might result in conflicts due to unresolved references to the deleted resource.

To delete an XSLT resource:

  1. In the Application Navigator or Project Navigator, expand the project and folders containing the XSL transformation to delete.
  2. Right-click the name of the transformation, and select Delete.
  3. If you are using JDeveloper, a confirmation dialog displays the number of references for the transformation. Click Show Usages to view information about the references, and then click Yes to confirm that you want to delete the resource.
  4. If you are using the Oracle Service Bus Console, click Activate to end the session and deploy the configuration to the runtime.