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

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 <jeni@xxxxxxxxxxxxxxxx>
Date: Sun, 13 Jan 2002 14:42:43 +0000
xml maximum value sum count
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

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

  - 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



Jeni Tennison

 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.