XSLT: contains for multiple strings

Discussion in 'XML' started by Aleksi Kallio, Aug 8, 2003.

  1. 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?
     
    Aleksi Kallio, Aug 8, 2003
    #1
    1. Advertising

  2. Aleksi Kallio

    nobody Guest

    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)
     
    nobody, Aug 11, 2003
    #2
    1. Advertising

  3. >><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?
     
    Aleksi Kallio, Aug 11, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Dyer
    Replies:
    5
    Views:
    676
  2. Dylan Phillips
    Replies:
    0
    Views:
    377
    Dylan Phillips
    Nov 13, 2003
  3. Replies:
    2
    Views:
    735
    Henry S. Thompson
    Oct 19, 2005
  4. jt
    Replies:
    13
    Views:
    745
    Gregory Pietsch
    Sep 28, 2005
  5. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    802
    Malcolm
    Jun 24, 2006
Loading...

Share This Page