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 1278 - [XQuery] Atomic Values to be returned in XPath steps
Summary: [XQuery] Atomic Values to be returned in XPath steps
Status: CLOSED WONTFIX
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XPath 2.0 (show other bugs)
Version: Last Call drafts
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Don Chamberlin
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords: futureConsideration
Depends on:
Blocks:
 
Reported: 2005-04-29 04:39 UTC by Henry Luo
Modified: 2005-06-10 23:16 UTC (History)
0 users

See Also:


Attachments

Description Henry Luo 2005-04-29 04:39:37 UTC
This is a consolidation of some views in the www-ql@w3.org mailing list on the 
issue.

Current spec only allows atomic values to be returned in the last step of 
XPath. And it is a compromise between two extremes, i.e.:

1. No atomic value to be returned in XPath
People supporting this want to preserve the node selection nature of the '/' 
operator and XPath. And prefer to use FLWR expression to work on atomic values.

However, even we go this way, we still cannot prevent the general iterator 
semantic, people can still construct expr like:
<a/> / <b/>,
let $a = any-node-expr1, $b = any-node-expr2 return $a/$b

2. Atomic values can be returned in all the steps in XPath
This would make '/' a general iterator, or mapping operator.
Personally I strongly support this semantic. Because it makes the semantic 
of '/' very simple and clean.

If we introduce a 'foreach' expression under XQuery like in XSLT,
then 'expr1/expr2' would be equivelent to 'foreach (expr1) return expr2'.
Then '/' becomes an abbreviation, just like '//' is the abbreviation of
'/descendant-or-self::node()/'. Even we don't introduce the 'foreach' 
expression in this version, we can still define the concept in the Semantic 
spec.

Allowing '/' to be iterator, can help construct some compact expressions, like:

concat(min(//*/local-name()), '-', max(//*/local-name()))
rather than
concat(min(for $n in //* return local-name($n)), '-', max(for $n in //*
return local-name($n))

Generally, the most common use case would be using '/' as a mapping operator, 
which is available in many funcational languages that applies a function unto a 
sequence of values.

Since we cannot eliminate the mapping semantic of '/' anywhere, why not accept 
it.

Personally I would strongly suggest either no atomic values to returned in
path expression or atomic values to returned in any step of the path.
The middle way is not a good choice. It makes the semantic and implementation 
more complicated and can cause a lot of confusion.
Comment 1 Henry Luo 2005-04-29 07:14:05 UTC
Michael Kay's comments which I think worth re-quoting here:

I personally wanted to use a different operator than "/" for mapping
sequences of atomic values, but now that we allow a sequence of atomic
values on the right of "/", I personally think it would make sense also to
allow a sequence of atomic values on the left. If we're going to allow
*/name() and */string-length() then we might as well also allow
*/name()/string-length(). The semantics are perfectly well-defined - it just
requires that (a) both operands must be homogenous sequences, and (b)
reordering and deduplication occurs only if the rh operand is a sequence of
nodes. It will allow some programming idioms which will look strange at
first, such as (1 to 5)/$x[.] to select the first 5 items in $x, but strange
programming idioms are nothing new in XPath.

I would suggest you raise this as a last-call comment on the spec. There
will probably be a reaction from the working group of "no new
functionality", but in my view there's a strong argument based on the fact
that it is simply removing a restriction from the language that can't be
justified. And it's not a new comment - there have been calls for a "simple
mapping operator" for years.
Comment 2 Don Chamberlin 2005-06-10 23:15:48 UTC
On May 17, 2005, the Query and XSLT working groups discussed your comment and 
decided that making "/" into a general mapping operator is beyond the scope of 
XPath 2.0.  This suggestion will be reconsidered in a future version of XPath.