RE: [xsl] XPath in Java Q?

Subject: RE: [xsl] XPath in Java Q?
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Thu, 13 Dec 2001 22:26:21 -0000
> I am not sure if this is the right place for this post, but
> anyway I would
> like to ask if there is a way how to query xml document in
> Java using XPath
> (e.g. some free library etc.).
>
Quite a few products offer this capability.

You can do it in Saxon, though it's perhaps a little bit cumbersome:

Expression exp = Expression.make("2+2", new StaticContext());
Context cxt = ((Controller)transformer.newContext();
System.err.println(exp.evaluateAsString(cxt));

will output "4".

The "transformer" is obtained from JAXP in the normal way. Really, this is
intended primarily for use within XSLT extension functions, where the
"context" object will be supplied in the calling parameters. But you can
also use it in a freestanding application, as illustrated in the
ShowBooks.java sample application issued with the product.

Saxon's XPath processor will run against Saxon's own internal tree format,
or against a JDOM tree. It won't run against a third-party DOM, unless you
do a lot of interfacing work.

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread