If you base your design around the ExtensionInstruction and SimpleExpression classes, then Saxon will evaluate the expression for you and pass the result to your call() method; for this to work the compile() phase of your ExtensionInstruction needs to create the instance of SimpleExpression and call setArguments() passing the relevant expression as one of the arguments; when the call() method is invoked, the corresponding expression will have been evaluated.

You're on the right lines, but as you've probably found there isn't much documentation in this area and you have to use some pretty low-level interfaces. Apart from suggesting that you follow the pattern of the extension instructions impemented for the SQL extension, I can't offer that much guidance. It would probably be a good idea to become sufficiently familiar with the Saxon source code that you can step through things in a debugger to see what is going on.

Michael Kay

On 8 Feb 2014, at 07:13, sky Chen <sky.freeprisoner@gmail.com> wrote:

Sorry, my question is a bit confusing. Let me explain:

I have created an Extension Element(extending ExtensionInstruction), in java, which has a "selectStr" attribute that takes an XPath(like xsl:value-of does). I want to know if my Extension Element code needs to take care of evaluating the XPath being passed in or if this evaluation is taken care of by Saxon before I receive attribute value. And if I do need to evaluate it myself, how?

After some look at Doc, I think I may need do this:
Expression compiledExpression = makeExpression( getAttributeValue("", "selectStr") );

compile(Executable exec, Declaration decl)
return new TextInstruction(compiledExpression);

private class TextInstruction extends SimpleExpression
public String call(XPathContext context, Sequence[] arguments)
return arguments[compiledExpression].head().evaluateAsString(context);

is it the right approach?
Thanks in advance


On Sat, Feb 8, 2014 at 12:38 AM, sky Chen <sky.freeprisoner@gmail.com> wrote:
Hi, I want to evaluate XPath string supplied through element attribute in extension instruction(Java). How can I pass current context(e.g. static|dynamic context, namespace) to XPathEvaluator? I'm new to Saxon and XSLT, probably this is just a silly question. Currently my code looks like:
private static doSelect(
XPathContext context,
String selectStr)
String nodeText = "";
XPathEvaluator evaluator = new XPathEvaluator();
nodeText = evaluator.evaluate(selectStr, context.getContextItem);

Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
saxon-help mailing list archived at http://saxon.markmail.org/