# Re: A question about the expressive power and limitati

 Subject: Re: A question about the expressive power and limitations of XPath 2.0 From: Jeni Tennison Date: Sun, 13 Jan 2002 14:42:43 +0000
```Hi Dimitre,

> A general statement about what "for" cannot do: Any problem of
> sequence processing, which requires that the result of processing an
> item be used as input for processing the next item(s).
>
> Is this true?
>
> Then an example with sales and having to compute the total sum, but
> also having to maintain a ***running total*** seems most close to
> earth.

I'd say this definition characterised some things that are inefficient
to do with the for expression (as well as some impossible things).

Taking your running total example, say \$items was a set of item
elements, with price and quantity attributes, and you wanted for
whatever reason to get pairs of item and running total.

You could do:

for \$i in (1 to count(\$items))
return (\$items[\$i],
sum( for \$j in (sublist(\$items, 1, \$i))
return (@price * @quantity) )

This isn't particularly efficient because you have to do two sublist
operations within the return expression, but it is possible.

What 'for' *cannot* do, I think, is any aggregation of a sequence of
values unless, of course, that aggregation is already catered for with
a function, for example sum(), count(), distinct-values(), min(),
max() and so on. That's why a concat() that takes a sequence is a good
example.

The 'for' expression is not very efficient at doing things where the
aggregation occurs over a set of nodes, and you want a set of nodes
in return, but the appropriate aggregation function would give you a
simple typed value instead. For example:

- getting the nodes with a particular maximum value (especially if
the 'value' of a node is calculated through some complex
expression)

- getting nodes with distinct values when the 'value' of a node is
not simply the value of a related node.

It is also not very efficient when the position of a node is important
for its interpretation. I've give examples with x,y coordinates
before.

Cheers,

Jeni

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

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

```
Current Thread

### PURCHASE STYLUS STUDIO ONLINE TODAY!

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

### 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.
Email
First Name
Last Name
Company
Subscribe in XML format
 RSS 2.0 Atom 0.3
 Site Map | Privacy Policy | Terms of Use | Trademarks Free Stylus Studio XML Training:
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.