xsl:apply-templates vs xsl:call-template in XSLT

In XSLT stylesheet development, xsl:apply-templates and xsl:call-template are the two primary instructions used to process content and modularize code. While both execute templates, they represent two distinct programming paradigms: declarative, node-driven transformation and imperative, procedural invocation. This article breaks down the fundamental differences between xsl:apply-templates and xsl:call-template, detailing how they handle context nodes, matching rules, polymorphism, and maintainability.


Core Mechanism and Processing Model


Key Differences

1. Invocation Target

2. Context Node and Node-Set Iteration

3. Polymorphism and Loose Coupling

4. Modes and Priority Handling

5. Parameter Handling


Summary of Differences

Feature xsl:apply-templates xsl:call-template
Paradigm Declarative / Rule-driven Imperative / Procedural
Target Identifier Evaluates node patterns (match) Explicit template name (name)
Context Node Changes to each selected node Stays identical to caller’s context
Multiple Executions Automatically loops over selected nodes Executes exactly once per call
Supports Modes Yes (mode="...") No
Coupling Loose (polymorphic) Tight (static call)

When to Use Each

Use xsl:apply-templates when:

Use xsl:call-template when: