On a very basic level, you use <xsl:apply-templates>
when you want to let the processor handle nodes automatically, and you use <xsl:call-template/>
when you want finer control over the processing. So if you have:
<foo>
<boo>World</boo>
<bar>Hello</bar>
</foo>
And you have the following XSLT:
<xsl:template match="foo">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="bar">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="boo">
<xsl:value-of select="."/>
</xsl:template>
You will get the result WorldHello
. Essentially, you've said "handle bar and boo this way" and then you've let the XSLT processor handle these nodes as it comes across them. In most cases, this is how you should do things in XSLT.
Sometimes, though, you want to do something fancier. In that case, you can create a special template that doesn't match any particular node. For example:
<xsl:template name="print-hello-world">
<xsl:value-of select="concat( bar, ' ' , boo )" />
</xsl:template>
And you can then call this template while you're processing <foo>
rather than automatically processing foo
's child nodes:
<xsl:template match="foo">
<xsl:call-template name="print-hello-world"/>
</xsl:template>
In this particular artificial example, you now get "Hello World" because you've overriden the default processing to do your own thing.