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" >
    <html>
      <body >
        <table border="1">
          <xsl:apply-templates />
        </table>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="item[(position()-1) mod 5 = 0]" >
    <tr>
      <td><xsl:value-of select="@desc" /></td>
      <xsl:for-each select="following-sibling::node()[position() &lt; 5]">
        <td><xsl:value-of select="@desc" /></td>
      </xsl:for-each>
    </tr>
  </xsl:template>
</xsl:stylesheet>
Visit JavaChina Online
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact