473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

produce colors in alternate rows in the table

I want to produce colors in alternate rows in the table.

The following will produce blue color on every row. So my problem is to figure
out to count the records. If it is odd record, then do <tr bgcolor="blue">,
otherwise, don't do anything, and it will output colors in alternate
rows. I tried to use count, but doesn't work.

Any ideas? Please advise.

<xsl:for-each select="/authors/author">
<tr bgcolor="blue">
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="url"/></td>
</tr>

<authors>
<author>
<name>author1</name>
<url>http://url1.com</url>
</author>
<author>
<name>author2</name>
<url>http://url2.com</url>
</author>
<author>
<name>author3</name>
<url>http://url3.com</url>
</author>
<author>
<name>author4</name>
<url>http://url4.com</url>
</author>
</authors>
Jul 20 '05 #1
5 6409

You seem to be asking a lot of xsl questions. xsl-list (or more
particularly the xsl-list faq) might be better place to start than
c.t.x.

coloring alternate rows of a table is an explict example in the xslt
spec.

http://www.w3.org/TR/xslt#section-Co...ng-with-xsl:if

The following colors every other table row yellow:
....

David
Jul 20 '05 #2


Matt wrote:
I want to produce colors in alternate rows in the table.

The following will produce blue color on every row. So my problem is to figure
out to count the records. If it is odd record, then do <tr bgcolor="blue">,
otherwise, don't do anything, and it will output colors in alternate
rows. I tried to use count, but doesn't work.

Any ideas? Please advise.

<xsl:for-each select="/authors/author">
<tr bgcolor="blue">


Use position e.g.
<tr>
<xsl:attribute name="bgcolor">
<xsl:choose>
<xsl:when test="position() mod 2 =
0"><xsl:text>red<</xsl:text></xsl:when>
<xsl:otherwise><xsl:text>blue</xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:attribute>


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #3
Hi,

I think you should use CSS where it is possible.
It makes the whole more controllable and even smaller:

<xsl:template match="/">
<html>
<head>
<style type="text/css">
tr.r0 {background-color:red}
tr.r1 {background-color:blue}
</style>
</head>
<body>
<table>
<xsl:apply-templates select="//authors/author"/>
</table>
</body>
</html>
</xsl:template>

<xsl:template match="author">
<tr class="r{position() mod 2}">
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="url"/></td>
</tr>
</xsl:template>
regards,

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #4
You seem to be asking a lot of xsl questions. xsl-list (or more
particularly the xsl-list faq) might be better place to start than
c.t.x.


Which one do you mean? Is there a XSL newsgroup I could not find up to now
or do you mean something like http://www.mulberrytech.com/xsl/xsl-list/ ?

Regards, Winfried
Jul 20 '05 #5
Which one do you mean? Is there a XSL newsgroup I could not find up to now
or do you mean something like http://www.mulberrytech.com/xsl/xsl-list/ ?


yes http://www.mulberrytech.com/xsl/xsl-list/ and its faq at
www.dpawson.co.uk (or jeni's site at http://www.jenitennison.com/xslt)
are all good places to start.

David
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: LRW | last post by:
Is there some way to make a table have alternating colors for rows when you're generating the table data with a WHILE statement? You know, row 1 has a gray BG, row 2 is white, row 3 is gray, 4 is...
5
by: aznFETISH | last post by:
I have a list of links that I ue on my page, I alternate background colors for these links in a table, I usually do it using a DB but this list of link is manually added into the page so my...
0
by: Paolo | last post by:
Hi to all, could you please help me with this issue? I'd like to have the rows of a VB6 ADO grid bound to a db painted with an alternate background and foreground colors. I'd like to have the odd...
1
by: Newton | last post by:
I know how to alternate table row bgcolor by odd/even method but what I am trying to acheive is alternate colors by the date value in the database so that each row with the same date value has the...
4
by: sconeek | last post by:
Hi all, I am generating a html based table with multiple rows of data coming in real time from a postgres DB. The underlying technology is java based however the front end is html. now i am...
4
by: Amy | last post by:
I need some help. I have this table with alternate row colors. Class gray and class white. I have javascript that do highlight when mouseover row ... and onclick to select row and highlight it...
1
by: pradheepayyanar | last post by:
Dear All i have dynamic generation of <table> rt now i have done the <TR> with alternate colors which is a dynamic table. my requirement is that for every cumulative <tr> i need different color....
5
by: Michael R | last post by:
Searching the net I've found a simple technique to add row numbers and alternate colors (for the even and the uneven row) to a continuous form. 1st step: Create a textbox, send it to background...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.