[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Calculate average value recursively

Subject: Calculate average value recursively
From: Weiran Zhang <weiran@xxxxxxxxxxx>
Date: Sun, 22 Jan 2006 12:56:04 +0000
calculate average
Hi,

I'm trying to calculate the average for a set of rainfall values in the 
following node-set:

<month number="1">
	<day number="1">
		<rainfall>1.5</rainfall>
	</day>
	<day number="2">
		<rainfall>0.5</rainfall>
	</day>
	<day number="3">
		<rainfall>TR</rainfall>
	</day>
	...
</month>

Usually, I'd use "sum(month/day/rainfall) div count(month/day)" to get 
the average rainfall, however, as null values are represented as "TR", 
that expression returns a NaN error.

I'm thinking that I would need a recursive method that can catch cases 
such as TR, appends either the rainfall value or 0 to a sequence, which 
it would send back recursively as a parameter until reaching the end and 
then dividing by the number of days? However, I'm not sure about how to 
do this, nor am I sure if it's the right solution!

Thanks in advance.

Regards,


Weiran.

-- 
Weiran Zhang

E-mail: weiran@xxxxxxxxxxx
Website: www.ejecutive.co.uk

[demime 1.01d removed an attachment of type application/x-pkcs7-signature which had a name of smime.p7s]

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.