Quick References
      ADO
      ASP
      CSS2
      HTML
      JavaScript
      Jet SQL
      VBScript
      WML
      WMLScript
      WSH
      XHTML
      XML DOM
      XSLT

Features
      Knowledge Base
      Tutorials

Partners
     ZVON.ORG
     XML
     Planet Source Code
     VisualBuilder
     Web Design
     Your HTML Source
     XML/XSLT Forums
     ASPAlliance
     Scripts
     
     Programmers Heaven
     Tek-Tips Forums
     Developer Fusion
     Code Project


   







ELEMENT:  xsl:call-template

<xsl:call-template
  name="qname"
>
</xsl:call-template>

 
The xsl:call-template element is used to invoke a template by name. By invoke, we mean that the named template is called and applied to the source document. If a template does not have a name, it cannot be called by this element.
 
The xsl:template element is used to create a template. You can name a template by using the name attribute of the xsl:template element. Further, the name called by the mandatory name attribute of the xsl:call-template element must match the name specified by the name attribute of the xsl:template element. Complicating matters is the fact that a template is not required to have a name. A template is only required to have either a name or match attribute. (It can have both.) Ideally, each template will have a unique name. However, if a name is repeated, then the two templates must have a different import precedence (refer to the xsl:import element), otherwise it is an error.
 
An xsl:call-template element cannot directly return a result. You need to enclose the xsl:call-template element inside an xsl:variable element which serves as the current output destination (see code example).
 
The xsl:call-template element can contain zero or more xsl:with-param elements. It cannot contain any other XSLT elements. These xsl:with-param elements will only be evaluated if there is a matching xsl:param element in the template being called. If there is no such match, then the xsl:with-param element is simply ignored.
 
This is not a self-closing element. The separate closing element is mandatory.
 
name="qname"
 
The mandatory name attribute is the unique qname of the template that you wish to invoke. A qname is a qualified name that is composed of an optional namespace prefix, a colon which is only present if there is a prefix, and a mandatory XML name (for example, xsl:zipcode or zipcode). This name must match the name used by the name attribute of the xsl:template element that was used originally to create the template.
 
We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_calltemplate.xsl"?>
and we name it: xslt_example_calltemplate.xml
 
Code for xslt_example_calltemplate.xsl:
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:variable name="hoo">
<html>
<body>
<xsl:call-template name="boo">
<xsl:with-param name="name" />
<xsl:with-param name="dob" />
</xsl:call-template>
</body>
</html>
</xsl:variable>

<xsl:template name="boo" match="/">
<xsl:param name="name" />
<xsl:param name="dob" />
<xsl:for-each select="devguru_staff/programmer">
<div>
NAME: <xsl:value-of select="name" />
<br />
DOB: <xsl:value-of select="dob" />
<hr />
</div>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

 
Output:
 
Click to view output in separate window - requires Internet Explorer

 
 


Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information