This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Alternating rows with multiple tables
- From: "David Dymm" <dymm at asset dot com>
- To: <XSL-List at lists dot mulberrytech dot com>
- Date: Mon, 17 Dec 2001 17:49:08 -0500
- Subject: [xsl] Alternating rows with multiple tables
- Reply-to: xsl-list at lists dot mulberrytech dot com
How to alternate background colors in a style sheet that displays multiple
tables so that the first row of each table is "white"? As seen below,
this snippet of code uses "position() mod 2" to determine which background
color to use. HOWEVER, this code is used within a template and is called
repeatedly to display multiple tables in the same document. And I want
the first row of every table to be "white" [#FFFFFF] with subsequent rows
alternating colors. The problem is that if the first table has an odd
number of rows, then "position() mod 2" will cause the first row of the
second table to be the wrong color. That is, if the first row of the
first table is white, then the first row of the second table will be
black. How do I get around this problem?
<xsl:param name="mission_id"></xsl:param>
<hr/>
<h2>Hierarchy for Mission #<B><U><xsl:value-of
select="$mission_id"/></U></B></h2>
<table border="0" bgcolor="white">
<xsl:for-each
select="*/tasked_country_segment/service_tasked_segment/task_unit_and_loca
tion_segment">
<xsl:if test
="aircraft_mission_data_segment/aircraft_mission_data/package_identificati
on!=''">
<xsl:if
test="aircraft_mission_data_segment/aircraft_mission_data/mission_number=$
mission_id">
<tr>
<xsl:attribute name="BGCOLOR">
<xsl:choose>
<xsl:when test="position() mod 2 = 1">#FFFFFF</xsl:when>
<xsl:when test="position() mod 2 = 0">#DBDBDB</xsl:when>
</xsl:choose>
</xsl:attribute>
<td><xsl:value-of
select="aircraft_mission_data_segment/aircraft_mission_data/package_identi
fication"/></td>
</tr>
</xsl:if>
</xsl:if>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
David Dymm
SAIC
304 284-9000 x228
304 284-9001 [fax]
Dymm@asset.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list