XSLT: contains for multiple strings

A

Aleksi Kallio

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 (ala_NO@SPAM_context.ch)
 
A

Aleksi Kallio

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top