Before I used a lot of call-template, and then said, suddenly found that apply-templates in most of the scenes than call-template easy to use, but also more secure.
For example, apply-templates can select specific node-set to match with the Select property, and if there is no such node-set, no conversion is possible, which is safer than call-template because the latter is called directly, No matter the existence of some nodes, and second, like Apply-templates and Call-template, the parameters can be accepted by <xsl:param/>, moreover, when we define multiple template, These templates can not have duplicate name, but can have duplicate match, duplicate template through priority to determine which template to use to convert, if more than one template has the same order, Then choose the one that appears last.
It seems that the apply-templates function is stronger than call-template. As far as the normal conversion I have used, it is safer to use apply-templates and more readable. However, in XSLT 1.0, it is convenient to use call-template, such as recursive invocation (Recursive function), if you want to implement functions like function in XSLT 2.0. Here is an example:
<xsl:template name= "Longest-speech" as= "element (speech)?" >
<xsl:param name= "list" as= "Element (SPEECH) *"/>
<xsl:choose>
<xsl:when test= "$list" >
<xsl:variable name= "First" select= "Count ($list [1]/line)" as= "Xs:integer"/>
<xsl:variable name= "longest-of-rest" as= "element (SPEECH)?" >
<xsl:call-template name= "Longest-speech" >
<xsl:with-param name= "list" select= "$list [Position ()!=1]"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test= "$first gt count ($longest-of-rest/line)" >
<xsl:value-of select= "$list [1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select= "$longest-of-rest"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match= "/" >
<longest-speech>
<xsl:call-template name= "Longest-speech" >
<xsl:with-param name= "list" select= "//speech"/>
</xsl:call-template>
</longest-speech>
</xsl:template>
The XML to be converted is:
<?xml version= "1.0″?>
<scene><title>scene I. Venice. A street.</title>
<stagedir>enter Roderigo and Iago</stagedir>
<SPEECH>
<SPEAKER>RODERIGO</SPEAKER>
<line>tush! Never tell me; I Take it much unkindly</line>
<line>that thou, Iago, who hast had my purse</line>
<line>as if the strings were thine, shouldst know of this.</line>
</SPEECH>
<SPEECH>
<SPEAKER>IAGO</SPEAKER>
<LINE> ' Sblood, but you'll not hear me:</line>
<line>if ever I did dream of such a matter, abhor me.</line>
</SPEECH>
etc.
</SCENE>
Sam Judson (Wrox Technical editor) has made a statement about the performance differences between using Call-template and apply-templates:
In terms of raw performance xsl:call-template was likely to being faster, as you are calling a specific named template, rather than telling the XSLT processor to pick the template which best matches.
There is certainly things you can does with xsl:call-template so can ' t do with xsl:apply-templates, such as recursive Templates which is very powerful.
Xsl:apply-templates are however the more flexible and extensible, due to their combined use of the match patterns, modes and Priorities.
I think the generalization is good, concise, so as to end it.