[xquery-talk] Use of for in XQuery

Amitabh Ojha amitabhojha at rediffmail.com
Thu Jul 15 17:46:18 PDT 2004


An HTML attachment was scrubbed...
URL: http://xquery.com/pipermail/talk/attachments/20040715/b91a4dcc/attachment.htm
-------------- next part --------------
Dear Sirs,

pl see the XQuery as follows :-

let $a := doc ("boxes.xml")/boxes/box

let $b := $a/length
let $c := $a/breadth

let $d := count ($a)

let $area := ()

for $i in (1 to $d) return 
sum (($area,$b[$i]*$c[$i])) 


The xml document is as follows :-

<boxes>
<box id="1">
<length>20</length>
<breadth>10</breadth>
</box>
<box id="2">
<length>80</length>
<breadth>40</breadth>
</box>
<box id="3">
<length>200</length>
<breadth>100</breadth>
</box>
</boxes>

As u would have guessed, I wish to summate the length*breadth for all boxes. But when I apply the above Xquery, for each iteration of the for statement, the $area is being taken as () even as I expect it to increment each time. The other thing is that I wish to first let the for statement do the summation and then finally I let return statement execute just once giving the sum. Right now, the return statement executes with each iteration of for (each time taking $area as () ) and I am unable to stop that : I just wish one final summation result.

Will be grateful for any advice/ help on this.

Regards.

Amitabh Ojha


More information about the talk mailing list