🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fr.comp.text.xml
Article #488

XSLT - compter et faire une moyenne

#488
From: vedder57
Date: Sat, 28 Oct 2006 16:27
60 lines
3653 bytes
Bonjour,
j'ai un fichier xml comme celui-ci :

<?xml version="1.0" encoding="ISO-8859-1" ?>
 <?xml-stylesheet href="class_exer3.xsl" type="text/xsl" ?>
 <université>
     <étudiant><nom>Réjean Tremblay</nom>
         <cours sigle="INF8430" note="89" />
         <cours sigle="INF1030" note="69" />
         <cours sigle="INF1230" note="75" /></étudiant>
     <étudiant><nom>Martin Lambert</nom>
         <cours sigle="INF8430" note="75" />
         <cours sigle="INF1030" note="72" />
         <cours sigle="INF1230" note="73" /></étudiant>
     <étudiant><nom>Luc Alain</nom>
         <cours sigle="INF9430" note="39" />
         <cours sigle="INF1030" note="89" />
         <cours sigle="INF1230" note="79" /></étudiant>
     <étudiant><nom>Olive Saint-Amant</nom>
         <cours sigle="INF8430" note="91" />
         <cours sigle="INF1230" note="99" /></étudiant>
 </université>

je veux faire une somme et une moyenne des cours ayant le même
sigle...voici mon fichier xsl :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
    <xsl:template match="université">
        <html><body>
            <table border="1">
                <tr ><td><b>Sigle</b></td><td ><b>Nombre
d'étudiants</b></td><td ><b>Moyenne du cours</b></td></tr>
                    <xsl:for-each select="//cours" >
                        <tr>
                        <td width="120px">
                            <xsl:value-of select="@sigle" />
                        </td>
                        <td width="120px">
                            <xsl:value-of
select="count(//cours[@sigle=current()/@sigle])" />
                        </td>
                        <td width="120px">
                            <xsl:value-of
select="format-number(sum(//cours[@sigle=current()/@sigle]/@note) div
count(//cours[@sigle=current()/@sigle]), '##.0')" />
                        </td>
                        </tr>
                    </xsl:for-each>
            </table>
        </body></html>
    </xsl:template>
</xsl:stylesheet>

la somme et la moyenne se calcul bien mais j'aimerais grouper les info
par sigle pour l'affichage...par exemple, présentement le cours
INF8430 s'affiche 4 fois puisqu'il y a 4 cours avec ce sigle dans mon
fichier xml...je ne peux pas utiliser le keyword "key"...quelqu'un a
une piste à me fournir ?
Technical Details
Message-ID: <1162052868.618381.83710@b28g2000cwb.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!b28g2000cwb.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 114f60,ed4259d1ef4bd1b7,start
X-Google-Attributes: gid114f60,public
X-Google-Language: FRENCH,ASCII
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!b28g2000cwb.googlegroups.com!not-for-mail
From: vedder57@gmail.com
Newsgroups: fr.comp.text.xml
Subject: XSLT - compter et faire une moyenne
Date: 28 Oct 2006 09:27:48 -0700
Organization: http://groups.google.com
Lines: 61
Message-ID: <1162052868.618381.83710@b28g2000cwb.googlegroups.com>
NNTP-Posting-Host: 69.157.131.82
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1162052874 30678 127.0.0.1 (28 Oct 2006 16:27:54 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sat, 28 Oct 2006 16:27:54 +0000 (UTC)
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) Gecko/20061010 Firefox/2.0,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: b28g2000cwb.googlegroups.com; posting-host=69.157.131.82;
   posting-account=9PYrEQ0AAADXvhPoHXK8rXG5kgxnYubv