About the select attribute in apply-templates
I have a question about how to use the select attribute in apply-templates.
When I write this: <ul>&l开发者_StackOverflow社区t;xsl:apply-templates select="authors/author" /></ul>
, what does it mean? Does it mean that it should apply a template where the author nodes are children of the authors node which is a child of the current node?
Following template rule:
<xsl:template match="author">
<li><xsl:value-of select="."/></li>
</xsl:template>
Does it mean that it should apply a template where the author nodes are children of the authors node which is a child of the current node?
Exactly.
Well, even more exatcly: It means the XSLT processor should apply templates to all <author>
nodes who are children of all <authors>
nodes who are children of the current node.
If there are mutliple templates that can match an <author>
, the XSLT processor will decide which template to apply. For example:
<xsl:template match="author[not(@country = 'USA')]">
<!-- will execute for any non-U.S. authors, specifically -->
</xsl:template>
<xsl:template match="author">
<!-- will execute for all other authors -->
</xsl:template>
精彩评论