[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] XPath case insensitive queries
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@s... Symeria (Consulting, Workflow,traceability, quality) http://www.symeria.com
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|