Salut Erwy
autrement tu aurais des algo un peu plus simple en passant la position en parametre et l'ensemble des noeuds a traiter et en testant si la position passe est pair ou impair
Si j'ai bien saisi l'idée, ca devrait donner ca :
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
| <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>TEST</title>
</head>
<body>
<xsl:call-template name="affiche">
<xsl:with-param name="mesBiens" select="test/bien"/>
<xsl:with-param name="position" select="1"/>
</xsl:call-template>
</body>
</html>
</xsl:template>
<xsl:template name="affiche">
<xsl:param name="mesBiens"/>
<xsl:param name="position"/>
<p>
<xsl:attribute name="style">
<xsl:choose>
<xsl:when test="$position mod 2 = 0">background-color: red</xsl:when>
<xsl:otherwise>background-color: blue</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="$mesBiens[$position]"/>
</p>
<xsl:if test="$mesBiens[$position + 1]">
<xsl:call-template name="affiche">
<xsl:with-param name="mesBiens" select="$mesBiens"/>
<xsl:with-param name="position" select="$position + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet> |
Effectivement, c'est un peu plus clean, pas d'utilisation des axes XPath. Mais bon, tout cela reste du bricolage...
Partager