1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="*/*"/>
<xsl:call-template name="moyenne"/>
</xsl:template>
<xsl:template match="*">
<xsl:text>Il y a </xsl:text>
<xsl:call-template name="comptage">
<xsl:with-param name="total">0</xsl:with-param>
<xsl:with-param name="index_courant">1</xsl:with-param>
</xsl:call-template>
<xsl:text> points cette semaine.
</xsl:text>
</xsl:template>
<xsl:template name="comptage">
<xsl:param name="total"/>
<xsl:param name="index_courant"/>
<xsl:choose>
<xsl:when test="$index_courant = count(*) + 1">
<xsl:value-of select="$total"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="un_nombre"><xsl:value-of select="*[position() = $index_courant]"/></xsl:variable>
<xsl:call-template name="comptage">
<xsl:with-param name="total">
<xsl:value-of select="$total + $un_nombre"/>
</xsl:with-param>
<xsl:with-param name="index_courant"><xsl:value-of select="$index_courant + 1"/></xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="moyenne">
<xsl:variable name="sem"><xsl:value-of select="sum(points/semaine/*)"/></xsl:variable>
<xsl:variable name="jour"><xsl:value-of select="sum(points/semaine/jour)"/></xsl:variable>
<!-- nbrSem= nombre de semaines et nbrJour= nombre de jours -->
<xsl:variable name="nbrSem"><xsl:value-of select="count(points/semaine)"/></xsl:variable>
<xsl:variable name="nbrJour"><xsl:value-of select="count(points/semaine/jour)"/></xsl:variable>
<xsl:text>la moyenne des totaux hebdomadaires de points: </xsl:text> <xsl:value-of select="$sem div $nbrSem"/>
<xsl:text>
la moyenne des points journaliers est : </xsl:text><xsl:value-of select="$jour div $nbrJour"/><xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet> |
Partager