You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Dirk Reinshagen_C <DR...@zaplet.com> on 2001/02/03 01:28:07 UTC

Nested XPath expressions

It's possible this is a FAQ, but I'm unable to find an answer in the various
docs. on
xml.apache.org, so here it goes....

I'm trying to invoke a java method from within Xalan-j Xpath expression.
I've included the 
"java" namespace in the XML document and can successfully call a method.
The problem 
I'm encountering is passing an evaluated XPath expression to Java method.
I've tried several
different variations, including calling the "evaluate" method which seems
like it should produce
the expected result, but I'm never able to see the evaluated XPath in the
method (other than
when passing a literal string).  I'm using Xalan 2.0 D07 with JDK 1.3. 


Class Test {
...
src removed
...

      public void testXPath (Node node) {
	System.out.println("java eval: \n" + evalXPath(node,
"java:Test.fooMethod(./to/text()) = 'mydes'"));
	System.out.println("java eval: \n" + evalXPath(node,
"java:Test.fooMethod(string(./to/text())) = 'mydes'"));
	System.out.println("java eval: \n" + evalXPath(node,
"java:Test.fooMethod(java:org.apache.xalan.lib.Extensions.evaluate('./to/tex
t()')) = 'mydes'"));
    }

    public static String fooMethod(String param) {
System.out.println("received in fooMethod: " + param);
	return "mydes";
   }

    public static boolean evalXPath(Node root, String xpathExp) {
        try {
 	XObject xobj = XPathAPI.eval(root, xpathExp);
	if (xobj instanceof XBoolean) {
		return xobj.bool();
	}
        }
        catch (Throwable t) {
System.out.println("error " + t);
	t.printStackTrace();
	return false;
       }
       return false;
   }
}