Assuming that you're looking to do a logical OR of substring containment...
First of all, this select
is likely wrong1:
<xsl:variable name="games" select="footballvolleyballchesscarrom"/>
It's looking for an element named footballvolleyballchesscarrom
. If you're trying to set games to the string footballvolleyballchesscarrom
, change it to this:
<xsl:variable name="games" select="'footballvolleyballchesscarrom'"/>
Then, use either
XSLT 1.0
<xsl:when test="contains($games,'chess')
or contains($games,'carrom')">CORRECT</xsl:when>
or
XSLT 2.0
<xsl:when test="matches($games,'chess|carrom')">CORRECT</xsl:when>
to test whether $games
contains one of your multiple substrings.
1 If you really intended to select (possibly multiple) elements from the input XML here, there is another XSLT 2.0 option for testing the selected sequence against a set of possible values. If your input XML were, say,
<games>
<game>football</game>
<game>volleyball</game>
<game>chess</game>
<game>carrom</game>
</games>
then this template,
<xsl:template match="/">
<xsl:variable name="games" select="//game"/>
<xsl:if test="$games = ('chess','carrom')">CORRECT</xsl:if>
</xsl:template>
would output CORRECT
because among the string values of the selected elements is at least one of chess
or carrom
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…