Tuesday, August 18, 2020

XSLT Overview (SOA/BPM)

 

XSLT (Extensible Stylesheet Language Transformations)

XSLT transforms an XML document into another XML document.

The XSLT Mapper enables you to create data transformations between source schema elements and target schema elements in either Oracle BPEL Process Manager or Oracle Mediator.

- Transformation Language

- XML as Input and Output

- Declarative Language

- XPath for Navigation

- Template-Based Transformation

- XSL Stylesheets

- Conditional Logic

- Iteration and Loops

- Built-in Functions

- Widely Used

While in design view, the following pages from the Component Palette can be used:

·         General: Commonly used XPath functions and XSLT constructs.

·         Advanced: More advanced XPath functions such as database and cross-reference functions.

·         User-Defined: User-defined functions and templates. This page is visible only when the user has templates in their XSL or user-defined external functions defined through the preferences pages.

·         All Pages: Provides a view of all functions in one page.

·         My Components: Contains user favorites and recently-used functions. To add a function to your favorites, right-click the function in the Component Palette and select Add to Favorites.

Note:

The following functions are available with Oracle Mediator and Oracle BPEL Process Manager, in the XSLT Mapper.

  • getProperty(propertyName as string)
  • setCompositeInstanceTitle(titleElement)
  • getComponentInstanceID()
  • getComponentName()
  • getCompositeInstanceID()
  • getCompositeName()
  • getECID()

For Oracle BPEL Process Manager, you can use these functions in an assign activity.

How to Set Constant Values

To set constant values:

<ProductName>ABC</ProductName>

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.

A menu provides the following selections:

o    <Empty>: Enables you to create an empty node.

o    Enter Text: Enables you to enter text.

4.    Select Enter Text.

The Set Text dialog appears.

5.    In the Set Text dialog, enter text

6.    Click OK to save the text.

A T icon is displayed next to the node that has text associated with it. The beginning of the text that is entered is shown next to the node name.

7.    To modify the text associated with the node, right-click the node and select Edit Text to invoke the Set Text dialog again.

8.    Edit the contents and click OK.

9.    To remove the text associated with the node, right-click the node and select Remove Text.

How to Add Functions

The XSLT Mapper provides many prebuilt extension functions and can support user-defined functions and named templates.

The extension functions are prefixed with oraext or orcl and mimic XPath 2.0 functions.

To add functions:

  1. From the Component Palette, select a category of functions (for example, String Functions).
  2. Right-click an individual function (for example, lower-case).
  3. Select Help. A dialog with a description of the function appears.
  4. Drag a function from the Component Palette to the center panel of the XSLT Mapper. You can then connect the source parameters from the source tree to the function and the output of the function to a node in the target tree.

XSLT Constructs – if, for-each,choose

To add XSLT constructs through the context menu on the target tree:
Right-click the element in the target tree where you want to insert an XSLT construct. A context menu is displayed
Select Add XSL Node and then the XSLT construct you want to insert.

xsl:if

When mapping an optional source node to an optional target node, it is important to surround the mapping with a xsl:if statement that tests for the existence of the source node. If this is not done and the source node does not exist in the input document, an empty node is created in the target document.

Note:

If these fields are optional in the source and target, it is a good practice to insert an xsl:if statement around these mappings to test for the existence of the source node.

If this is not done, and the source node does not exist in the input document, an empty node is created in the target document. For example, if ProductName is optional in both the source and target, map them as follows: 

<xsl:if test="ProductName">

    <ProductName>

      <xsl:value-of select="ProductName"/>

    </ProductName>

</xsl:if>

xsl:choose

It contain when & otherwise (like if else)

you can copy PurchaseOrder/HQAccount/AccountNumber to Invoice/BilledToAccount/AccountNumber, if it exists. Otherwise, copy PurchaseOrder/BranchAccount to Invoice/BilledToAccount/AccountNumber.

To use conditional processing with xsl:choose:

  1. In the target tree, select Invoice/BilledToAccount/AccountNumber and right-click to invoke the context sensitive menu.
  2. Select Add XSL Node > choose from the menu.
  3. Connect PurchaseOrder/HQAccount/AccountNumber to Invoice/BilledToAccount/choose/when to define the condition.
  4. Connect PurchaseOrder/HQAccount/AccountNumber to Invoice/BilledToAccount/choose/when/AccountNumber.
  5. In the target tree, select XSL Add Node > choose and right-click to invoke the context sensitive menu.
  6. Select Add XSL node > otherwise from the menu.
  7. Connect PurchaseOrder/BranchAccount/AccountNumber to Invoice/BilledToAccount/choose/otherwise/AccountNumber.

xsl:for-each

<xsl:for-each select=””>

Selecting a tag itself

<xsl:value-of select=””/>

Selecting the actual content inside of tag.

How to Search Source and Target Nodes 

To search source and target nodes: 

1.    Right-click a source or target node and select Find from the context menu.

2.    Enter a keyword for which to search.

3.    Specify additional details, as necessary. For example:

a.    Select Search Annotations if you want annotations text to also be searched.

b.    Specify the scope of the search. You can search the entire source or target tree, search starting from a selected position, or search within a selected sub-tree.

4.    The first match found is highlighted, and the Find dialog closes. If no matches are found, a message displays on-screen.

5.    Select the F3 key to find the next match in the direction specified. To search in the opposite direction, select the Shift and F3 keys.

Note: You cannot search on functions or text values set with the Set Text option.

No comments:

Post a Comment

SOA Overview Part-1

  Middleware It provides a mechanism for the process to interact with other processes running on multiple network machines. Advantages...