html" />
开发者

Select template for execution using a condition including variable on apply-templates

I have a template that looks like below

<xsl:template match="more-info" mode="docuSection"> html </xsl:template>

and which is applied with the call

<xsl:apply-templates select="." mode="docuSection"/>

so the template is applied when the current node has more-info elem开发者_C百科ent, is there a way to make this template get applied with the same call and with the condition which includes a global variable e.g. match="$mode='edit' or more-info"

Best Regards, Keshav


is there a way to make this template get applied with the same call and with the condition which includes a global variable e.g. match="$mode='edit' or more-info"

In XSLT 2.0 this is perfectly legal:

<xsl:template match="more-info[$mode = ('edit', 'more-info')]"
mode="docuSection">

In XSLT 1.0 it is forbidden to use variable or key references within a match pattern.

However, one can use either of the following techniques:

I. Within the <xsl:apply-templates> instruction specify the exact node-list of nodes to be processed.

<xsl:apply-templates mode="docuSection" 
     select="self::*[$mode = 'edit' or $mode='more-info']" />

||. Make the match pattern more general, but do any processing within the template only if the desired condition is fulfilled:

<xsl:template match="more-info" mode="docuSection">
 <xsl:if test="$mode = 'edit' or $mode='more-info'">
    html
 </xsl:if>
</xsl:template>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜