Is the following (a) allowed (b) useful
<xsl:template match="foo" name="bar">
</xsl:template>
(it means that the template could be triggered either from recursive template processing or directly from <xsl:call-template name="bar"/>
The <xsl:template> element is used to build templates. The match attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document).
XSLT Template defines a way to set rules to generate the desired Output in a proper structure for a particular context and to build a template. The template tells the XSLT processor how to format a particular output from the XML source document.
The <xsl:call-template> element calls a named template.
With <xsl:apply-templates> the current node moves on with every iteration, whereas <xsl:call-template> does not change the current node. I.e. the . within a called template refers to the same node as the . in the calling template.
Simply put, yes. I quite often name the identity template and invoke it directly using a <xsl:call-template name="identity" />
.
It's a useful tool for a form of inheritance; you can define a template to match one node, and another that handles a derivative of that node that does the specifics, then calls the more general template.
For example:
<xsl:template match="animal" name="animal">
<!-- handle any animal related stuff here -->
</xsl:template>
<xsl:template match="dog">
<xsl:call-template name="animal" />
<!-- handle any dog specific stuff here -->
</xsl:template>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With