Skip to main content

Alternative row colours in XSL

In the same project as before, my search results are being presented in a table.  The issue here, is that I want to have a different background colour for an alternate for the purpose of easy readability.

Luckily, XSL saves the day with the position() function.  This is really handy for obtaining your current index when in a loop.  Just as with using any other server side language you want to mod 2 the position to identify the alternate row:

<xsl:if test="position() mod 2 ='1'">
    <xsl:attribute name="class">rowA</xsl:attribute>
</xsl:if>


For a quick reminder of the modulus operation (mod): when applying the arithmetic on an even number it, correctly returns 0.  When applying to an uneven number, such as 5, it will return the value 1.  1 denotes that there is a remainder.

The purpose of xsl:attribute is to apply XML/XSL to an attribute of a HTML tag.  In this case I want to apply a CSS style to the table row (tr), to keep separation of design and content in the resulting HTML.





Blogged with Flock

Comments

Popular posts from this blog

Open Source alternatives to Adobe Creative Suite

With the take over of Macromedia by Adobe, they have increased their arsenal of design packages, as well as the price. No-one can do pretty much without the popular package of Photoshop for their images, and Dreamweaver for websites, especially aspiring design students who do not have much money. Nevertheless, open source software has come to save the day. What is open source software? In a nutshell it is free software with its source-code freely available to those who would like to expand or improve on the software. To expand further, anyone who’s tinkered with the source code such as optimisation or additional functionality can resubmit it back to the holders and let others enjoy the fruits of your labour. I have trawled through the World Wide Web to find out how everyone can benefit from Open Source to build up their own studio and compete against Adobe Creative Suite. All this for free, apart from the cost of the Internet. I am planning to have a facility where you can purchase...

Will we ever get Dreamweaver on Linux?

I have been a keen user of Ubuntu for some time now, and have to admit that this distribution has improved by leaps and bounds. However, what I do honestly miss on windows is... Dreamweaver. Some will swear by it, some will swear at the mention of its name. But for me, it is a very powerful tool when used correctly. Such a very popular and powerful web design and development tool is available on Windows and Mac OS, but not Linux. If you would just consider, Adobe has already supported the platform with their Adobe Reader and Adobe Air. Why is Dreamweaver not available? It just seems that there's not such a huge call for it so they just don't see the need to put in an effort for another platform. One chap at Adobe suggested to use Dreameaver under wine , but it doesn't work so great. There is an alternative to wine which, according to a user on the forums, works flawlessly - Crossover . However, the former option is not free, so some may be dissuaded where they woul...

New Ray, Blue Year

Happy New Year! I've had a hectic start to the New Year trying to fulfill my New Year's Resolution. Remembering to keep promises I've made to the family. I never realised I had a long list. What am I using to achieve this? The most underused program in a Smartphone... the To-Do List. Yes, it is underused and it exists on virtually all the current phones in the market. It is such a simple program and I intend on using till my fingers run out of blood. Probably won't happen, but nevertheless. However, the news for the beginning of the year goes to Blue Ray. Previously the HD war was leaning towards HD DVD, with the XBox 360 adding support to it. Only recently did Paramount announce that they intend on dropping support for HD DVD, along with Dreamworks and Disney. So if you're intending on getting the PS3 go ahead. It's still cheaper than buying a separate Blue Ray player.