Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [XSLT] searchresults/exchanging background color

From: Tjerk Wolterink <tjerk@------------------.--->
To: 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.


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent