title: xslt - get last row from a foreach loop (split into 3 columns)
body: <p>I'm looping through 1-20 <code>&lt;li&gt;</code>'s using xslt and I'm trying to figure out how to add a class to the last row of the list, when displayed in a 3 column grid type format.</p>
  
  <p>At the moment, I'm using this code to add a class of <code>col-last</code> to every 3rd column in the list.</p>
  
  <pre><code>&lt;xsl:if test="not(position() mod 3)"&gt;
    &lt;xsl:attribute name="class"&gt;col-last&lt;/xsl:attribute&gt;
  &lt;/xsl:if&gt;
  </code></pre>
  
  <p>Is there a way I can add a class of "row-last" to the last row, considering they may be 1-3 items on it?</p>
  
  <p><strong><em>Example</em></strong></p>
  
  <p><strong>4 items</strong></p>
  
  <pre><code>&lt;li&gt;Item 1&lt;/li&gt;
  &lt;li&gt;Item 2&lt;/li&gt;
  &lt;li class="col-last"&gt;Item 3&lt;/li&gt;
  &lt;li class="row-last"&gt;Item 4&lt;/li&gt;
  </code></pre>
  
  <p><strong>5 Items</strong></p>
  
  <pre><code>&lt;li&gt;Item 1&lt;/li&gt;
  &lt;li&gt;Item 2&lt;/li&gt;
  &lt;li class="col-last"&gt;Item 3&lt;/li&gt;
  &lt;li class="row-last"&gt;Item 4&lt;/li&gt;
  &lt;li class="row-last"&gt;Item 5&lt;/li&gt;
  </code></pre>
  
  <p><strong>6 Items</strong></p>
  
  <pre><code>&lt;li&gt;Item 1&lt;/li&gt;
  &lt;li&gt;Item 2&lt;/li&gt;
  &lt;li class="col-last"&gt;Item 3&lt;/li&gt;
  &lt;li class="row-last"&gt;Item 4&lt;/li&gt;
  &lt;li class="row-last"&gt;Item 5&lt;/li&gt;
  &lt;li class="row-last col-last"&gt;Item 6&lt;/li&gt;
  </code></pre>
  
  <p>Any help appreciated.</p>