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 |
Testing the POC in Oracle Enterprise Manager |
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:
- Oracle SOA Suite on Oracle Technology Network
- XSL Transformations (XSLT) Version 1.0: http://www.w3.org/TR/xslt/
- XML Path Language (XPath) Version 1.0: http://www.w3.org/TR/xpath
- Download this POC
No comments:
Post a Comment