Click to See Complete Forum and Search --> : Searching Element conten


MichaelF
November 17th, 2003, 01:54 PM
Hi, I'm building a simple "search" tool that allows a user to type in a term which is compared to the contents of a repeated element.

ie:

<root>
<items>
<itemname>Pencils</itemname>
<itemname>Books</itemname>
<itemname>Erasers</itemname>
</items>
</root>

I'm using the contains() function to check the text inside the elements, ie: <xsl:when test="contains(itemname, searchterm)">

If the user enters 'pencils', there is not a match due to the lowercase entry. Is there a way in XSL to ignore case or, to convert case so that the user does not need to enter capitalized words?

thanks for any ideas,

khp
November 17th, 2003, 04:24 PM
AFAIK the only way to to make a case insensitive search in xslt, is to convert both the search term and subject strings to uppercase (or lowercase), using the translate function.

http://www.w3.org/TR/xpath#function-translate

MichaelF
November 17th, 2003, 05:50 PM
thanks for the tip, khp. I took a brief look at the translate fx but I didn't see how it applied. I'll check the documentation.

thanks again!

khp
November 17th, 2003, 06:18 PM
translate(string,"abcdefghijlkmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")

translates all lower case characters in the string to upper case.