Meaningless Drivel is fun!
The moose likes XML and Related Technologies and the fly likes  XSLT  Calculations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark " XSLT  Calculations" Watch " XSLT  Calculations" New topic

XSLT Calculations

Siva Arun

Joined: Feb 23, 2010
Posts: 28
Input XML


I just want to calculate the average marks of all the students and display it on the same output HTML. Could you please guide me?
Thanks in advance.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

There's a "sum(nodeset)" function in XSLT. And I expect if you looked in some documentation you would find another function called something like "count". Those should take care of the problem.
Siva Arun

Joined: Feb 23, 2010
Posts: 28
The below code works fine.

avg function seems to be not available in XLST 1.0 version. Though I used XSLT 2.0, It is giving me the error.

I agree. Here's the link:
subject: XSLT Calculations
It's not a secret anymore!