How to dynamically generate HTML table by using XSLT?

Roseanne Zhang

Here is your simple and complete answer. There is no need to do more than one steps. You just need a little xpath trick. The output is valid xhtml as well as html.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes" />
  <xsl:template match="/items" >
      <body >
        <table border="1">
          <xsl:apply-templates />
  <xsl:template match="item[(position()-1) mod 5 = 0]" >
      <td><xsl:value-of select="@desc" /></td>
      <xsl:for-each select="following-sibling::node()[position() &lt; 5]">
        <td><xsl:value-of select="@desc" /></td>
Visit JavaChina Online