From: Aurélie Sérieux (aserieux@ydris.com)
Date: 02/03/2001 - 12:05
Bonjour à tous !!!
Pour ceux que cela intéresse, j'ai écrit un exemple qui illustre le problème
que j'ai eu sur des calculs à partir de variables lors du passage de MSXML3
à Xalan2 (voir mails "Formatage de nombres" du 27/02/2001).
Je vous remercie d'avance de me faire part du résultat de vos essais (
surtout s'ils sont différents des miens, ou réalisés avec d'autres
processeurs XSLT ).
Aurélie
=====Fichier XML=====
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="Exemple.xsl" type="text/xsl" ?>
<resultat>
<of>
<no>1</no>
<classe>A</classe>
<long>12</long>
<larg>5</larg>
</of>
<of>
<no>2</no>
<classe>B</classe>
<long>26</long>
<larg>31</larg>
</of>
<of>
<no>3</no>
<classe>A</classe>
<long>15</long>
<larg>4</larg>
</of>
<of>
<no>4</no>
<classe>B</classe>
<long>34</long>
<larg>45</larg>
</of>
<of>
<no>5</no>
<classe>A</classe>
<long>954</long>
<larg>45</larg>
</of>
<of>
<no>6</no>
<classe>B</classe>
<long>43</long>
<larg>38</larg>
</of>
</resultat>
=====Fichier XSL=====
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:apply-templates select="resultat" />
</body>
</html>
</xsl:template>
<xsl:template match="resultat">
<div><b>Tableau contenant les données du document XML : </b></div>
<table border="0" cellpadding="2" cellspacing="2" width="100%">
<xsl:call-template name="TeteTab" />
<xsl:apply-templates select="of" />
</table>
<br />
<hr />
<div align="center"><font size="4"><b>S T A T I S T I Q U E
S</b></font></div><br />
<div><b>Les variables de ce tableau ne sont calculées correctement
qu'avec MSXML3 : les déclarations des variables $Metr1, $Metr2, $Surf1 et
$Surf2 sont faites dans les cellules du tableau.</b></div>
<xsl:call-template name="TabMSXML3" /><br />
<div><b>Les variables de ce tableau sont calculées correctement avec
MSXML3 et Xalan : les déclarations des variables $Metr1, $Metr2, $Surf1 et
$Surf2 sont faites à la racine du tableau.</b></div>
<xsl:call-template name="TabXALAN" />
</xsl:template>
<xsl:template name="TeteTab">
<tr>
<th bgcolor="#000000"><font color="#FFFFFF">Numero</font></th>
<th bgcolor="#000000"><font color="#FFFFFF">Classe</font></th>
<th bgcolor="#000000"><font color="#FFFFFF">Longueur</font></th>
<th bgcolor="#000000"><font color="#FFFFFF">Largeur</font></th>
</tr>
</xsl:template>
<xsl:template match="of">
<tr align="center">
<td bgcolor="#dddddd"><xsl:value-of select="no" /></td>
<td bgcolor="#dddddd"><xsl:value-of select="classe" /></td>
<td bgcolor="#dddddd"><xsl:value-of select="long" /></td>
<td bgcolor="#dddddd"><xsl:value-of select="larg" /></td>
</tr>
</xsl:template>
<xsl:template name="TabMSXML3">
<table border="0" cellpadding="2" cellspacing="2" width="100%">
<tr>
<th bgcolor="#000000"><font color="#FFFFFF">Libellé</font></th>
<th bgcolor="#0ff0">
<font color="#000000">Classe A</font>
</th>
<th bgcolor="#ff00ff">
<font color="#000000">Classe B</font>
</th>
</tr>
<tr align="center">
<th bgcolor="#000000"><font color="#FFFFFF">Métrage
:</font></th>
<td bgcolor="#affa">
<xsl:variable name="Metr1" select="sum( of[classe='A']/long
)" />
<xsl:value-of select="$Metr1" />
</td>
<td bgcolor="#ffaaff">
<xsl:variable name="Metr2" select="sum( of[classe='B']/long
)" />
<xsl:value-of select="$Metr2" />
</td>
</tr>
<tr align="center">
<xsl:variable name="MetrTot" select="$Metr1 + $Metr2" />
<th bgcolor="#000000"><font color="#FFFFFF">% Métrage
:</font></th>
<td bgcolor="#affa">
<xsl:value-of select="( $Metr1 div $MetrTot ) * 100" />
</td>
<td bgcolor="#ffaaff">
<xsl:value-of select="( $Metr2 div $MetrTot ) * 100" />
</td>
</tr>
<tr align="center">
<th bgcolor="#000000"><font color="#FFFFFF">Surface
:</font></th>
<td bgcolor="#affa">
<xsl:variable name="EnsSurf1" select="of[classe='A']" />
<xsl:variable name="Surf1">
<xsl:call-template name="Surface">
<xsl:with-param name="EnsSurf" select="$EnsSurf1" />
<xsl:with-param name="ResCourant" select="0" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$Surf1" />
</td>
<td bgcolor="#ffaaff">
<xsl:variable name="EnsSurf2" select="of[classe='B']" />
<xsl:variable name="Surf2">
<xsl:call-template name="Surface">
<xsl:with-param name="EnsSurf" select="$EnsSurf2" />
<xsl:with-param name="ResCourant" select="0" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$Surf2" />
</td>
</tr>
<tr align="center">
<xsl:variable name="EnsSurf" select="of" />
<xsl:variable name="SurfTot">
<xsl:call-template name="Surface">
<xsl:with-param name="EnsSurf" select="$EnsSurf" />
<xsl:with-param name="ResCourant" select="0" />
</xsl:call-template>
</xsl:variable>
<th bgcolor="#000000"><font color="#FFFFFF">% Surface
:</font></th>
<td bgcolor="#affa">
<xsl:value-of select="( $Surf1 div $SurfTot ) * 100" />
</td>
<td bgcolor="#ffaaff">
<xsl:value-of select="( $Surf2 div $SurfTot ) * 100" />
</td>
</tr>
</table>
</xsl:template>
<xsl:template name="TabXALAN">
<table border="0" cellpadding="2" cellspacing="2" width="100%">
<tr>
<th bgcolor="#000000"><font color="#FFFFFF">Libellé</font></th>
<th bgcolor="#0ff0">
<font color="#000000">Classe A</font>
</th>
<th bgcolor="#ff00ff">
<font color="#000000">Classe B</font>
</th>
</tr>
<xsl:variable name="Metr1" select="sum( of[classe='A']/long )" />
<xsl:variable name="Metr2" select="sum( of[classe='B']/long )" />
<tr align="center">
<th bgcolor="#000000"><font color="#FFFFFF">Métrage
:</font></th>
<td bgcolor="#affa">
<xsl:value-of select="$Metr1" />
</td>
<td bgcolor="#ffaaff">
<xsl:value-of select="$Metr2" />
</td>
</tr>
<tr align="center">
<xsl:variable name="MetrTot" select="$Metr1 + $Metr2" />
<th bgcolor="#000000"><font color="#FFFFFF">% Métrage
:</font></th>
<td bgcolor="#affa">
<xsl:value-of select="( $Metr1 div $MetrTot ) * 100" />
</td>
<td bgcolor="#ffaaff">
<xsl:value-of select="( $Metr2 div $MetrTot ) * 100" />
</td>
</tr>
<xsl:variable name="EnsSurf1" select="of[classe='A']" />
<xsl:variable name="Surf1">
<xsl:call-template name="Surface">
<xsl:with-param name="EnsSurf" select="$EnsSurf1" />
<xsl:with-param name="ResCourant" select="0" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="EnsSurf2" select="of[classe='B']" />
<xsl:variable name="Surf2">
<xsl:call-template name="Surface">
<xsl:with-param name="EnsSurf" select="$EnsSurf2" />
<xsl:with-param name="ResCourant" select="0" />
</xsl:call-template>
</xsl:variable>
<tr align="center">
<th bgcolor="#000000"><font color="#FFFFFF">Surface
:</font></th>
<td bgcolor="#affa">
<xsl:value-of select="$Surf1" />
</td>
<td bgcolor="#ffaaff">
<xsl:value-of select="$Surf2" />
</td>
</tr>
<tr align="center">
<xsl:variable name="EnsSurf" select="of" />
<xsl:variable name="SurfTot">
<xsl:call-template name="Surface">
<xsl:with-param name="EnsSurf" select="$EnsSurf" />
<xsl:with-param name="ResCourant" select="0" />
</xsl:call-template>
</xsl:variable>
<th bgcolor="#000000"><font color="#FFFFFF">% Surface
:</font></th>
<td bgcolor="#affa">
<xsl:value-of select="( $Surf1 div $SurfTot ) * 100" />
</td>
<td bgcolor="#ffaaff">
<xsl:value-of select="( $Surf2 div $SurfTot ) * 100" />
</td>
</tr>
</table>
</xsl:template>
<xsl:template name="Surface">
<xsl:param name="EnsSurf" />
<xsl:param name="ResCourant" />
<xsl:choose>
<xsl:when test="not($EnsSurf)">
<xsl:copy-of select="$ResCourant"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="TotCourant" select="$ResCourant +
($EnsSurf[1]/long * $EnsSurf[1]/larg )"/>
<xsl:call-template name="Surface">
<xsl:with-param name="EnsSurf"
select="$EnsSurf[position()>1]"/>
<xsl:with-param name="ResCourant" select="$TotCourant"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
--
Devenez redacteur <XML>fr et contribuez au developpement du
xml francophone (http://xmlfr.org/infos/redacteurs/) !
Liste de diffusion "xml-tech@xmlfr.org" (http://xmlfr.org).
Cette liste est a votre disposition pour discuter en francais de
tout sujet technique lie a XML.
Pour resilier votre abonnement, envoyez un message contenant
la commande "unsubscribe" a xml-tech-request@xmlfr.org
(mailto:xml-tech-request@xmlfr.org?Subject=unsubscribe)
Archive générée par hypermail 2.1.3 le 28/06/2004 - 11:05 UTC
webmaster@xmlfr.org
|