This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 18541

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.

It is sorta covered in the JavaRanch Style Guide.
subject: XSLT Calculations
Similar Threads
Problem with using PrintWriter inside a JSP
Java in XSLT
Exception coming while transforming
xmlns and xsl
Using XSL to display XML