Does contains()
work for multiple words stored in a variable? Will the below one work? If it won't work, please help me with a solution.
<xsl:variable name="games" select="footballvolleyballchesscarrom"/>
<xsl:when test="contains($games,'chess,carrom')">CORRECT</xsl:when>
Assuming that you're looking to do a logical OR of substring containment...
First of all, this
select
is likely wrong1:It's looking for an element named
footballvolleyballchesscarrom
. If you're trying to set games to the stringfootballvolleyballchesscarrom
, change it to this:Then, use either
XSLT 1.0
or
XSLT 2.0
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,
then this template,
would output
CORRECT
because among the string values of the selected elements is at least one ofchess
orcarrom
.I think multiple variables will not work with contains method. As per the defination:
str1 : A string that might contain the second argument. str2: A string that might be contained in the first argument.
Refer : https://msdn.microsoft.com/en-us/library/ms256195(v=vs.110).aspx
You can use or operator: