Using xalan:evaluate to ‘parameterize’ XPATH

This is in reference to this OTN post.The poster there had the below XML:


<?xml version="1.0" encoding="ISO-8859-1"?>
 <catalog>
 <cd>
 <title>Empire Burlesque</title>
 <artist>Bob Dylan</artist>
 <country>USA</country>
 <company>Columbia</company>
 <price>10.90</price>
 <year>1985</year>
 </cd>
 </catalog>

And he wanted to extract the value of /catalog/cd/title. The problem is that this xpath needs to be parameterized and not hardcoded, which means it requires dynamic XPATH evaluation. This can be done in OSB using a XSLT transformation leveraging  xalan:evaluate.

First lets create the xslt for doing this:


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan">

<xsl:param name="xpath"/>

<xsl:template match="/">
<XalanResult> <xsl:value-of select="xalan:evaluate($xpath)"/></XalanResult>

</xsl:template>

</xsl:stylesheet>

Register this as a XSLT resource in OSB. Next create a proxy service to test this XSLT.
We will use a ASSIGN action to test this. This action just assigns the result of XSLT to the xalanEvaluationResult variable.

We configure it to pass content of $body as source input. The second parameter is the string representation of the Xpath we want to apply on the source XML.
Click the test button to test this.

For $body we pass the xml in that post.

The test result shows XSLT function applying the ‘parameterised’ xpath on the source xml and returning the result.

Advertisements

About atheek

I am a Weblogic consultant working in Middleware/Integration area.
This entry was posted in OSB, XSLT and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s