Skip to main content

searching nodes on the basis of case insensitive string

3 replies [Last post]
rjilani
Offline
Joined: 2007-08-12
Points: 0

Hi: Gurus I am using J2SE1.5 JAXP library to search for xpath nodes. Here is my expression

"//textblocks/textblock/line/word[.='the']/attribute::*")

that searches for all the attributes of element "word" whose value is string "the". The problem is that right now my search is case sensitive. Is there any way to make this search case insensitive, and how.

Thanks,
RJ.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joehw
Offline
Joined: 2004-12-15
Points: 0

XPath 1.0 j2se1.5 supported does not support lower-case function. But you may use the translate function to achieve the same goal:
[translate(@word,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='the']

Hope that works for you.

Joe

rjilani
Offline
Joined: 2007-08-12
Points: 0

Thanks Joe I am aware of the translate function but I guess I am not an expert of xpath expression rules and how to put the translate function at the right place in the node context. I tried the following expression which means I am trying to get all the attributes of node word (word it is an element not an attribute) whose value is some string (in my case 'the' ) that is case insensitive, but the expression don't return me any value.

XPathExpression expr
= xpath.compile("//textblocks/textblock/line/word[.= translate(word,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')= 'the']/attribute::*");

Any pointers....

thanks,
RJ

rjilani
Offline
Joined: 2007-08-12
Points: 0

Never mind Joe I figured it out the right expression is

XPathExpression expr
= xpath.compile("//textblocks/textblock/line/word[translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='the']/attribute::*");

thanks for your help though.

Regards,
RJ.