Possible Duplicate:
XSLT expression to check if variable belongs to set of elements
Given a parameter, $name
, what is a short and clean way to check if its value is equal to one of a finite number of values?
For example, say I wanted to merge the first 3 of these when
tests because their contents were exactly the same.
<choose>
<when test="$name='Alice'">
<when test="$name='Bob'">
<when test="$name='Cindy'">
<when test="$name='Dave'">
<otherwise>
Something like test="$name in ['Alice','Bob','Cindy']"
, except actually valid :P
With XSLT 2.0 it suffices to use $name = ('Alice', 'Bob', 'Cindy')
.
Use (both in XSLT 1.0 and in XSLT 2.0):
contains('|Alice|Bob|Cindy|', concat('|', $name, '|'))
and, as Martin Honnen already mentioned, in XPath 2.0 (XSLT 2.0) only, one can simply write:
$name = ($seqOfNames)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With