[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Alternating table row colors with recursion

Subject: Re: Alternating table row colors with recursion
From: "Steve Muench" <Steve.Muench@xxxxxxxxxx>
Date: Tue, 28 Nov 2000 11:37:52 -0800
css alternating table row colors
I recently had a similar problem whose solution worked
for me, but is not necessarily the most performant option
available. It might get some other thoughts spinning though
so here goes...

I have a requirements document like this:

   <reqs>
     <req title="ta">
       <req title="xy"/>
       <req title="zz">
         <req title="pp"/>
       </req>
     </req>
     <req title="qq">
       <req title="bb">
         <req title="mm"/>
         <req title="jj"/>
       </req>
       <req title="ww"/>
     </req>
   </reqs>

Which I wanted to print out with a global-alternating
row colors for rows like:

Color Text
----- ---------------------------
[0]   1. ta
[1]      1.1 xy
[0]      1.2 zz
[1]          1.2.1 pp
[0]   2. qq
[1]      2.1 bb
[0]          2.1.1 mm
[1]          2.1.2 jj
[0]      2.2 ww

I didn't want the coloring to *restart* with each
subnode's children list.

I used a brute-force approach of doing:

  <xsl:variable name="global-position"
                select="count(preceding::req) +
                        count(ancestor::req)  + 1"/>

which gave me the overall effective linear "row number"
regardless of the level of the tree, and then I used
the standard:

   <tr class="c{$global-position mod 2}">

to create <table> rows whose CSS class name alternates
between "c0" and "c1" for the even and odd colors.

This counting approach was just what I thought of, but
you might also use the output of <xsl:number> for
the current <req> and do some kind of calculation
on the "2.1.2" value to derive the relative row 
number without counting again (but I haven't thought 
that one through yet)

______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG
Author "Building Oracle XML Applications", O'Reilly
http://www.oreilly.com/catalog/orxmlapp/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.