Project

Profile

Help

problem with EarlyEvaluationContext

Added by Joern Turner over 4 years ago

I'm trying to implement an XForms function lib and i'm using the approach to extend BuiltInFunctionSet which i can successfully use with my evaluator.

Having two functions - one works the other not. Main problem is that while one function gets an XPathContextMajor when the function is called the other gets an EarlyEvaluationContext where the subobject Controller (just having Configuration) is missing. I cannot see why this happens.

However my function relies on passing a userobject as context via

 context.getXPathContextObject().getController().setUserData

before evaluating and accessing that object within the function to resolve between different DOM documents in this case. I've attached my barebone functionlib - the instance function is the one that fails due to the missing object in the evaluation context.

So this question is related to https://saxonica.plan.io/boards/3/topics/6087?r=6090#message-6090

I haven't quite understood which are the mechanisms which determine which kind of EvaluationContext is passed to the function. Is there any way i can influence this?

Thanks a lot,

Joern


Replies (2)

RE: problem with EarlyEvaluationContext - Added by Joern Turner over 4 years ago

have found it myself in that minute:

by calling register function with properties value of CITEM (context item) i now get the XPathContextMajor.

RE: problem with EarlyEvaluationContext - Added by Michael Kay over 4 years ago

An EarlyEvaluationContext is used if Saxon decides that the function can be executed at compile time. There are two main preconditions for that: the argument values must all be known at compile time, and the function must have no dependencies on the dynamic context. By declaring the function to have a dependency on the context item, you force run-time evaluation.

EarlyEvaluationContext is a kind of "dummy" context for functions that don't need actual dynamic context information.

Note that by using Controller.setUserData() you're making your code dependent on order of evaluation; take particular care, for example, if your code is executed within the scope of xsl:result-document, which in Saxon-EE is executed asynchronously. You may want to set the configuration flag that disables multi-threading.

    (1-2/2)

    Please register to reply