Alternating table row colors WITHOUT using position()

Discussion in 'XML' started by Ralph Snart, Aug 1, 2003.

  1. Ralph Snart

    Ralph Snart Guest

    Is there a way to alternate table row colors without using the
    position() mod 2 trick? I'm in a series of nested xsl:for-each
    elements, about 3 deep, and I want to alternate the table row
    color all the way through. position() resets to 1 whenever
    the inner for-each loops around, of course.

    Example code:

    <xsl:for-each select="/games/game[count(. | key('platforms', platform)[1]) = 1]">
    <xsl:sort select="platform"/>
    <xsl:variable name="platform" select="platform"/>
    <xsl:for-each select="/games/game[date = $date][region = $region][platform = $platform]">
    <xsl:sort select="title"/>
    <tr class="???????" bgcolor="???????">
    <td>
    <xsl:choose>
    <xsl:when test="position() = 1"><xsl:value-of select="platform"/></xsl:when>
    <xsl:eek:therwise>&nbsp;</xsl:eek:therwise>
    </xsl:choose>
    </td>
    <td><a href="{path}/data/{id}.html"><xsl:value-of select="title"/></a></td>
    <td><xsl:value-of select="genre"/></td>
    </tr>
    </xsl:for-each>
    </xsl:for-each>

    -rs-
     
    Ralph Snart, Aug 1, 2003
    #1
    1. Advertising

  2. This can be done in two steps:

    Step1:

    <xsl:variable name="vrtfMyRows">
    <!-- All your processing here but not creating the table -->

    > <xsl:for-each select="/games/game[count(. | key('platforms', platform)[1])

    = 1]">
    > <xsl:sort select="platform"/>
    > <xsl:variable name="platform" select="platform"/>
    > <xsl:for-each select="/games/game[date = $date][region =

    $region][platform = $platform]">
    > <xsl:sort select="title"/>

    <xsl:copy-of select="."/>
    > </xsl:for-each>
    > </xsl:for-each>


    </xsl:variable>

    Step2:

    <xsl:for-each select="ext:node-set($vrtfMyRows)/*">
    <!-- Produce the table with alternating rows using position() mod 2 -->
    </xsl:for-each>



    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL





    "Ralph Snart" <> wrote in message
    news:...
    > Is there a way to alternate table row colors without using the
    > position() mod 2 trick? I'm in a series of nested xsl:for-each
    > elements, about 3 deep, and I want to alternate the table row
    > color all the way through. position() resets to 1 whenever
    > the inner for-each loops around, of course.
    >
    > Example code:
    >
    > <xsl:for-each select="/games/game[count(. | key('platforms', platform)[1])

    = 1]">
    > <xsl:sort select="platform"/>
    > <xsl:variable name="platform" select="platform"/>
    > <xsl:for-each select="/games/game[date = $date][region =

    $region][platform = $platform]">
    > <xsl:sort select="title"/>
    > <tr class="???????" bgcolor="???????">
    > <td>
    > <xsl:choose>
    > <xsl:when test="position() = 1"><xsl:value-of

    select="platform"/></xsl:when>
    > <xsl:eek:therwise>&nbsp;</xsl:eek:therwise>
    > </xsl:choose>
    > </td>
    > <td><a href="{path}/data/{id}.html"><xsl:value-of

    select="title"/></a></td>
    > <td><xsl:value-of select="genre"/></td>
    > </tr>
    > </xsl:for-each>
    > </xsl:for-each>
    >
    > -rs-
     
    Dimitre Novatchev, Aug 2, 2003
    #2
    1. Advertising

  3. Ralph Snart

    Ralph Snart Guest

    On Sat, 2 Aug 2003 12:15:40 +0200, Dimitre Novatchev <> wrote:
    ><xsl:for-each select="ext:node-set($vrtfMyRows)/*">


    is it possible to do this without ext:node-set? i use sablotron which doesn't
    support that extension.

    -rs-
     
    Ralph Snart, Aug 3, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    5
    Views:
    1,786
    Eliyahu Goldin
    Jul 13, 2006
  2. AAaron123

    TreeNode colors come from anchor colors

    AAaron123, Aug 7, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    561
    darrel
    Aug 7, 2008
  3. ZelluX
    Replies:
    3
    Views:
    1,960
    Peter Otten
    Dec 1, 2008
  4. NancyASAP

    alternating item style in template row with table tags

    NancyASAP, Jul 12, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    197
    Fiaz Ali Saleemi
    Jul 14, 2005
  5. Newton

    Alternating table background colors

    Newton, Jun 12, 2004, in forum: ASP General
    Replies:
    1
    Views:
    157
    Roji. P. Thomas
    Jun 12, 2004
Loading...

Share This Page