I’m using java and saxon processor.
Let say I have some XPath expression with possible variable refs in it. I also have some custom xpath functions which can be nested to arbitrary depth which can have variable refs as parameters. So xpath expression is pretty complex.
I’d like to extract prefix and localname for every variable ref in xpath expression without evaluating it.
I can extract it by setting some custom XPathVariableResolver to my xpath and by evaluating it. But this can make pretty overhead as I only want variable refs to extract, not to call custom functions which can be time consuming.
Is it safe to do it just by some pattern matching with ‘$’ sign?
Probably some API call for this would be great. Or if no API call is available, then which cases I should avoid with ‘$’ sign (probably it can be located as string and I need to avoid taking that one).
Use the s9api XPathCompiler class to compile the expression:
The external variables in the expression are then available by calling:
By the way, it’s hit and miss whether Saxon questions get noticed here. If you want to be sure of an answer, use the Saxon forum at http://saxonica.plan.io/