469,336 Members | 5,552 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

XSLT: contains for multiple strings

I want to say something like this:

<xsl:if test="contains($my-string, {'banana', 'apple', 'lemon'})">

Ie. I want to do "contains" against many strings. I don't want to write
them all manually to condition clause, because it's cumbersome and it
would help a lot if those strings could be passed into template as a
parameter.

What would be the easiest way to do this?
Jul 20 '05 #1
2 13205
Aleksi Kallio wrote:
<xsl:if test="contains($my-string, {'banana', 'apple', 'lemon'})">
Ie. I want to do "contains" against many strings.


contains works the other way round:
contains($haystack,$needle)

to test a string against a list of strings, I use

contains('/string1/string2/string3/',concat('/',$string,'/'))
take care of delimiting your $string, otherwise "string"
would match as well.

HTH, andreas (ala_NO@SPAM_context.ch)
Jul 20 '05 #2
>><xsl:if test="contains($my-string, {'banana', 'apple', 'lemon'})">
Ie. I want to do "contains" against many strings.

to test a string against a list of strings, I use
contains('/string1/string2/string3/',concat('/',$string,'/'))
take care of delimiting your $string, otherwise "string"
would match as well.


The problem is that I really need contains (not string equality). For
example, I need to find if 'I hava a banana' contains 'banana', 'apple',
or 'lemon'.

Is it possible, or do I need some cumbersome template magic?

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Aleksi Kallio | last post: by
4 posts views Thread by David S. Alexander | last post: by
4 posts views Thread by Iain | last post: by
3 posts views Thread by shaun roe | last post: by
2 posts views Thread by Scott Sauyet | last post: by
11 posts views Thread by =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.