<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html"/>
	<xsl:variable name="coefmax">
		<xsl:call-template name="max">
			<xsl:with-param name="noeuds" select="//COEF"/>
		</xsl:call-template>
	</xsl:variable>
	<xsl:template match="CATALOGUE">
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head/>
			<body>
				<xsl:call-template name="valeurs"/>
			</body>
		</html>
	</xsl:template>
	<xsl:template name="valeurs">
		<xsl:param name="i">1</xsl:param>
		<xsl:if test="$coefmax >= $i">
			<xsl:call-template name="baton">
				<xsl:with-param name="val" select="count(//COEF[. = $i])"/>
				<xsl:with-param name="text" select="concat('Coef = ',$i)"/>
			</xsl:call-template>
			<xsl:call-template name="valeurs">
				<xsl:with-param name="i" select="$i + 1"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	<xsl:template name="baton">
		<xsl:param name="max">20</xsl:param>
		<xsl:param name="val"/>
		<xsl:param name="text"/>
		<xsl:variable name="long" select="$val div $max * 100"/>
		<table width="100%">
			<tr>
				<td bgcolor="red" width="{$long}%"/>
				<td>
					<xsl:value-of select="$val"/> - <xsl:value-of select="$text"/>
				</td>
			</tr>
		</table>
	</xsl:template>
	<xsl:template name="max">
		<xsl:param name="noeuds"/>
		<xsl:param name="m">0</xsl:param>
		<xsl:choose>
			<xsl:when test="count($noeuds)=0">
				<xsl:value-of select="$m"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="max">
					<xsl:with-param name="noeuds" select="$noeuds[position() != 1]"/>
					<xsl:with-param name="m">
						<xsl:choose>
							<xsl:when test="$m &lt; $noeuds[1]">
								<xsl:value-of select="$noeuds[1]"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="$m"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
