dcsimg
sum up values of all entities in XSLT
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Aaron_Fong
Posted On:   Saturday, October 28, 2006 12:01 AM

Dear all, I have a xml like this: <?xml version="1.0" encoding="UTF-8"?> Maria Hong Kong Observatory 1.6 15.0 Mid Levels 0.0 2.0 10.0 0.0 Shau Kei Wan 0.0 2.5 10.0 1.0 I want to sum up the total rainfall amount in html like this: Station Total Hong Kong Observatory 16.6 Mid Levels 12.0 Shau Kei Wan 13.5 So how to sum up the value of the "amount" entity? Please help!!! Thx a lot!.    More>>

Dear all,

I have a xml like this:

			
<?xml version="1.0" encoding="UTF-8"?>

Maria


Hong Kong Observatory
1.6
15.0


Mid Levels
0.0
2.0
10.0
0.0


Shau Kei Wan
0.0
2.5
10.0
1.0




I want to sum up the total rainfall amount in html like this:

Station Total
Hong Kong Observatory 16.6
Mid Levels 12.0
Shau Kei Wan 13.5

So how to sum up the value of the "amount" entity? Please help!!! Thx a lot!.    <<Less

Re: sum up values of all entities in XSLT

Posted By:   Roseanne_Zhang  
Posted On:   Tuesday, November 21, 2006 09:40 AM

Aaron Fong

Please use
 tag to make your code readable. I did this one for you!


Thanks!

Re: sum up values of all entities in XSLT

Posted By:   Robert_Lybarger  
Posted On:   Saturday, October 28, 2006 11:10 AM

Doing that purely in xslt is entirely possible, but is generally not straightforward, so I will not be taking the time to code a working stylesheet. I've generally attacked that kind of thing via a recursion (which presents its own problems for very large xml data sets). On the other hand, just writing a simple xslt file to create a text file with one value on each line and then use a simple program to add the values on the lines. This'll be easier than pure xslt. Heck, given the relative simplicity of your xml file, just write java code that reads xml itself ... SAX-based might be very simple here.
About | Sitemap | Contact