This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 3380 - [XPath] //45 returns what?
Summary: [XPath] //45 returns what?
Status: CLOSED INVALID
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XPath 2.0 (show other bugs)
Version: Candidate Recommendation
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Jerome Simeon
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-23 10:06 UTC by atsushi.ohtake
Modified: 2006-08-15 16:16 UTC (History)
0 users

See Also:


Attachments

Description atsushi.ohtake 2006-06-23 10:06:11 UTC
Hi,

As per the XPath 2.0 specification Literal can be specified after // (double slash).
means //45 is the correct path expression.

But I have a doubt regarding the returned value for this expression as it is not clearly specified in the specification.

1. Should it return me the sequence containing N no. of integer(45). Where N is the no. of nodes exist into my xml file. (except attribute node).

2. Should it give me an error. (I think it should throw an error as 45(Literal) can never be the name of element, Hence there is no meaning of this expression.)

3. Should it give me the integer(45) only once.

Current spec is 1. But is it helpful to users?
I would appreciate if you help me clarifying this doubt.

Regards,
Atsushi Ohtake
Hitachi, Ltd.
Comment 1 Mukul Gandhi 2006-06-24 08:13:46 UTC
I have a feeling, I agree with your point 2. I am not sure, but probably XPath 2.0 grammar would need correction in this regard.

Regards,
Mukul
Comment 2 Michael Kay 2006-06-24 08:42:23 UTC
I have reclassified this as an XPath comment, since it is not specific to the formal semantics.

I think it would be better if you asked questions about the language first on an open list such as the xsl-list at www.mulberrytech.com. This forum is intended for comments on the language specification documents, not for general questions from users of the language.

The meaning of //45 is unambiguous. It means /descendant-or-self::node()/45, which returns a sequence consisting of the number 45, repeated as many times as there are nodes in the current document. 

It is probably not a very useful expression, but there are many legal expressions that are not very useful, for example 0+0, or 1+1. There are similar expressions that *are* useful, for example //count(*), and a language should always allow a literal to be used in a context where an expression is allowed, even if one can't see a practical use case for it.

Michael Kay
(personal response)

Comment 3 Jim Melton 2006-08-01 16:58:11 UTC
I know that the behavior of any specific implementation does not resolve the question of what the spec says, but...

I just ran this query using the XPath 2.0 feature of Stylus Studio 6 Enterprise Edition Release 3, on a rather large complex document.  The result given by that implementation is 1 hit and a returned value of "45" (without the quotes, of course). 

Using the unabbreviated step syntax (/descendant-or-self::node()/45), the result is exactly the same: 1 hit, value "45".

Is this a helpful data point?
Comment 4 David Carlisle 2006-08-01 17:06:11 UTC
(In reply to comment #3)

> Using the unabbreviated step syntax (/descendant-or-self::node()/45), the
> result is exactly the same: 1 hit, value "45".
> 
> Is this a helpful data point?
> 

Unless there is only one node in the document, then I think it's clear from the spec that you should get multiple copies of 45. duplication-removal done by /
is identity (that is the is operator) not value equality (the eq operator) so doesn't apply to atomic values. (In any case the duplication removal clause is explictly only applied if the sequence consists only of nodes (xquery section 3.2 item 1)
Comment 5 Jerome Simeon 2006-08-01 17:08:44 UTC
Jim, this is a useful bug report for Stylus Studio :)
Below is a trace showing what's supposed to happen.

I agree with Michael's description of the semantics and that the spec is very
clear about what the query means.

- Jerome

simeon ~ > cat test.xq
declare variable $v := <a><b/><b/><b/></a>;
$v//45
simeon ~ > galax-run ~/test.xq -serialize standard
45 45 45 45
Comment 6 Michael Kay 2006-08-15 16:15:52 UTC
The Working Groups discussed this on 15 August 2006 and decided to endorse my personal response in comment #3. I will close the bug report on this basis. If this closure is not acceptable to you, please reopen the bug and explain why.

Thank you for your interest.

Michael Kay
for the XSL and XQuery Working Groups