Tuesday, March 31, 2015

Node selection of Oracle's XSLT engine

Oracle Busisness Process Management Suite and Oracle SOA Suite enable XML Stylesheet Transformations (XSLT). The XSLT engine is part of the mediator component engine, which is indeed the former enterprise service bus (ESB) implementation of Oracle before Oracle Service Bus (OSB) was bought.
For implementation purpose, it is sometimes useful to know exactly the node selection behavior of the XSLT engine. In most cases, XSLT relies on XML Path Language (XPath) node selection mechanisms. But what happens, if the expression would match more then one node? Well, let's try!

The POC is quiet simple. A synchornous BPEL process exposing a SOAP web service interface accepts a list of animals as request.

SCA Composite of the POC

For the response, a list of the first, last and XPath node-selected animal will be returned.

XML Schema definition of request and response of the SOAP web service endpoint

The BPEL process itself is quiet simple: Received input data from the input variable are transformed to the output variable to be returned to the requester.

BPEL Process "SortMyAnimals"


The XSL Transformation uses XPath expression to map the first animal of the input list (/request/animals/animal[1]), the last animal of the input list (/request/animals/animal[last()]) and the animal that is selected by the XSLT engine we are actually interested in (/request/animals/animal) ... since we did not define its position in the list.

  <xsl:template match="/">
    <ns1:response>
      <ns1:firstanimal>
        <xsl:value-of select="/ns1:request/ns1:animals/ns1:animal[1]"/>
      </ns1:firstanimal>
      <ns1:lastanimal>
        <xsl:value-of select="/ns1:request/ns1:animals/ns1:animal[last()]"/>
      </ns1:lastanimal>
      <ns1:nodeselectedanimal>
        <xsl:value-of select="/ns1:request/ns1:animals/ns1:animal"/>
      </ns1:nodeselectedanimal>
    </ns1:response>
  </xsl:template>


For a sample input of three animals cat, dog and cow (in that order), the XSLT tester in JDeveloper returns the cat, that means the first element that is matching the XPath expression.

Local testing in JDeveloper using XSLT tester
After deployment of the POC to our environment, we will run the same example to proof what we found out.

Testing the POC in Oracle Enterprise Manager
 And yes, the result is the same:

Testing result in Oracle Enterprise Manager

Summery: Not specifying the exact node in an XPath expression in an XSL Stylesheet Transformation will return the first node matching the path criteria.

References:

No comments:

Post a Comment