#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Posts
    20
    Rep Power
    0

    creating every other row with green background


    Hi

    Just wondering how would I create a table the at displays every other row (odd row) cells as green using and <xsl:if> below is my code

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">

    <HTML>
    <BODY>
    <p align="left"><font color="#FF0000"><strong>Airport Flight Schedule Leslie Ho</strong></font></p>
    <div align="left">
    <TABLE border="1">
    <tr>
    <th rowspan="2">Airline</th>
    <th colspan="4">To</th>
    <th colspan="3">From</th>
    </tr>
    <tr>
    <th>Airport</th>
    <th>Date</th>
    <th>ATime</th>
    <th>Price($)</th>
    <th>Airport</th>
    <th>Date</th>
    <th>Dtime</th>
    </tr>
    <xsl:for-each select="FLIGHT_SCHEDULE/FLIGHT">
    <xsl:sort select="TO/DATE" data-type="text" order="ascending"/>

    <TR>
    <TD><xsl:value-of select="AIRLINE"/><xsl:value-of select="AIRLINE/@number"/></TD>
    <TD><xsl:value-of select="TO/AIRPORT"/></TD>
    <TD><xsl:value-of select="TO/DATE"/></TD>
    <TD><xsl:value-of select="TO/ATIME"/></TD>
    <TD><xsl:value-of select="TO/PRICE"/></TD>
    <TD><xsl:value-of select="FROM/AIRPORT"/></TD>
    <TD><xsl:value-of select="FROM/DATE"/></TD>
    <TD><xsl:value-of select="FROM/DTIME"/></TD>
    </TR>
    </xsl:for-each>
    </TABLE>
    <font color="#336633"><xsl:text></xsl:text></font></div>
    </BODY>
    </HTML>
    </xsl:template>
    </xsl:stylesheet>

    thanx

    getchoo
  2. #2
  3. No Profile Picture
    CF sMod
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Maine, USA (a.k.a. Boonies)
    Posts
    242
    Rep Power
    15
    I'd think something like:

    <xsl:for-each select="FLIGHT_SCHEDULE/FLIGHT">
    <xsl:sort select="TO/DATE" data-type="text" order="ascending"/>

    <TR>
    <xsl:attribute name="style">
    <xsl:if test="position() mod 2 = 0">
    background-color: evencolor;
    </xsl:if>
    <xsl:if test="position() mod 2 = 1">
    background-color: oddcolor;
    </xsl:if>
    </xsl:attribute>

    Would do it.

    FYI, the CSS3 spec calls for an :nth-child psuedo-class, which would make this definable through CSS and not require any extra markup:

    tr:nth-child(odd) {
    background-color: gray;
    }

    This is one CSS3 selector though that Mozilla doesn't support.
    (Well, nor does any other web browser in existance)
    Jason Contact Me
    Super moderator @ CodingForums

IMN logo majestic logo threadwatch logo seochat tools logo