473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 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 14048
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 string contains any of those names. I have this:...
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 space. ----source---- <document xmlns="..."...
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 that value to an attribute in the XML output...
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 personal information and one takes the data out of...
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 the point? Yes its got a fancy new data model...
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 working fine for selecting the services, bindings,...
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 the classification, e.g. : "John P. Jones" "Jane...
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 a string then normalizing the strings. Then I'm...
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 works fine. The problem I have is that I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.