Batch-Processing Nodes : Introduction « 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 » Introduction 
5. 1. 6. Batch-Processing Nodes
The xsl:for-each element processes all the nodes in the same way, one after the other. 
 
File: Data.xml

 
<?xml version="1.0"?>
<employees>
  <animal>
    <name language="English">T1</name>
    <name language="Latin">T2</name>
    <projects>
      <project>project1</project>
    </projects>
  </animal>
</employees>

File: Transform.xslt

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:template match="animal">
    <paragraph align="center">
      <br />
      <font size="+3">
        <xsl:apply-templates select="name" />
      </font>
    </paragraph>

    <table width="100%" border="2">
      <tr>
        <td>Subspecies</td>
        <td>Region</td>
        <td>Number</td>
        <td>As Of</td>
      </tr>

      <xsl:for-each select="subspecies">
        <tr>
          <td>
            <xsl:apply-templates select="name" />
          </td>
          <td>

            <xsl:value-of select="region" />
          </td>

          <td>
            <xsl:value-of select="population" />
          </td>

          <td>
            <xsl:value-of select="population/@year" />
          </td>
        </tr>

      </xsl:for-each>

    </table>
  </xsl:template>

</xsl:stylesheet>
Output:

<?xml version="1.0" encoding="UTF-8"?>
  <paragraph align="center"><br/><font size="+3">T1T2</font></paragraph><table width="100%" border="2"><tr><td>Subspecies</th><td>Region</th><td>Number</th><td>As Of</th></tr></table>
5. 1. Introduction
5. 1. 1. With XSL you can modify any source text and produce different output from the same source file
5. 1. 2. Every XSL stylesheet must start with xsl:stylesheet element
5. 1. 3. "xsl:template xsl:value-of"
5. 1. 4. "xsl:value-of xsl:apply-templates"
5. 1. 5. Insert html tags into template
5. 1. 6. Batch-Processing Nodes
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.