For comparing an xml string value against multiple strings, I am doing the following.
<xsl:if test="/Lines/@name = 'John' or /Lines/@name = 'Steve' or /Lines/@name = 'Marc' " >
Can any one tell me, instead of using 'or' in the above case, how can I check whether a string is existing in an set of strings using xslt.
Thanks.
Other possiblity:
XPath 2.0 (XSLT 2.0)
In XSLT 1.0 you have the similar function
matches
provided by EXSLT.Notice
This is not exact match against the string, but a regex match, which in your case seems appropriate anyway.
XSLT 2.0 only:
<xsl:if test="/Lines/@name = ('John', 'Steve', 'Marc')">
With XSLT 1.0 you can't write a literal expression representing a sequence of strings or a set of strings but if you know the literal values then you can construct a set of nodes e.g.
Yep - I use substring - put all your name in a string - xsl:variable - then if contains true, the name is there
e.g.
XPath has a
some $x in (1,2,..) satisfies $x>10
expression that could be useful for this. See: http://www.java2s.com/Code/XML/XSLT-stylesheet/everyandsomeoperator.htmFor space-separated words you can use
index-of(tokenize("list of allowed", "\s+"), "needle"))
ormatch
to go with regular expressions, although I am pretty sure there is something smarter than this.Three ways of doing this:
...
.2. Test against an externally passed parameter. If the parameter is not externally set, and we are using XSLT 1.0, the
xxx:node-set()
extension function needs to be used to convert it to normal node-set, before accessing its children.3. In XSLT 2.0 compare against a sequence of strings