Hi all,
I am a bit desperate already trying to display a XML file using XSLT. I create a table and use <xsl:for-each> to extract every element node. This is working fine. What I want now is so format every column with a color (e.g. red) if the element value is the same as the one in the next node. if the value changes if should change the color (e.g. to blue) and stay so long blue as the value is the same. With the next change, I should switch back to red.
The problem is that I can't find a way to memorize the value of the "old" color.
I give you the shot example which makes is hopefully more clear.
XML file
<node name="first">
<type>1 for test purpose</type>
<user>Paul</user>
</node>
<node name="second">
<type>2 for test purpose</type>
<user>Paul</user>
</node>
<node name="third">
<type>3 for test purpose</type>
<user>Joe</user>
</node>
<node name="fourth">
<type>4 for test purpose</type>
<user>Jenny</user>
</node>
<node name="fith">
<type>5 for test purpose</type>
<user>Jenny</user>
</node>
XSL
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<table border="1">
<tr><td><b>Nodename</b></td>
<td><b>type</b></td>
<td><b>user</b></td>
</tr>
<xsl:for-each select="node">
<tr><td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="type"/></td>
<td><xsl:apply-templates select="user"/></xsl:when>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="user">
<xsl:variable name="before" select="preceding::node[1]/url" />
<xsl:variable name="after" select="following::node[1]/url" />
<xsl:variable name="new" select="." />
<xsl:if test="$after != $new">
<xsl:variable name="newcolor" select="1">
</xsl:variable>
<xsl:call-template name="urlcolor">
<xsl:with-param name="counter" select="$newcolor" />
</xsl:call-template>
</xsl:if>
<xsl:if test="$after = $new">
<xsl:variable name="newcolor"><xsl:text>0</xsl:text></xsl:variable>
<xsl:call-template name="urlcolor">
<xsl:with-param name="counter" select="$newcolor + 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="urlcolor">
<xsl:param name="counter" />
<xsl:if test="$counter = 1">
<div style=" color:#000000; font-style:bold; background-color:#33CC33">
<xsl:value-of select="." />
</div>
</xsl:if>
<xsl:if test="$counter = 2">
<div style=" color:#000000; font-style:bold; background-color:#FFCC33">
<xsl:value-of select="." />
</div>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
It doesn't work now but it should give the user "Paul" the red color(for 2 rows), Joe blue (one row), Jenny again red (2 rows)
Please help.
Thanks a lot