W3C home > Mailing lists > Public > www-xpath-comments@w3.org > January to March 2002

Re: Comments on XPath 2.0 specification

From: Jonas Sicking <sicking@bigfoot.com>
Date: Wed, 23 Jan 2002 23:30:22 +0100
Message-ID: <005501c1a45d$8c02ebc0$b3e0d0d9@telia.com>
To: <www-xpath-comments@w3.org>
> > Still, compare
> >
> > sum(//item/quantity * //item/USPrice)
> >
> > and
> >
> > sum(for $item in //item return($item/quantity*$item/USPrice))
> >
> > (Assuming that's correct.  I'm presuming the bound variable does not
> > become the focus of the return expression, since I can't find
> > language
> > in the spec saying it does.)
> >
> > Which is simpler and eaiser to use?
>
> We have debated (and may well debate again) the possible provision of a
> variant of the "for" expression that uses the context item instead of an
> explicit range variable. This would allow syntax such as
>
>     sum(for //item return quantity * USPrice)
>
> The main reason we excluded this from the current draft is that there are
> technical problems with the parsing (because of the need to avoid reserved
> words). But personally, I would like to see such a construct.

How about a 'foreach' construct? So one could write

sum(foreach //item return quantity * USPrice)

Shouldn't that avoid any parsingproblems?

> > By the way, I presume someone has noticed how much this looks like an
> > SQL select, and suggested something akin to
> >
> > sum(select quantity*price from //item)
> >
> >
> > (Here the value of "from" *does* become the focus.)
> >
> Yes indeed. It does suggest to me the idea that
>
>     sum(quantity * price from //item)
>
> might be an acceptable (and parseable) syntax.

This syntax seems a bit reversed IMHO. Somewhat like the perl syntax

print "foo" if a == 1;

While the syntax is both parsable and understandable it is certainly
opposite to most other language-constructs. Normally you put what is
evaluated first first in the syntax; |a == 1| is evaluated before |print
"foo"| therefore |if a==1 { print "foo" }| looks more logical then |print
"foo" if a==1|. For the same reason "//item" should appear before "quantity
* price" since it's evaluated before.

/ Jonas Sicking
Received on Wednesday, 23 January 2002 17:25:51 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 3 October 2007 16:05:54 GMT