Subject: Re: Alternating Between Values From: "Steve Muench" <smuench@xxxxxxxxxxxxx> Date: Wed, 17 May 2000 07:55:23 -0700 |
| 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Alternating Between Values, Stallion, Jason (Cah | Thread | Re: Alternating Between Values, David Carlisle |
Alternating Between Values, Stallion, Jason (Cah | Date | Re: Alternating Between Values, David Carlisle |
Month |