What is the purpose of the XPathContext (in extension functions)
Added by Michael Staal-Olsen over 4 years ago
My current Java based project incorporates the use of your Integrated Extension Functions. The interface (as specified by you) make it so that one has to make a call method with two arguments: One being an XPathContext, the other being an array of Sequences.
Currently, all of our functions only use the array of Sequences parameter. And I have yet to see an example where the XPathContext is used. Can you share some perspectives as to how this can be used, just so that I know if we are missing some opportunities. Can it be used to retrieve the original XPath expression given to the function?
Replies (1)
RE: What is the purpose of the XPathContext (in extension functions) - Added by Michael Kay over 4 years ago
The availability of the XPathContext argument enables you to write functions that access the XPath dynamic context in the same way that standard functions do: for example, as well as writing a function path-to-node($N as node())
which takes a node as argument, you could also write a version with no arguments that applies the function to the context node.
The context also gives you access to the Saxon configuration, so you can make the behaviour of your function dependent on configuration settings.
If you don't need any of this then you might consider using the much simpler s9api interface net.sf.saxon.s9api.ExtensionFunction
.
The static context of the function call is not made available, neither is the expression containing the function call.
Please register to reply