title: Loop Through Table
body: <p>I am attempting to loop through a table by column and transform it to individual divs. Id like to have tr[1]/td[1], tr[2]/td[1], tr[3]/td[1] ... all be part of one div. Then I'd like to move on to tr[1]/td[2], tr[2]/td[2], tr[3]/td[2].</p>
  
  <p>I am able to transform my table when I use simpler code, but I'm having issues jumping down each tr row. Below is my XSLT. Any help would be great. I'm pretty new to XSLT, but not programming.  The divs/styling is simply to make the output easier to see. </p>
  
  <p><strong>XML:</strong></p>
  
  <pre><code>  &lt;table class="table-with-caption"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Column Title 1&lt;/th&gt;
        &lt;th&gt;Column Title 2&lt;/th&gt;
        &lt;th&gt;Column Title 3&lt;/th&gt;
        &lt;th&gt;Column Title 4&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tfoot&gt;
      &lt;tr&gt;
        &lt;td class="alert-info table-scroll-option" colspan="4"&gt;column&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tfoot&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;TR1, TD1&lt;/td&gt;
        &lt;td&gt;&lt;span&gt;TR1, TD2&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span&gt;TR1, TD3&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span&gt;TR1, TD4&lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;span&gt;TR2, TD1&lt;/span&gt;&lt;/td&gt;
      &lt;td&gt;Atque ab corporis modi deserunt adipisci, expedita temporibus.&lt;/td&gt;
      &lt;td&gt;Vitae, sint ullam velit accusantium, dolorum ad dolorem.&lt;/td&gt;
      &lt;td&gt;Iusto expedita minus praesentium vero voluptatum aut laboriosam.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;span&gt;TR3, TD1&lt;/span&gt;.&lt;/td&gt;
      &lt;td&gt;Consequuntur corporis quo libero fuga ducimus provident minus.&lt;/td&gt;
      &lt;td&gt;Natus reiciendis molestias earum, dolorum similique amet quasi.&lt;/td&gt;
      &lt;td&gt;Consequuntur sunt minus laudantium, magnam labore, debitis quia!&lt;/td&gt;
    &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p><strong>XSL:</strong>
      
        
          
          </p>
  
  <pre><code>    &lt;xsl:for-each select="tbody/tr[position()&amp;lt;=$count-rows]"&gt;
        &lt;xsl:variable select="1" name="counter" /&gt;
        &lt;div style="border:thin solid red; padding 5px; margin:5px;"&gt;
          &lt;xsl:for-each select="tr[$counter]/td[position() le $count-cols]"&gt;
            &lt;div style="border:thin solid blue; padding 5px; margin:5px;"&gt;
              &lt;xsl:apply-templates select="node()[name() != 'caption']|attribute()[name() != 'class' and name() != 'tfoot']" /&gt;
            &lt;/div&gt;
            &lt;xsl:with-param name="counter" select="$counter + 1"/&gt; 
          &lt;/xsl:for-each&gt;
  
        &lt;/div&gt;
      &lt;/xsl:for-each&gt;
    &lt;/div&gt;
  &lt;/xsl:when&gt;
  </code></pre>
  
  <p><strong>Expected Output:</strong></p>
  
  <pre><code>&lt;div style="border:thin solid red; padding 5px; margin:5px;"&gt;
     &lt;div style="border:thin solid blue; padding 5px; margin:5px;"&gt;TR1, TD1&lt;/div&gt;
     &lt;div style="border:thin solid blue; padding 5px; margin:5px;"&gt;&lt;span&gt;TR2, TD1&lt;/span&gt;&lt;/div&gt;
     &lt;div style="border:thin solid blue; padding 5px; margin:5px;"&gt;&lt;span&gt;TR3, TD1&lt;/span&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>