Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum exam score

Status
Not open for further replies.

immalada

Technical User
Jul 18, 2003
2
0
0
ES
HI,I don't know how calculate the final exam score adding all questions scores. If the answer is correct I want to increment 1 point, and if is incorrect I don't want to increment the final score.
If someone could help me please... :)

<xsl:template match=&quot;exam&quot;>
<xsl:for-each select=&quot;question&quot;>
<xsl:if test=&quot;identquest/@id='Q'&quot;><br></br><br></br>
<xsl:choose>
<xsl:when test=&quot;response/condition/@ident='Correct'&quot;>
<xsl:text>Correct answer</xsl:text>
<xsl:variable name=&quot;score&quot; select=&quot;1&quot; >
</xsl:variable>
</xsl:when>
<xsl:eek:therwise>
<xsl:if test=&quot;response/condition/@ident='Incorrect'&quot;>
<xsl:text>Correct answer</xsl:text>
<xsl:variable name=&quot;score&quot;select=&quot;0&quot;></xsl:variable>
</xsl:if>
</xsl:eek:therwise>
</xsl:choose>
</xsl:if>
..................more questions.............

</xsl:for-each>
<xsl:text> Final Score : .................</xsl:text>
</xsl:template>
 
Hi,

If you want the final score, then instead of incrementing a variable in xsl (which you can't do anyways since xsl variables are all immutable), you can use a construct like:

<xsl:value-of select=&quot;count(question/identquest[@id='Q']/response/condition[@ident='Correct'])&quot;/>

This construct effectively counts all the 'condition' elements which have their ident attribute set to 'Correct' and which are child elements of 'question' elements which have an attribute 'id' with a value of 'Q'.
You could assign this value to a variable and use it wherever you want.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top