generates a table with selected elements,with the number of elements per row given in the stylesheet : table « XSLT stylesheet « XML Tutorial

XML Tutorial
1. Introduction
2. Namespace
3. XML Schema
4. XPath
5. XSLT stylesheet
Java
XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
XML Tutorial » XSLT stylesheet » table 
5. 5. 5. generates a table with selected elements,with the number of elements per row given in the stylesheet
File: Data.xml
<?xml version="1.0" encoding="utf-8"?>
<data>
  <element>Fe</element>
  <element>Cl</element>
  <element>Br</element>
  <element>I</element>
  <element>Ni</element>
  <element>H</element>
  <element>Po</element>
  <element>S</element>
  <element>O</element>
</data>
File: Transform.xslt

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
      <TABLE border="1">
        <xsl:variable name="inRow" select="3"/>
        <xsl:apply-templates select="//element[position() mod $inRow = 1]">
          <xsl:with-param name="inRow" select="$inRow"/>
        </xsl:apply-templates>
      </TABLE>
      <TABLE border="1">
        <xsl:variable name="inRow" select="4"/>
        <xsl:apply-templates select="//element[position() mod $inRow = 1]">
          <xsl:with-param name="inRow" select="$inRow"/>
        </xsl:apply-templates>
      </TABLE>
      <TABLE border="1">
        <xsl:variable name="inRow" select="5"/>
        <xsl:apply-templates select="//element[position() mod $inRow = 1]">
          <xsl:with-param name="inRow" select="$inRow"/>
        </xsl:apply-templates>
      </TABLE>
    </xsl:template>
    <xsl:template match="element">
      <xsl:param name="inRow"/>
      <TR>
        <TD>
          <xsl:value-of select="."/>
        </TD>
        <xsl:apply-templates select="following::element[position() &lt; $inRow]" mode="cell"/>
      </TR>
    </xsl:template>
    <xsl:template match="element" mode="cell">
      <xsl:param name="inRow"/>
      <TD>
        <xsl:value-of select="."/>
      </TD>
    </xsl:template>
</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?><TABLE border="1"><TR><TD>Fe</TD><TD>Cl</TD><TD>Br</TD></TR><TR><TD>I</TD><TD>Ni</TD><TD>H</TD></TR><TR><TD>Po</TD><TD>S</TD><TD>O</TD></TR></TABLE><TABLE border="1"><TR><TD>Fe</TD><TD>Cl</TD><TD>Br</TD><TD>I</TD></TR><TR><TD>Ni</TD><TD>H</TD><TD>Po</TD><TD>S</TD></TR><TR><TD>O</TD></TR></TABLE><TABLE border="1"><TR><TD>Fe</TD><TD>Cl</TD><TD>Br</TD><TD>I</TD><TD>Ni</TD></TR><TR><TD>H</TD><TD>Po</TD><TD>S</TD><TD>O</TD></TR></TABLE>
5. 5. table
5. 5. 1. Use for-each loop to output table row
5. 5. 2. Table cell format
5. 5. 3. Format table cell with choose statement
5. 5. 4. Set table cell style with choose statement
5. 5. 5. generates a table with selected elements,with the number of elements per row given in the stylesheet
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.