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

Re: Alternating Between Values

Subject: Re: Alternating Between Values
From: "Steve Muench" <smuench@xxxxxxxxxxxxx>
Date: Wed, 17 May 2000 07:55:23 -0700
css class in use
| Is it possible to express, in XSL-T, alternate colors on TABLE rows?
| 
| Does anyone have any tips for adding a background color to every *alternate*
| TABLE row in the result tree?

There are lots of ways to do this, but the one I've settled
on in the XSLT-driven database apps I build is the following:

(1) I create a CSS Stylesheet containing two CSS classes
    like "row0" and "row1" as follows (I shorten to "r0" and "r1"):

    # My CSS File named "Something.css"
    .r0 {background-color: #f9f9f9}
    .r1 {background-color: #f7f7e7}

(2) I create an XSLT stylesheet that creates an HTML page
    that links to this Something.css stylesheet:

    <!-- Root template of my stylesheet -->
    <xsl:template match="/">
      <html>
        <head>
           <title>Cool XSLT App</title>
           <link rel="stylesheet" type="text/css" href="Something.css"/>
        </head>
        <body><xsl:apply-templates/></body>
      </html>
    </xsl:template>

(3) In my template that is creating HTML table rows, I
    use an attribute value template to alternate the
    *name* of the CSS class in use for that row to
    "toggle" between the names "r0" for even rows and
    "r1" for odd rows...

    <!-- Match a row of database query query results in XML -->
    <xsl:template match="ROW">
      <tr class="r{position() mod 2}">
        <xsl:apply-templates/>
      </tr>
    </xsl:template>

The expression {position() mod 2} will alternate
between the values 1 and 0 so the effective value
of the "class" attribute on the <tr> element I'm 
creating is "r1" and "r0".

This way, I can control the fonts/colors of my entire
site by touching a single CSS file, while XSLT takes
care of all the fancy stuff.

______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
Business Components for Java & XSQL Servlet Development Teams
Oracle Rep to the W3C XSL Working Group


 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.