HTML Table with Dynamic Columns

  • Thread starter Thread starter Fresh Air Rider
  • Start date Start date
F

Fresh Air Rider

Hello

Does anyone know how to display data from a data source such as an
array or SqlDataReader etc within an HTML table whose number of
columns can change according to the value of a variable ?

This is one thing that XSL is brilliant at but I can't find a nice
..Net solution

The following is how it can easily be achieved in XSL.

-------- XML file -------------

<root>
<letter>a</letter>
<letter>b</letter>
<letter>d</letter>
<letter>c</letter>
<letter>f</letter>
<letter>e</letter>
<letter>g</letter>
<letter>h</letter>
<letter>i</letter>
</root>

------- XSL file --------------

<xsl:template match="root">
<xsl:variable name="columns" select="6" />
<TABLE>
<xsl:for-each select="letter[position() mod $columns = 1]">
<TR>
<xsl:for-each select=".|following-sibling::letter[position()
&lt; $columns]">
<TD>
<xsl:value-of select="." />
</TD>
</xsl:for-each>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
 
Back
Top