Novell is now a part of Micro Focus

Calling a Java Program from an XPath Expression

Novell Cool Solutions: Tip
By Perin Blanchard

Digg This - Slashdot This

Posted: 17 Aug 2005


A reader asked:

"What is the syntax for calling a Java program from an XPath expression? I'd like to call it and set the return value to a local variable.

And here's the response from Novell's Perin Blanchard ...


A namespace must be declared with the following form:


So, to use the java.lang.String class, the declaration could be as follows:


Using Policy Builder, click on the "Edit namespaces" button and enter the prefix in the "Name" field, and the name of the class in the "URL" field. Policy Builder will then create a namespace of the correct form for you in your policy definition.

(If you are using XSLT, just declare the namespace as above.)

Then, in the XPath expression, use the prefix and the name of the method (New is a special case that means constructor):

jstring:new('this is a string')

An instance method is called like this:

jstring:indexOf($, 'something')

A static method is called the same way, but without the instance being passed as the first parameter.

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© Copyright Micro Focus or one of its affiliates