This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Alternating rows with multiple tables


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]