非常重要:只要是select或match,其节点关系跨模板后都是可以继承的
什么时候用
select当需要选取节点或者节点属性进行匹配,或者获取属性值,变量值的时候
1、节点(模板调用)
<xsl:apply-templates select="fpage | lpage" mode="content"/>
2、满足某个条件的节点(模板的定义中,for-each等)
<xsl:template match="trans-title-group" mode="content">
<xsl:if test="trans-title[@xml:lang='en']">
<ArticleTitle>
<xsl:apply-templates select="trans-title[@xml:lang='en']"/>
</ArticleTitle>
</xsl:if>
</xsl:template>
3、获取属性值
<xsl:variable name="pub-id-type" select="@pub-id-type"/>
4、获取变量值
<xsl:variable name="pub-id-type" select="@pub-id-type"/>
<xsl:if test="($pub-id-type = 'pii') or ($pub-id-type = 'doi')">
<ELocationID>
<xsl:attribute name="EIdType">
<xsl:value-of select="$pub-id-type"/>
</xsl:attribute>
<xsl:apply-templates/>
</ELocationID>
</xsl:if>
match匹配模板中select选取的节点(会自动忽略条件)
<!--AuthorList-->
<xsl:template match="contrib-group" mode="content">
<xsl:apply-templates select="contrib" mode="content"/>
</xsl:template>
<xsl:template match="contrib" mode="content">
<xsl:if test="name-alternatives/name/given-names and name-alternatives/name/surname">
<Author>
<xsl:apply-templates select="name-alternatives/name" mode="name"/>
<xsl:apply-templates select="xref[@ref-type='aff']" mode="aff"/>
</Author>
</xsl:if>
</xsl:template>
用在哪儿
select出现在
- 调用模板 apply-templates
- 遍历节点 for-each
<!--AuthorList-->
<xsl:template match="contrib-group" mode="content">
<xsl:apply-templates select="contrib" mode="content"/>
</xsl:template>
<xsl:template match="contrib" mode="content">
<xsl:if test="name-alternatives/name/given-names and name-alternatives/name/surname">
<Author>
<xsl:apply-templates select="name-alternatives/name" mode="name"/>
<xsl:apply-templates select="xref[@ref-type='aff']" mode="aff"/>
</Author>
</xsl:if>
</xsl:template>
match出现在template定义(一般都在会被apply-templates调用的模板中,call-template调用的模板只用name参数来实现)
<!--Language-->
<xsl:call-template name="language"/>
<!--Language-->
<xsl:template name="language">
<xsl:choose>
<xsl:when test="($upper-local-language = 'EN')">
<Language>
<xsl:text>EN</xsl:text>
</Language>
<Language>
<xsl:value-of select="$upper-other-language"/>
</Language>
</xsl:when>
<xsl:when test="($upper-other-language = 'EN')">
<Language>
<xsl:text>EN</xsl:text>
</Language>
<Language>
<xsl:value-of select="$upper-local-language"/>
</Language>
</xsl:when>
<xsl:otherwise>
<Language>
<xsl:value-of select="$upper-local-language"/>
</Language>
<Language>
<xsl:value-of select="$upper-other-language"/>
</Language>
</xsl:otherwise>
</xsl:choose>
</xsl:template>