Setting the context position?

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

Setting the context position?

by Norman Walsh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I thought I had code that did this, but maybe it was with the Saxon 6 APIs,
or the pre-s9api APIs, or maybe I'm just confused.

I can set the context item on an XPathSelector before I evaluate it, can
I also set the context position and size?

In this particular case, I'm walking over a (virtual) sequence of
documents that I'm reading and I want to make position() reflect the
position in that sequence.

                                        Be seeing you,
                                          norm

--
Norman Walsh <ndw@...> | Never doubt that a small group of
http://nwalsh.com/            | thoughtful, committed citizens can
                              | change the world. Indeed, it's the only
                              | thing that ever has.--Margaret Mead


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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: Setting the context position?

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At the level of the XPathContext object, you can call
context.setCurrentIterator() supplying a SequenceIterator; the methods
current() and position() on that SequenceIterator provide the context item
and context position, and if the SequenceIterator is a LastPositionFinder
then its getLastPosition() method provides the value of the context size.

There's no equivalent to this in any higher-level APIs. There's also no way
of drilling down from the XPathSelector to access the XPathContext object
directly.

Michael Kay
 

> -----Original Message-----
> From: saxon-help-bounces@...
> [mailto:saxon-help-bounces@...] On Behalf
> Of Norman Walsh
> Sent: 22 July 2008 20:20
> To: saxon-help@...
> Subject: [saxon] Setting the context position?
>
> I thought I had code that did this, but maybe it was with the
> Saxon 6 APIs, or the pre-s9api APIs, or maybe I'm just confused.
>
> I can set the context item on an XPathSelector before I
> evaluate it, can I also set the context position and size?
>
> In this particular case, I'm walking over a (virtual)
> sequence of documents that I'm reading and I want to make
> position() reflect the position in that sequence.
>
>                                         Be seeing you,
>                                           norm
>
> --
> Norman Walsh <ndw@...> | Never doubt that a small group of
> http://nwalsh.com/            | thoughtful, committed citizens can
>                               | change the world. Indeed,
> it's the only
>                               | thing that ever has.--Margaret Mead
>


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: Setting the context position?

by Norman Walsh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

/ "Michael Kay" <mike@...> was heard to say:
| At the level of the XPathContext object, you can call
| context.setCurrentIterator() supplying a SequenceIterator; the methods
| current() and position() on that SequenceIterator provide the context item
| and context position, and if the SequenceIterator is a LastPositionFinder
| then its getLastPosition() method provides the value of the context size.
|
| There's no equivalent to this in any higher-level APIs. There's also no way
| of drilling down from the XPathSelector to access the XPathContext object
| directly.

Uhm. Ok, I'm doing something a little weird so I have to get my hands
dirty, I don't mind, but ... could you give me a push me in the right
direction?

In broad strokes, what do I do instead of

  XPathCompiler c = new XPathCompiler(processor);
  XPathExecutable e = c.compile(expr);
  XPathSelector s = e.load();
  Iterator<XdmItem> values = s.iterator();

I tried to find somewhere to start by poking at the JavaDocs, but
wasn't successful.

                                        Be seeing you,
                                          norm

--
Norman Walsh <ndw@...> | Words ought to be a little wild for
http://nwalsh.com/            | they are assaults of thought on the
                              | unthinking.--John Maynard Keynes


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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: Setting the context position?

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Underneath the s9api XPathExecutable is a
net.sf.saxon.sxpath.XPathExpression. Call createDynamicContext() on this to
get an XPathDynamicContext object; call getXPathContextObject() on that to
get the underlying XPathContext. Then call XPathContext.setCurrentIterator()
to supply a SequenceIterator whose current() and position() methods return
the context item and position respectively. If there's any risk that the
expression will call the last() method, then it's simplest to make your
iterator's getProperties() return LAST_POSITION_FINDER, and implement the
LastPositionFinder interface, in which case last() will be implemented by
calling the iterator's getLastPosition() method. (Otherwise last() is
implemented by calling getAnother() to clone the iterator and calling next()
on the clone until the end of the sequence is reached).

Then evaluate the expression by calling iterate() on the
net.sf.saxon.sxpath.XPathExpression object.

Good luck!

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

> -----Original Message-----
> From: saxon-help-bounces@...
> [mailto:saxon-help-bounces@...] On Behalf
> Of Norman Walsh
> Sent: 23 July 2008 14:54
> To: saxon-help@...
> Subject: Re: [saxon] Setting the context position?
>
> / "Michael Kay" <mike@...> was heard to say:
> | At the level of the XPathContext object, you can call
> | context.setCurrentIterator() supplying a SequenceIterator;
> the methods
> | current() and position() on that SequenceIterator provide
> the context
> | item and context position, and if the SequenceIterator is a
> | LastPositionFinder then its getLastPosition() method
> provides the value of the context size.
> |
> | There's no equivalent to this in any higher-level APIs.
> There's also
> | no way of drilling down from the XPathSelector to access the
> | XPathContext object directly.
>
> Uhm. Ok, I'm doing something a little weird so I have to get
> my hands dirty, I don't mind, but ... could you give me a
> push me in the right direction?
>
> In broad strokes, what do I do instead of
>
>   XPathCompiler c = new XPathCompiler(processor);
>   XPathExecutable e = c.compile(expr);
>   XPathSelector s = e.load();
>   Iterator<XdmItem> values = s.iterator();
>
> I tried to find somewhere to start by poking at the JavaDocs,
> but wasn't successful.
>
>                                         Be seeing you,
>                                           norm
>
> --
> Norman Walsh <ndw@...> | Words ought to be a little wild for
> http://nwalsh.com/            | they are assaults of thought on the
>                               | unthinking.--John Maynard Keynes
>


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: Setting the context position?

by Norman Walsh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

/ "Michael Kay" <mike@...> was heard to say:
| Underneath the s9api XPathExecutable is a
| net.sf.saxon.sxpath.XPathExpression.

Alas, it's private. Ideally, I'd like to be able to distribute XProc
without distributing a hacked version of Saxon :-)

Would you consider adding some method for extricating the underlying
XPathExpression from the XPathExecutable?

                                        Be seeing you,
                                          norm

--
Norman Walsh <ndw@...> | It is said that power corrupts, but
http://nwalsh.com/            | actually it's more true that power
                              | attracts the corruptible. The sane are
                              | usually attracted by other things than
                              | power.--David Brin


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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: Setting the context position?

by Norman Walsh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

/ "Michael Kay" <mike@...> was heard to say:
| Then evaluate the expression by calling iterate() on the
| net.sf.saxon.sxpath.XPathExpression object.
|
| Good luck!

Sweet success! Thanks, Mike!

                                        Be seeing you,
                                          norm

--
Norman Walsh <ndw@...> | There is something fundamentally wrong
http://nwalsh.com/            | with treating the earth as if it were a
                              | business in liquidation.--Herman Daly


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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: Setting the context position?

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> / "Michael Kay" <mike@...> was heard to say:
> | Underneath the s9api XPathExecutable is a
> | net.sf.saxon.sxpath.XPathExpression.
>
> Alas, it's private. Ideally, I'd like to be able to
> distribute XProc without distributing a hacked version of Saxon :-)
>
> Would you consider adding some method for extricating the
> underlying XPathExpression from the XPathExecutable?
>

There's a public accessor getUnderlyingExpression()

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


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 
LightInTheBox - Buy quality products at wholesale price