xsl-list
[Top] [All Lists]

Alternating row background color - a twist

2004-12-28 07:13:06
The typical way of alternating the background color of every other row
in an HTML table is something like this:

<xsl:for-each select="msxsl:node-set($sorted_legislators)">
        <tr>
                <xsl:if test="position() mod 2 = 0">
                        <xsl:attribute
name="bgcolor">#eeeeee</xsl:attribute>
                </xsl:if>

------------------------------------

My situation is this - the for-each is based on legislators sorted by
district - here's a sample (not real) xml to illustrate:

<legislators>
    <legislator>
         <name>Joe</name>
         <district_id>1</district_id>
    </legislator>
    <legislator>
         <name>Bob</name>
         <district_id>2</district_id>
    </legislator>
    <legislator>
         <name>Pete</name>
         <district_id>2</district_id>
    </legislator>
</legislators>

There will be one *or more* legislators for each district.  Instead of
alternating the background color for every *legislator*, I want to
alternate the background color for every *district*.  In other words, I
want Joe in district_id 1 to have white background, but I want both Bob
and Pete in district_id 2 to have a gray background.  But since I can't
change the value of a variable (can't increment a counter), I don't know
what I can base the bgcolor alternation on.

The xsl:for-each is based on a select of a variable containing all
legislators sorted by district.

I know there is probably an easy way to do this, but I don't know it. 
Help!

Thanks.

Hardy Merrill

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>