By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,463 Members | 2,954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,463 IT Pros & Developers. It's quick & easy.

produce colors in alternate rows in the table

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a

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

P: n/a


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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.