, , , , ,

Using <xsl:Apply-templates/>

Prerequisit: Please go through previous post “XSLT Startup

Using apply-templates enable us to use default templates. It also let us not to think about complex XPATH statements/ finding a complex XPATH pattern that works. Though using apply-templates cause your XSLT code to be larger but it let your code to be simple and easy to go through.

I use same example as in “XSLT-startup” post but just used another XSLT:

<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;

<xsl:template match=”/”>



<h1>Employee Listing</h1>





<xsl:template match=”employee”>

<div style=”border: 1px dashed  #66CCFF”>

<h3>Employee Id:

<xsl:value-of select=”@employeeid”/>


<xsl:apply-templates select=”firstname”/>

<xsl:apply-templates select=”lastname”/>

<xsl:apply-templates select=”homephone”/>

<xsl:apply-templates select=”notes”/>



<xsl:template match=”firstname”>

<b>First Name: </b><xsl:value-of select=”.”/>



<xsl:template match=”lastname”>


Last Name:    </b> <xsl:value-of select=”.”/>



<xsl:template match=”homephone”>


Home Phone:</b> <xsl:value-of select=”.”/>



<xsl:template match=”notes”>


Remarks:</b> <xsl:value-of select=”.”/>




Where XSLT starts with a entry templates where match=”/” and gradually apply templates that matches with the given XPATH statement for each templates.

Please notice that all the Apply-templates tags are within the <xsl:Stylesheet> tag.