472,353 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 13801
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Aleksi Kallio | last post by:
I'm passing a result tree fragment that holds multiple strings (fieldnames, in this case) and in the called template I wan't to test if a certain...
4
by: cyclops | last post by:
I'm trying to do XML + XSLT -> Another XML. The source XML contains multiple namespaces and XSLT will handle all possible tags under each name...
4
by: David S. Alexander | last post by:
How can I do simple subtraction in an XSLT. I want to read a few attribute values from an XML document, calculate their difference, and transform...
4
by: Iain | last post by:
Hi all, I am try to split the some data out of a nested xml file and get all the data in one new xml file. I have two XSLT files one takes the...
3
by: shaun roe | last post by:
mild rant follows Working now for a couple of years with xslt and now xslt 2.0, does anyone else get the impression that xslt 2.0 somehow missed...
2
by: Scott Sauyet | last post by:
I'm trying to select a subset of a WSDL document using XSLT and a simple text document describing the high-level elements to include. I have it...
9
by: | last post by:
I am interested in scanning web pages for content of interest, and then auto-classifying that content. I have tables of metadata that I can use for...
11
by: =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post by:
Context: I'm trying to compare XML tree fragments and I'm doing so by outputting the attributes of each element in the tree and outputting it to...
2
by: groo78 | last post by:
Hi, I have an XML document that I need to convert to XHTML and I would like to use XSLT. I have attempted transformations using javascript and it...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.