Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XQuery problem - fn:sum

Thread Tools

XQuery problem - fn:sum
Posts: n/a
Hi All,

I hope someone could help; I need to query bunch of files in certain
collection in certain period of time and generate the result;

1. All files are stored in //Bookkeeping collection

2. XML file Syntax:

<?xml version="1.0" encoding="UTF-8"?>
<bookkeeping date="20050128">
<record billed="40" category="Fee" drid="2" index="1" pid="15" qty="1"
received="20" unitprice="">
<desc>Adjust 40</desc>
<record billed="40" category="Fee" drid="2" index="1" pid="15" qty="1"
received="20" unitprice="">
<desc>OST: Adjust 40</desc>

3. My query:

for $b in //bookkeeping
let $m := $b/VISA/record/@billed
let $n := $b/VISA/record/@received
where $b/@date[contains(., '200501')] and $b/VISA/record/@billed > '0'
<VISA date="{$b/@date}" billed="{sum($m)}" received="{sum($n)}"/>

4. Current result:

<VISA date="20050112" billed="128.0" received="128.0"/>
<VISA date="20050106" billed="400.0" received="400.0"/>
<VISA date="20050119" billed="60.0" received="60.0"/>
<VISA date="20050125" billed="256.0" received="256.0"/>
<VISA date="20050126" billed="100.0" received="100.0"/>
<VISA date="20050127" billed="60.0" received="60.0"/>
<VISA date="20050131" billed="40.0" received="40.0"/>
<VISA date="20050130" billed="115.0" received="115.0"/>

What I need is:

<VISA billed="3400" received="3400"> - the summary of the above



Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with an XQuery statement XML 0 06-06-2008 11:37 AM
problem using xquery and amessimon ASP .Net 1 03-09-2005 10:42 AM
Binding data from XQuery to a dataset HNguyen ASP .Net 0 06-03-2004 07:33 PM
How to bind data from XQuery to a Dataset ?? HNguyen ASP .Net 0 06-03-2004 07:32 PM
Xquery Problem with referenced nodes/objects in Tamino Bastian Gorke XML 0 08-14-2003 10:53 AM