[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: For expressions and / operator in XPath 2.0 (Was: Re: [x

Subject: RE: For expressions and / operator in XPath 2.0 (Was: Re: result = node1 * node2 and then get total of all the result from whole document at the end)
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 2 Jan 2002 17:50:46 -0000
xpath and operator
> Mike wrote:
> > In XPath 2.0 the answer is
> >
> >    sum(for $r in //rate return $r/@value * $r/@quantity)
> I feel sure that this is one of the more contentious aspects of XPath
> 2.0, but here goes...
> Why is it that the General Steps have to return nodes? If they didn't,
> you could do something like:
>   sum( //rate/(@value * @quantity) )
> I thought that the answer might be to do with the old set vs. sequence
> thing, and the fact that for backwards compatibility, the / operator
> has to union and sort the nodes.

That is indeed the reason. It was simply too messy to say "if the result is
a sequence of nodes, then they are returned in document order with
duplicates eliminated, if the result is a sequence of simple values, they
are returned as is, and if the result is a mixture of the two, then fire
breaks out." We needed to retain the "document order" semantics for
compatibility and for sensible behavior with recursive mixed content
document structures, and there wasn't a natural way of extending this to
values other than nodes.
> However, I can't work out why you can't just say that the / operator
> performs a union on node identity and a sort on document order; simple
> typed values have neither node identity nor document order, so
> sequences of simple typed values are left as they are.
It would mean, for example, that sum(XXX/@value) would not necessarily give
the same answer as sum(XXX/(@value+0)) (where XXX is an arbitrary
expression); though it would give the same answer 99% of the time, which
would make the exceptions even more surprising.

After months of agonising on this one, we just decided to keep things
simple: "/" eliminates duplicates and returns results in canonical order,
"for" retains duplicates and retains the ordering of the operand. I was sad
to lose "sum(//rate/(@value * @quantity))" but I'd rather make it an error
than have it return results that were difficult to explain to people.

Mike Kay

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.