Re: XPath2 questions

Hi Peter,

> I have a few questions relating to an implementation of XPath2.0 and
> hope this is the correct address for advice.

This address was used for comments on the WDs (the address you should
send comments to now is public-qt-comments@w3.org). For advice about
XPath, I recommend posting on XSL-List
(http://www.mulberrytech.com/xsl/xsl-list).

> I'd like to better understand how to address the context item focus
> over a sequence of nodes. For example, given the following input
> sequence into the expression "//child::mynode" :
>
> (
>   <mydocA><mynode></mydocA>,
>   <mdocB><mynode></mydocB>
> )
>
> Will this return (<mynode>,<mynode>), the child nodes of <mydocA>
> and <mydocB>?

Yes. The expression expands to:

  root()/descendant-or-self::node()/child::mynode

With a context node of the first item in your sequence, the <mydocA>
element, root() returns the <mydocA> element; the
descendant-or-self::node() step returns the <mydocA> and <mynode>
elements. With a context node of the <mydocA> element, the step
child::mynode returns the <mynode> element. With a context node of the
<mynode> element, child::mynode> returns an empty sequence. So for the
first item in your input sequence, the result is the <mynode> element
within the <mydocA> element.

With a context node of the second item in your sequence, the <mydocB>
element, root() returns the <mydocB> element; the
descendant-or-self::node() step returns the <mydocB> and <mynode>
elements. With a context node of the <mydocB> element, the step
child::mynode returns the <mynode> element. With a context node of the
<mynode> element, child::mynode> returns an empty sequence. So for the
second item in your input sequence, the result is the <mynode> element
within the <mydocB> element.

Thus the result for the sequence as a whole is a sequence of the two
<mynode> elements.

[Note: I've assumed that <mydocA> and <mydocB> are parentless
elements, but the answer would be the same if they weren't.]

> Also, in the case of the expression "child::mydocA" operating on the
> same input sequence, will this result in a singleton sequence of
> (<mydocA>)? My feeling is that it does, however if this is correct,
> I'm finding it difficult to conceptualise the notion of a child axis
> for a sequence of items.

With a context node of the first item in your sequence, the <mydocA>
element, the step "child::mydocA" results in an empty sequence because
the <mydocA> element doesn't have any <mydocA> element children.

With a context node of the second item in your sequence, the <mydocB>
element, the step "child::mydocA" results in an empty sequence because
the <mydocB> element doesn't have any <mydocB> element children.

Thus the result of "child::mydocA" with your input sequence is an
empty sequence.

> Finally, is there a test suite available or under development for
> XPath 2.0?

I don't know; perhaps someone else can answer this.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Thursday, 6 March 2003 07:35:26 UTC