Sign Up
Search
Options
search
Chat
Help
News
Log in
Not Logged in
Home
»
Boards
»
Stylus Studio Developer Network
»
XQuery Help and Discussion
»
summing up the figure in the nodes retrieved.
Topic
Prev Topic
Next Topic
next
Subject:
summing up the figure in the nodes retrieved.
Author:
shirley tay
Date:
31 May 2007 09:46 AM
Hi,
Is there any method that i actully can sum up the values(as in amount) to be in a single node instead of so many? thanks!
Here's part of my xquery:
{
(let $projName := $a/project/row[members/member/text() = $staffName/text()]/name
return<project>{data($projName)}</project>)
union
( for $projName in $a/project/row[members/member/text() = $staffName/text()]/name,
$projFund in $a/project/row[name=$projName]/fundings/fund
let $fundAmt := $a/funding/row[id=$projFund]/amount/number(),
$nrProjMem := count($a/project/row[name=$projName]/members/member)
return <fundings>
{
let $funds := $a/funding/row[id=$projFund]/id,
$nrProj := count($a/project/row[fundings/fund=$funds]/name),
$totalAmt := $fundAmt div $nrProj div $nrProjMem
return <amount>${$totalAmt}</amount>
}
</fundings>)
and this is the output :
<project>Project 1 Project 2 Project 3</project>
<fundings>
<amount>$75000</amount>
</fundings>
<fundings>
<amount>$25000</amount>
</fundings>
<fundings>
<amount>$100000</amount>
</fundings>
<fundings>
<amount>$150000</amount>
</fundings>
<fundings>
<amount>$100000</amount>
</fundings>
<fundings>
<amount>$50000</amount>
</fundings>
next
Subject:
summing up the figure in the nodes retrieved.
Author:
(Deleted User)
Date:
31 May 2007 11:56 AM
Hi Shirley,
it's not clear what do you mean by "a single node"; could you post the desired output?
Alberto
next
Subject:
summing up the figure in the nodes retrieved.
Author:
shirley tay
Date:
31 May 2007 12:13 PM
sorry abt the unclear statements...
my desired output is as in below:
<project>Project 1 Project 2 Project 3</project>
<fundings>
<amount>$x</amount>
</fundings>
$x = $75000+$25000+$100000+$150000+$100000+$50000
the amount should be sum up of all the values in the <amount>.
so the final output would be $500,000 instead of seperated nodes with the unsum values.
Cheers!
next
Subject:
summing up the figure in the nodes retrieved.
Author:
Ivan Pedruzzi
Date:
31 May 2007 10:49 PM
See function sum
http://www.w3.org/TR/xquery-operators/#func-sum
Ivan Pedruzzi
Stylus Studio Team
next
Subject:
summing up the figure in the nodes retrieved.
Author:
shirley tay
Date:
01 Jun 2007 12:20 AM
hi there, i've actually try to use the sum function, bt it seems not to work with my xquery.
is there any better solution?
Thanks!
next
Subject:
summing up the figure in the nodes retrieved.
Author:
Ivan Pedruzzi
Date:
01 Jun 2007 01:13 AM
Could you please provide an example of the input document that the query needs to process?
Ivan Pedruzzi
Stylus Studio Team
next
Subject:
summing up the figure in the nodes retrieved.
Author:
shirley tay
Date:
01 Jun 2007 02:13 AM
Originally Posted: 01 Jun 2007 02:12 AM
the input doc is as below:-
<?xml version="1.0" ?>
- <researchnet>
- <staff>
- <row>
<name>John</name>
<position>Lecturer</position>
<faculty>law</faculty>
<email>john@law.com</email>
<homepage>www.law.uni.edu/john</homepage>
</row>
- <row>
<name>Mary</name>
<position>Professor</position>
<faculty>information-technology</faculty>
<email>mary@it.com</email>
<homepage>www.it.uni.edu/mary</homepage>
</row>
- <row>
<name>Lucy</name>
<position>Professor</position>
<faculty>law</faculty>
<email>lucy@law.com</email>
<homepage>www.law.uni.edu/lucy</homepage>
</row>
- <row>
<name>Mike</name>
<position>Lecturer</position>
<faculty>information-technology</faculty>
<email>mike@it.com</email>
<homepage>www.it.uni.edu/mike</homepage>
</row>
- <row>
<name>Alan</name>
<position>Associate Professor</position>
<faculty>information-technology</faculty>
<email>alan@it.com</email>
<homepage>www.it.uni.edu/alan</homepage>
</row>
- <row>
<name>Tom</name>
<position>Professor</position>
<faculty>information-technology</faculty>
<email>tom@it.com</email>
<homepage>www.law.uni.edu/tom</homepage>
</row>
</staff>
- <project>
- <row>
<id>P1</id>
<name>Project 1</name>
<description>This is a project for a small group.</description>
- <members>
<member>Mary</member>
<member>Alan</member>
</members>
- <fundings>
<fund>Fund3</fund>
<fund>Fund1</fund>
</fundings>
<products>Prod1</products>
- <publications>
<publication>Pub1</publication>
<publication>Pub2</publication>
</publications>
<start_date>2004-08-12</start_date>
</row>
- <row>
<id>P2</id>
<name>Project 2</name>
<description>This is a project for a commercial company.</description>
- <members>
<member>Mary</member>
</members>
- <fundings>
<fund>Fund2</fund>
<fund>Fund3</fund>
</fundings>
<products>Prod2</products>
- <publications>
<publication>Pub3</publication>
<publication>Pub4</publication>
</publications>
<start_date>2003-04-01</start_date>
<end_date>2007-03-31</end_date>
</row>
- <row>
<id>P3</id>
<name>Project 3</name>
<description>This is a project for graduates.</description>
- <members>
<member>Mary</member>
</members>
- <fundings>
<fund>Fund2</fund>
<fund>Fund1</fund>
</fundings>
<products>Prod3</products>
<start_date>2007-04-01</start_date>
</row>
</project>
- <funding>
- <row>
<id>Fund1</id>
<source>National Fund</source>
<amount>100000</amount>
<start_date>2007-04-01</start_date>
<end_date>2010-03-31</end_date>
</row>
- <row>
<id>Fund2</id>
<source>Country Fund</source>
<amount>200000</amount>
<start_date>2003-04-01</start_date>
<end_date>2007-03-31</end_date>
</row>
- <row>
<id>Fund3</id>
<source>State Fund</source>
<amount>300000</amount>
<start_date>2003-01-01</start_date>
<end_date>2010-03-31</end_date>
</row>
</funding>
</researchnet>
Thanks!
top
Subject:
summing up the figure in the nodes retrieved.
Author:
Minollo I.
Date:
01 Jun 2007 09:29 AM
Have you tried...
sum(//amount)
...?
Prev Topic
Next Topic
Powered by
Stylus Studio
, the world's leading
XML IDE
for
XML
,
XSLT
,
XQuery
,
XML Schema
,
DTD
,
XPath
,
WSDL
,
XHTML
,
SQL/XML
, and
XML Mapping
!
Go to Conference:
Select Conference
Stylus Studio Feature Requests
Stylus Studio Technical Forum
Website Feedback
XSLT Help and Discussion
XQuery Help and Discussion
Stylus Studio FAQs
Stylus Studio Code Samples & Utilities
Stylus Studio Announcements
go
Log In Options
Username:
Password:
Site Map
|
Privacy Policy
|
Terms of Use
|
Trademarks
Stylus Scoop XML Newsletter:
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.