OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   XPath case insensitive queries

[ Lists Home | Date Index | Thread Index ]

Hi all,
I have experienced troubles to make case insensitive queries against an 
XML DB that supports XQuery scripts.

I found many people had this kind of issue on this mailing list or 
elsewhere.

First I found some kind of translate function examples:
/translate(string1,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")/
This looked very ugly to me and not practical.

I found a simpler and nicer solution (I am certainly not the first one 
;-) but as I found nothing on this matter, I guess it's good to share 
the solution).
If you use the lower-case or upper-case function of XPath, you can make 
you query readable and case insensitive very easily.

*Example:*
Let's say you have an XML db like eXist in which you have store some XML 
docs.
You wish to find the doc id for which the 'indentity' node contains 
'myid' but you don't care about the case

The XML stored in the db could be something like:

/<doc id='123456'>
    <identity>myidentity</indentity>
</doc>/

Use the following XQuery script:
/for
$doc in xcollection('/db/mydb/mycollection')//*
[
contains(lower-case(identity), lower-case('mYiD'))
]
order by $doc/identity ascending
return <doc id="{$doc/@id}">{$doc/identity}</doc>
}/

The lower-case function will lower case the value of the 'indentity' 
node as well as the string I am using to do my query.
Using the contains function combined with the result of the lower-case 
will allow to find out all element that contains myid, MyId, myId or why 
not myIdentity (since myid is contained in myidentity).

Best regards,
Pierre
-- 
______________________

Pierre Martins
Mail: pierre.martins@symeria.com
Symeria (Consulting, Workflow,traceability, quality)
http://www.symeria.com 





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS