title: Using XSLT to loop through column names and bring back corresponding data
body: <p>I have a database table containing a large amount of columns, so to display them in XSLT i need to loop through all the column names and bring them back as well as displaying all the data corresponding with those column names.</p>
  
  <p></p>
  
  <pre><code>  &lt;table class="list"&gt;
      &lt;tr&gt;
        &lt;xsl:for-each select="Columns"&gt;
        &lt;th&gt;
          &lt;xsl:value-of select="Name"/&gt;
        &lt;/th&gt;
        &lt;/xsl:for-each&gt;
      &lt;/tr&gt;
  
      &lt;xsl:for-each select="Clients"&gt;
        &lt;tr&gt;
        &lt;xsl:for-each select="/List/Columns"&gt;
          &lt;xsl:variable name="var" select="Name"&gt;&lt;/xsl:variable&gt;
          &lt;td&gt;
            &lt;xsl:value-of select="$var"/&gt;|
            &lt;xsl:value-of select="/List/Clients/*[$var]"/&gt;
          &lt;/td&gt;
        &lt;/xsl:for-each&gt;
        &lt;/tr&gt;
      &lt;/xsl:for-each&gt;
  
  
    &lt;/table&gt;
  </code></pre>
  
  <p></p>
  
  <p>The Table 'Columns' brings back the column names and the table 'Clients' contains the data in each column.
  The above code successfully displays all the different column names.  But when attempted to grab the data and display it using <code>&lt;xsl:value-of select="/List/Clients/*[$var]"/&gt;</code> included in the loop only the first column data is brought back.</p>