Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - [XSLT] searchresults/exchanging background color >Thread Next - Re: searchresults/exchanging background color Re: [XSLT] searchresults/exchanging background colorTo: NULL Date: 10/2/2005 11:02:00 PM 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. | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
