Problem: Compute the average grade of each student and the total
average of the course
XML Input file (students.xml):
XSL Style Sheet :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="course">
<xsl:apply-templates select="student"/>
total average="<xsl:value-of select="(sum(//hw1) +
sum(//hw2) +
sum(//final) +
sum(//project))
div (4*count(//student))"/>"
</xsl:template>
<xsl:template match="student">
<xsl:variable name="ave">
<xsl:value-of select="(hw1 + hw2 + project + final) div 4"/>
</xsl:variable>
Student name="<xsl:value-of select="name"/>"
average="<xsl:value-of select="$ave"/>"
</xsl:template>
</xsl:stylesheet>
Output file (grades.txt):
Student name="John Smith"
average="66.25"
Student name="George Lucas"
average="77.5"
Student name="Elizabeth Roberts"
average="73.75"
total average="72.5"