1
votes

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 element, 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

1
Good question: +1. See my answer for explanation and complete solutions.Dimitre Novatchev

1 Answers

2
votes

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>