This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: string comparison
Hi Dan,
> I have a document made up from a collection of addresses like this:
> <address-book>
> <contact>
> <name>Dan Corneanu Cornel</name>
> .....
> </contact>
> <contact>
> <name>Florin Corneanu</name>
> ......
> </contact>
> ........
> </address-book>
>
> How can I select all the contacts which contain the string
> "corneanu" or "Corneanu" or "cOrneanu" etc. in the <name>
> child? Is there something like the 'like()' function from SQL?
You can select all the contacts whose name contains 'Corneanu' with:
/address-book/contact[contains(name, 'Corneanu')]
As you no doubt know, though, contains() is a case-sensitive function.
You make it case-insensitive by converting the name (and the string
that you're testing with) to lowercase, which you can do with the
translate() function, as follows:
/address-book/contact
[contains(translate(name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz'), 'corneanu')]
If you only test for 'Corneanu', you may as well just convert those
letters:
/address-book/contact
[contains(translate(name, 'CORNEAU',
'corneau'), 'corneanu')]
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list