Project

Profile

Help

Value of xsl variable in extension function

Added by Anonymous about 18 years ago

Legacy ID: #3556841 Legacy Poster: Eric Reynolds (ehremo)

Hello, I am writing an extension function in which I would like to get the value of declared xsl variables by their name. E.g. String variableName = "exec"; Object variableValue = getVariableValue ("exec"); Is this possible? I cannot figure out how to do it. The reason I want this is that my function takes a query expression as a string like "{{$exec.name}/blah}" and I would like users to be able to refer to variables in these queries in an uncumbersome way.


Replies (1)

RE: Value of xsl variable in extension functi - Added by Anonymous about 18 years ago

Legacy ID: #3556890 Legacy Poster: Michael Kay (mhkay)

This is quite tricky to achieve, which is why saxon:evaluate() doesn't do it: it allows you only to refer to variables $p1 to $p9 which you have to pass as separate parameters. Doing it properly means that you have to know something about the static context of the expression as well as the dynamic context (for example, you need to know the namespace prefixes in scope), and Saxon doesn't make static context information available to user-written extension functions. However, the information as to what local variables and global variables are in scope is now available dynamically, and reachable via the XPathContext object that can be passed as an optional parameter to extension functions (this is how the debuggers are able to display variable values). You'll just have to scout around the JavaDoc (and probably the source code) to see how to get there!

    (1-1/1)

    Please register to reply