[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XPath case insensitive queries

  • To: xml-dev@l...
  • Subject: XPath case insensitive queries
  • From: Pierre Martins <pierre.martins@s...>
  • Date: Sun, 20 Mar 2005 11:08:54 +0100
  • User-agent: Mozilla Thunderbird 0.8 (Windows/20040913)

xpath case insensitive
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!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.