XPATH Extension functions supported ?
Added by Anonymous almost 20 years ago
Legacy ID: #2869510 Legacy Poster: sid (siddharth_c)
hi I am a newbie to saxon and I had a query regarding its capabilities.I know and have a working example for an extension function which I am using ina xslt stylsheet. I was wondering if I could use the same extension function in xpath expression outside a stylsheet. See code snippet below : InputSource is = new InputSource(new File(filename).toURL().toString()); SAXSource ss = new SAXSource(is); XPathEvaluator xpe = new XPathEvaluator(ss); XPathExpression extension = xpe.createExpression("x:reverse("hello1")"); I use the same reverse function ina stylsheet and it works like a charm but when i try to use it in xpath thru java code it gives me an error given below Exception in thread "main" net.sf.saxon.xpath.XPathException$Static: XPath synta x error in {x:reverse("hello1")}: Prefix x has not been declared at net.sf.saxon.expr.ExpressionParser.grumble(ExpressionParser.java:99) Note that my top level xml root element has the prefix defined as <BOOKLIST xsi:noNamespaceSchemaLocation="books.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="java:test.XPathExtension"> I also tried an alternative way by setting a NodeContext and giving it a NamespaceNode, but that did not work either. Am I missing something ? Any help would be appreciated. thanks.
Replies (5)
Please register to reply
RE: XPATH Extension functions supported ? - Added by Anonymous almost 20 years ago
Legacy ID: #2869579 Legacy Poster: Michael Kay (mhkay)
The XPathEvaluator gets the static context from a StandaloneContext object, which has a declareNamespace method allowing you to associate the namespace used in your function call with a suitable URI. So you can do xpe.getStaticContext().declareNamespace("prefix", "uri") Saxon 8.2 will include support for the XPath API defined in JAXP 1.3, alongside the existing API. Michael Kay
RE: XPATH Extension functions supported ? - Added by Anonymous almost 20 years ago
Legacy ID: #2870148 Legacy Poster: sid (siddharth_c)
hi I am using saxon8B and in that there is no such method for the StaticContext. see trace below : XPathExample.java:74: cannot resolve symbol symbol : method declareNamespace (java.lang.String,java.lang.String) Any other way around ? thanks
RE: XPATH Extension functions supported ? - Added by Anonymous almost 20 years ago
Legacy ID: #2870157 Legacy Poster: sid (siddharth_c)
Sorry for the hurried previous post. StandAloneContext is a child of StaticContext and that has the required method. Everything works ! thanks a lot.
RE: XPATH Extension functions supported ? - Added by Anonymous almost 20 years ago
Legacy ID: #2870162 Legacy Poster: Michael Kay (mhkay)
I don't know what you're doing wrong. The methods I referred to, XPathEvaluator.getStaticContext and StandaloneContext.declareNamespace, have been in the product for many releases. Michael Kay
RE: XPATH Extension functions supported ? - Added by Anonymous almost 20 years ago
Legacy ID: #2879209 Legacy Poster: sid (siddharth_c)
Everything works. My previous posts got reordered incorrectly(see timestamp), so you felt I still had a problem. thanks
Please register to reply