Re: XPointer question - selecting locations from a location-set

On Wed, Nov 22, 2000 at 01:23:09AM -0800, Michael Dyck wrote:
> Daniel Veillard (Daniel.Veillard@w3.org) wrote:
> >
> > Jiri Jirat wrote:
> > >
> > > If I want to select the point (marked X) just before the string-range
> > > 'another', which expression is correct?
> > >
> > > Is this correct?:
> > > xpointer(string-range(//*,'another')[0])
> > 
> >   Hum, no, that would select the first range in the returned location set
> 
> Actually, the first one would be selected using the predicate [1]. Using
> the predicate [0] guarantees that the expression will never select
> anything, and thus that the XPointer will always have a sub-resource
> error.

  yes, you're right.

> > > Or should it look like this?:
> > > xpointer(string-range(//*,'another')[1][0])
> > 
> >   I think this would return an empty set,
> 
> That is, it wouldn't select anything, and this XPointer also has a
> sub-resource error.
> 
> > > Or should there be some parentheses?
> > 
> >   IMHO the right thing is to use the 4th parameter of string-range to
> > limit the range to the point starting it:
> > 
> > xpointer(string-range(//*,'another',1,0))
> 
> This selects the (collapsed) string-range that begins and ends immediately
> before the 'a' of 'another', which is not quite what was requested.

  hum, right. I did think about it from a text selection point of view,
leading to the confusion.

> Instead,
> 
>     xpointer(start-point(string-range(//*,'another',1,0)))
> 
> will select the *point* immediately before the 'a' of 'another'. Note that
> for the 4th argument to 'string-range', you could use a number other than
> '0', or just omit it, since you're only extracting the start-point and
> don't care where the end-point of the range falls. Also, '1' is the
> default for the 3rd argument, so you could simplify the expression to
> 
>     xpointer(start-point(string-range(//*,'another')))
> 
> > > IMPORTANT: here, in this example, the location-set returned by
> > > "string-range(//*,'another')" consists just of ONE location.
> 
> Actually, this raises an interesting point. The path-expression //*
> selects all element nodes in the document tree, and in fact *two* of them
> have "another" in their string-value: the second <BBB> element obviously,
> but also the <AAA> element, whose string value is the concatenation of the
> string-values of all text nodes in the document. So the string-range()
> call finds two locations in //* that have a match for "another". But does
> it return two range locations, or just one?  I'm pretty sure the answer is
> one, but it's not immediately obvious from the XPointer spec.

  right, 5.1 states:

"Thus, XPointer also defines location-set as a generalization of
 XPath's node-set"

I think this should be added there.

Daniel

-- 
Daniel.Veillard@w3.org | W3C, INRIA Rhone-Alpes  | libxml Gnome XML toolkit
Tel : +33 476 615 257  | 655, avenue de l'Europe | http://xmlsoft.org/
Fax : +33 476 615 207  | 38330 Montbonnot FRANCE | Rpmfind search site
 http://www.w3.org/People/all#veillard%40w3.org  | http://rpmfind.net/

Received on Wednesday, 22 November 2000 04:55:45 UTC