XSL : Function position() and attribute

Laurent Bientz

A very simple example of use: you want to make a simple HTML table and ask a simple CSS class second line, the position () function and xsl: attribute are your friends!

Assume the following XML stream:

<?xml version="1.0" encoding="UTF-8"?>
                <name>Laurent Bientz</name>
                <name>Florian Collot</name>
                <name>Kevin Lancien</name>
                <name>Nicolas Nowak</name>
            <!-- ... -->

In XSL, the position() function returns the index (note starts with 1) of the node in the collection; xsl: attribute still allows him to dynamically create / override a previous HTML attribute.

So just test the mod to override the class every two lines:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">
    <xsl:template name="showWandiz">
        <table class="team">
            <xsl:for-each select="//View/wandiz/staff">
                <tr class="light">
                    <xsl:if test="position() mod 2 = 0"><xsl:attribute name="class">dark</xsl:attribute></xsl:if>
                    <td><xsl:value-of select="id" /></td>
                    <td><xsl:value-of select="name" /></td>


Nelsi - 2013-09-02 03:16:40
Thank you for your post about XSLT date convertions. It was very ueusfl. I was looking for a way to convert a dates without using explicit Xpath date convertion functions and you gave just that. Thank you again.
IgnacioDext - 2016-08-18 21:08:54
Lakers #24 Kobe Bryant Black/Grey Women's Fadeaway Fashion Embroidered NBA Jersey
authentic jersey wholesale
real nfl jerseys
NHL Jerseys Tampa Bay Lightning 91 Steven Stamkos Black
cheap nfl authentic jerseys wholesale
nfl jersey cheap
nfl cheap apparel
cheap team jerseys
Nike Eagles #10 DeSean Jackson White Mens NFL Elite Jersey
Majestic Athletic MLB San Francisco Giants Womens Orange Blended T-Shirt 018
Top MLB New York Yankees Snapback Hat NU27 Cheap Sale
Manchester United #5 Marcos Rojo Black Long Sleeves Soccer Club Jersey
MLB Jerseys Milwaukee Brewers 8 Ryan Braun grey
MLB Jerseys New York Mets 45 Martinez white blue stripe
PrzemekUnlip - 2017-05-24 21:13:41
Witam wszystkich :) Jako świeżak na forum postanowiłem się przywitać :)
MyronLox - 2017-11-06 12:21:53
Never know where to discover an essay writing service with on the finest top quality - Study reviews to seek out the leading good quality service with consumer-friendly.We present on the web Expert Writing Guide for Academic Writing Services at all levels - Do not get stuck together with your papers - Let us assist you.
DoyleBinna - 2017-11-20 08:31:50
пригожий веб сайт http://xdoza.com/prostitutki/
MatthewLow - 2018-03-04 05:52:28
Wonderful website, how do u find all this information?I have read a few posts on your website and I love your style. Thanks a million, keep up the great work.
IbuxaTheat - 2019-10-13 01:39:44
Hi! I could have sworn I’ve been to this blog before but after looking at
a few of the posts I realized it’s new to me. Regardless,
I’m definitely happy I came across it and I’ll be bookmarking it and checking back frequently!
RobertOliynuk - 2019-11-26 02:44:33
NXPatrick - 2019-12-27 17:01:40
Hello. And Bye.
FUBrad - 2020-01-30 14:28:30
Hello. And Bye.
MixMen - 2020-02-02 23:50:16
hi guys :). I am looking for help for me and my girl. i am from France
Darnellneoni - 2020-02-19 03:15:20
belleprots - 2020-03-01 17:22:30
Hi :). I am from Netherlands and i don't know how can i disable my signature? Regards :)
Kristinasmise - 2020-03-18 20:01:54
Quelqu'un à la maison? :)
EdwardDit - 2020-03-24 23:44:14
Hello. And Bye.



Wandi invites you to discover a new approach to navigating a website...
Are you ready?

Launch the experience