[xquery-talk] Use of for in XQuery
jeni at jenitennison.com
Thu Jul 15 22:13:11 PDT 2004
> As u would have guessed, I wish to summate the length*breadth for
> all boxes.
The sum() function takes a sequence and sums the items in that
sequence. So if you want to sum the length*breadth of the boxes, you
need to create a sequence that contains the length*breadth of each
box, and then use the sum() function on that sequence. For example:
sum( for $box in (doc("boxes.xml")/boxes/box)
return ($box/length * $box/breadth) )
Note that it's a lot easier to iterate over the <box> elements
themselves rather than iterating over a sequence of integers whose
length is the same as the number of <box> elements.
More information about the talk