Name
<xsl:call-template>
Invokes a particular template by name. If you have output that you need to generate often, you can put the markup that creates that output into a named template and invoke that template whenever you want.
Category
Instruction.
Required Attribute
nameThe name of the template you’re invoking.
Optional Attributes
None.
Content
This element can contain any number of optional <xsl:with-param> elements.
Appears in
<xsl:call-template>
appears inside a template.
Defined in
[1.0] XSLT section 6, “Named Templates.”
[2.0] XSLT section 10.1, “Named Templates.”
Example
Invoking named templates with <xsl:call-template> is a great way to
create modular stylesheets. We’ll use named templates to format our
document of chocolate sales:
<?xml version="1.0" encoding="utf-8"?>
<!-- chocolate.xml -->
<report month="8" year="2006">
<title>Chocolate bar sales</title>
<brand>
<name>Lindt</name>
<units>27408</units>
</brand>
<brand>
<name>Callebaut</name>
<units>8203</units>
</brand>
<brand>
<name>Valrhona</name>
<units>22101</units>
</brand>
<brand>
<name>Perugina</name>
<units>14336</units>
</brand>
<brand>
<name>Ghirardelli</name>
<units>19268</units>
</brand>
</report>Here is our stylesheet with named templates:
<?xml version="1.0"?> <!-- call-template.xsl --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="report"> <html> <head> <xsl:call-template name="report-title"> <xsl:with-param name="in-heading" select="true()"/> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access