can an xslt template carry both name and match attributes?
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 di开发者_高级运维rectly from <xsl:call-template name="bar"/>
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 an xsl:template element has a name attribute, it may, but need not, also have a match attribute. From W3C XSLT specification
精彩评论