# [xquery-talk] Using Sum and Count

Wei, Alice J. ajwei at indiana.edu
Tue Jan 15 18:33:21 PST 2008

```Hi,

Thanks for the replies. Returning to your question, what I want is something simple. That is,  to compute how many "nodes" there are in the XML to express how many child occurrences are from the parent.

The result I have computed before your configurations show individual numbers of the occurrences of the nodes, which is "1". Instead of seeing "1" line after line, I only want to see one line that tells me how many occurrences are there from the XML without printing the rest of the stuff in the code.

Is this possible?

Thanks to those who can help.
======================================================
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu
________________________________________
From: David Carlisle [davidc at nag.co.uk]
Sent: Tuesday, January 15, 2008 6:25 PM
To: Wei, Alice J.
Cc: talk at x-query.com
Subject: Re: [xquery-talk] Using Sum and Count

If I understand your requirement you just want
<statistics>{
count(doc("http://chausie.slis.indiana.edu:8080/exist/rest//db/resume/resume.xml")//projection)
}</statistics>
no need for a FLWR clause here.

for \$project in
doc("http://chausie.slis.indiana.edu:8080/exist/rest//db/resume/resume.xml"),

using for over a single node is rather odd in xquery (it means the same
as let, it's needed in Xpath2 which lacks the let clause, but not here)

here again I think you intended let rather than for, using for means
that \$head gets bound, on each iteration, to a single projection
element, so count(\$head) is always going to be 1.

Conversely

would bind \$head to the sequence of elements so count() would do
something useful.

finally I'm not sure what you intended to sum with sum() but expressions
need to be in {} as otherwise it's just taken as a text node child of
the generated eleemnt.

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is