Batch-Processing Nodes : Introduction « XSLT stylesheet « XML Tutorial






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