XSLT: contains for multiple strings

Aleksi Kallio

Usenet Archive
Joined
Sep 28, 2000
Messages
26
Reaction score
0
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?
 
N

nobody

Aleksi said:
<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
 

Aleksi Kallio

Usenet Archive
Joined
Sep 28, 2000
Messages
26
Reaction score
0
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top