XSLT Question (figuring out end position)
Posted on 2006-06-02
Here is what I am trying to do.
I have a grid of items. The grid is a HTML table. After every third item I use the XSLT position element and mod (if the remainder after dividing by 3 is 0) to start a new table row so that the grid never has more than three items across. The problem is that at the end of the grid I do not know what position the last element was and sometimes I am missing the one or two cells that would bring the final row to three across (if the total number of elements is not divisible by three, and I do not know the total number beforehand).
What I would like to do is have a value after the end of the for-each loop (that generates the grid) with the remainder of the final position value (after it has been divided by three).
So if the remainder is 1, then I can add two more table cells, if it is 2 then I can add one more, and if it is 0 then I can just close the table.
I tried doing this by setting a variable inside the for-each loop. But this variable is out of scope when I try accessing it outside the loop, and I can't declare a top level variable and then change the value inside the loop either.
Does anyone have any suggestions as to how to tackle this problem?
Thanks in advance for any help and or advice.