I have a list named "Links". I want to display them in following format:


So basically I want to display 2 records per row instead of the regular one. This requires that I calculate mod of current records being displayed. But I don't know how to get record number while looping records. In PHP I would normally do like this:

$i = 0;

while (looping through records)
    <calculate MOD of current row here>

But how do I do the same in XSL in SharePoint?

I have hit a snag. This is what my code looks like but I am getting error.
Basically it is not accepting only "tr" and it also expects closing "/tr" but if I write that in first WHEN condition then my logic won't work. So any other logic to make it work?

    <xsl:when test="position() mod 2 = 1">
        <tr> (this is my error line)

<td>rest of my code will come here</td>

    <xsl:when test="position() mod 2 = 0">

Ok I got it. This is how you do it:

<xsl:value-of select="position() mod 2">
  • Please check my edit above which I wrote after this answer. – Frank Martin Aug 2 '13 at 2:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.