would you please explain me the difference between<xsl:apply-template> and <xsl:call-template> and when should i use <xsl:call-template> ?
thank you
would you please explain me the difference between <xsl:apply-template> and <xsl:call-template> and when should
Share
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:And you have the following XSLT:
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:
And you can then call this template while you’re processing
<foo>rather than automatically processingfoo‘s child nodes:In this particular artificial example, you now get “Hello World” because you’ve overriden the default processing to do your own thing.
Hope that helps.