groupement + fonction distinct-values()
Bonsoir,
soit le doc votes.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
<?xml version="1.0"?>
<Votes>
<Ville nom="Cachan" dept="94">
<Bureau num="1">
<Candidat nom="Toto" voix="3398"/><Candidat nom="Dupont" voix="6589"/>
</Bureau>
<Bureau num="2">
<Candidat nom="Toto" voix="5645"/><Candidat nom="Dupont" voix="4090"/>
</Bureau>
</Ville>
<Ville nom="LHay" dept="94">
<Bureau num="1">
<Candidat nom="Toto" voix="2067"/><Candidat nom="Dupont" voix="4089"/>
</Bureau>
</Ville>
<Ville nom="Bagneux" dept="92">
<Bureau num="1">
<Candidat nom="Toto" voix="4723"/><Candidat nom="Dupont" voix="5167"/>
</Bureau>
</Ville>
</Votes> |
Question:
Écrivez un programme XSLT qui calcule la somme des voix pour chacun des candidats. Le résultat de la transformation donnera le document :
<Votes>
<Candidat nom="Toto">15833</Candidat>
<Candidat nom="Dupont">19935</Candidat>
</Votes>
Mon essai:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
...
xsl:template match="Votes">
<votes>
<xsl:for-each select="Ville/Bureau/Candidat">
<xsl:if test="not(@nom=following::Candidat/@nom)">
<xsl:variable name="nom" select="@nom"/>
<candidat nom="{@nom}"><xsl:value-of select="sum(//Candidat[@nom=$nom]/@voix)"/> </candidat>
</xsl:if>
</xsl:for-each>
</votes>
</xsl:template>
... |
çà marche tés bien. je veux une autre solution utilisant la fonction:
distinct-values ()
merci d'avance