473,396 Members | 1,859 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,396 software developers and data experts.

[XSLT] searchresults/exchanging background color

Hi all,

I'm writing a searchinterface on a mysql database in PHP. I retrieve
the searchoutput and write it to an XML file, which is then being
displayed in the webbrowser. I'm using XSLT to process the XML file and
to output HTML.

So far so good, but now I want to switch the background color for each
resultrow.
So resultrow 1 should have say background color white, resultrow 2
grey, resultrow 3 white again and so on.

The relevant part of my XSLT looks like this:

<table class="searchresults">
<xsl:for-each select="result/document">
<tr><td colspan="3"><strong><a href="viewfulldoc.php"><xsl:value-of
select="dossiernaam"/></a></strong></td></tr>
<tr><td colspan="3" class="preview"><xsl:value-of
select="fulltext"/></td></tr>
<tr>
<td><xsl:value-of select="documenttype"/></td>
<td><xsl:value-of select="organisatie"/></td>
<td><xsl:value-of select="invoerdatum"/></td>
</tr>
</xsl:for-each>
</table>

I'd somehow like to keep track of a rowcounter to know if it's an odd
or even row, but how would I do something like that in XSLT.
I'm obviously new to XSLT, so please bear with me. :)
Thanks in advance.

Kind regards,
Peter.

Oct 2 '05 #1
2 1106
Peter van Schie wrote:
Hi all,

I'm writing a searchinterface on a mysql database in PHP. I retrieve
the searchoutput and write it to an XML file, which is then being
displayed in the webbrowser. I'm using XSLT to process the XML file and
to output HTML.

So far so good, but now I want to switch the background color for each
resultrow.
So resultrow 1 should have say background color white, resultrow 2
grey, resultrow 3 white again and so on.

The relevant part of my XSLT looks like this:

<table class="searchresults">
<xsl:for-each select="result/document">
<tr><td colspan="3"><strong><a href="viewfulldoc.php"><xsl:value-of
select="dossiernaam"/></a></strong></td></tr>
<tr><td colspan="3" class="preview"><xsl:value-of
select="fulltext"/></td></tr>
<tr>
<td><xsl:value-of select="documenttype"/></td>
<td><xsl:value-of select="organisatie"/></td>
<td><xsl:value-of select="invoerdatum"/></td>
</tr>
</xsl:for-each>
</table>

I'd somehow like to keep track of a rowcounter to know if it's an odd
or even row, but how would I do something like that in XSLT.
I'm obviously new to XSLT, so please bear with me. :)
Thanks in advance.

Kind regards,
Peter.


It is easy,
just use the module operator,

1 mod 2 = 1
2 mod 2 = 0
3 mod 2 = 1
4 mod 2 = 0

so in your case:

<xsl:if test="(position() mod 2)=0">
- put the style here.
</xsl:if>
Hope it helps.
Oct 2 '05 #2
Thanks a lot Tjerk, I got it working using the modulo operator.

Kind regards,
Peter.

Oct 2 '05 #3

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

Similar topics

1
by: David | last post by:
I would like to be able to re-sort data in an HTML table on the without returning to the server. It seems like an XSLT should be able to accomplish this, but I can't find enough information... ...
12
by: gipsy boy | last post by:
Hello, I have sort of a big problem. I would really appreciate any help you could give me. I made a web service in C++ that throws XML to the client (browser). But, the XSLT transormation...
2
by: FrankStallone | last post by:
I am just getting started in XML and I made my first xml, dtd and xslt file and XML spy said they were all valid and they worked. This was the xslt doc that worked. <?xml version="1.0"...
6
by: kadykedar | last post by:
Hi, I want to display Image using XSLT My XML is as follow <casestudy> <Company> <companylogo>http://www.microsoft.com/casestudies/resources/Logos/4000000140.gif</companylogo> </Company>...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.