Providing additional information to an extension function

View: New views
3 Messages — Rating Filter:   Alert me  

Providing additional information to an extension function

by Norman Walsh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Mike,

In Saxon 9.1, I created a FunctionLibrary for each context where I wanted
to evaluate XPath expressions and assigned that library to the evaluator.
In Saxon 9.2, it appears that functions can only be registered globally.

How can pass additional application-specific context to the extension
function?

For example, I need to implement p:step-available which answers the
question "is this step available". The answer to that question depends
on the step in which it's called.

                                        Be seeing you,
                                          norm

--
Norman Walsh <ndw@...> | Clearness is so eminently one of the
http://nwalsh.com/            | characteristics of truth that often it
                              | even passes for truth itself.-- Joubert


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

attachment0 (191 bytes) Download Attachment

Re: Providing additional information to an extension function

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Here's one approach.

Let's suppose you have a Pipeline object with a method currentStep().

When you instantiate your ExtensionFunctionDefinition class, you pass the
Pipeline object to its constructor. When Saxon calls its
makeCallExpression() method, you pass the Pipeline object to the
ExtensionFunctionCall object. Then when the call() method of the
ExtensionFunctionCall object is called, it can get information by calling
currentStep() on the Pipeline object.

Here's another approach: use setUserData()/getUserData() in the Saxon
Controller. You can set this data before running a transformation, and you
can access it from the extension function call() method using
context.getController().getUserData().

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

> -----Original Message-----
> From: Norman Walsh [mailto:ndw@...]
> Sent: 18 October 2009 14:26
> To: saxon-help@...
> Subject: [saxon] Providing additional information to an
> extension function
>
> Hi Mike,
>
> In Saxon 9.1, I created a FunctionLibrary for each context
> where I wanted to evaluate XPath expressions and assigned
> that library to the evaluator.
> In Saxon 9.2, it appears that functions can only be
> registered globally.
>
> How can pass additional application-specific context to the
> extension function?
>
> For example, I need to implement p:step-available which
> answers the question "is this step available". The answer to
> that question depends on the step in which it's called.
>
>                                         Be seeing you,
>                                           norm
>
> --
> Norman Walsh <ndw@...> | Clearness is so eminently one of the
> http://nwalsh.com/            | characteristics of truth that often it
>                               | even passes for truth
> itself.-- Joubert
>


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: Providing additional information to an extension function

by Norman Walsh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Michael Kay" <mike@...> writes:
> When you instantiate your ExtensionFunctionDefinition class, you pass the
> Pipeline object to its constructor. When Saxon calls its
> makeCallExpression() method, you pass the Pipeline object to the
> ExtensionFunctionCall object. Then when the call() method of the
> ExtensionFunctionCall object is called, it can get information by calling
> currentStep() on the Pipeline object.

Perhaps I've misunderstood the intended use of the definition class. It
appears to me that I'm expected to register the extension functions once,
on the processor.

In that world, I don't have a handle on a single Pipeline object which
can answer the question "what is the current step?" I suppose I could,
but looking forward to some future where I allow multiple threads to
run, I think that could get tricky.

> Here's another approach: use setUserData()/getUserData() in the Saxon
> Controller. You can set this data before running a transformation, and you
> can access it from the extension function call() method using
> context.getController().getUserData().

Ah. I thought there was one of these, but I guess I wasn't looking in the
right place. I think I can make this work. It may be a bit messy, but...

Thanks!

                                        Be seeing you,
                                          norm

--
Norman Walsh <ndw@...> | When someone tells you something defies
http://nwalsh.com/            | description, you can be pretty sure
                              | he's going to have a go at it
                              | anyway.--Clyde B. Aster


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

attachment0 (191 bytes) Download Attachment