Learn XML, XSLT, XPath with Tutorials & Samples


xsl:apply-templates
XML XSL

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="myFile.xslt"?>

<store>

  <book id="1">
    <title>XML</title>
    <author>Bill</author>
    <price>25.50</price>
  </book>

  <book id="2">
    <title>XSL</title>
    <author>Vijay</author>
    <price>75.60</price>
  </book>

  <book id="3">
    <title>HTML</title>
    <author>Kris</author>
    <price>50.40</price>
  </book>

</store>

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>

  <xsl:template match="/">
    <html>
      <body>
        <table border="1" >
          <tr>
            <th>No</th>
            <th>Title</th>
            <th>Author</th>
            <th>Price</th>
          </tr>
          <xsl:apply-templates/>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="book">
    <tr>
      <td>
        <xsl:number/>
      </td>
      <xsl:apply-templates/>
    </tr>
  </xsl:template>

  <xsl:template match="title  | author | price">
    <td>
      <xsl:value-of select="."/>
    </td>
  </xsl:template>

</xsl:stylesheet>
Example : 1 | 2 | 4

OutPut:

No Title Author Price
1 XML Bill 25.50
2 XSL Vijay 75.60
3 HTML Kris 50.40