1

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

<tr>
    <td>Link1</td>
    <td>Link2</td>
</tr>
<tr>
    <td>Link3</td>
    <td>Link4</td>
</tr>

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)
{
    $i++;
    <calculate MOD of current row here>
}

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

EDIT
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:choose>
    <xsl:when test="position() mod 2 = 1">
        <tr> (this is my error line)
    </xsl:when>
</xsl:choose>

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

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

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.