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
   | <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
 
	<xsl:template match="/">
		<table border="1">
			<xsl:for-each select="//categorie">
				<xsl:variable name="total" select="sum(descendant::montant)"/>
				<tr>
					<td><xsl:value-of select="libelle"/></td>
					<td><xsl:value-of select="$total"/></td>
					<td>
						<xsl:variable name="total-pondere">
							<xsl:call-template name="cumul">
								<xsl:with-param name="categories" select="descendant-or-self::categorie[montant]"/>
							</xsl:call-template>
						</xsl:variable>
						<xsl:value-of select="round($total-pondere div $total * 100)"/>
					</td>
				</tr>
			</xsl:for-each>
		</table>
	</xsl:template>
 
	<xsl:template name="cumul">
		<xsl:param name="categories"/>
		<xsl:param name="index" select="1"/>
		<xsl:param name="total" select="0"/>
		<xsl:choose>
			<xsl:when test="$index <= count($categories)">
				<xsl:call-template name="cumul">
					<xsl:with-param name="categories" select="$categories"/>
					<xsl:with-param name="index" select="$index + 1"/>
					<xsl:with-param name="total" select="$total + ($categories[$index]/montant * $categories[$index]/pourcentage div 100)"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$total"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
 
</xsl:stylesheet>  |