Subject: Re: string comparison
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 6 Jun 2002 12:13:25 +0100
|
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
| Current Thread |
- RE: James Clark on Schema, (continued)
- Michael Kay - Thu, 6 Jun 2002 04:30:11 -0400 (EDT)
- David Carlisle - Thu, 6 Jun 2002 05:38:31 -0400 (EDT)
- Ranjith Kodikara - Thu, 6 Jun 2002 06:27:38 -0400 (EDT)
- Corneanu Dan - Thu, 6 Jun 2002 06:49:43 -0400 (EDT)
- Jeni Tennison - Thu, 6 Jun 2002 07:22:51 -0400 (EDT) <=
- Joerg Heinicke - Thu, 6 Jun 2002 06:49:59 -0400 (EDT)
- Agnes Kielen - Thu, 6 Jun 2002 10:19:28 -0400 (EDT)
- Ranjith Kodikara - Thu, 6 Jun 2002 22:46:08 -0400 (EDT)
- Michael Kay - Thu, 6 Jun 2002 10:06:33 -0400 (EDT)
|
|