Connecting Tech Pros Worldwide Forums | Help | Site Map

xpath substring with case insensitivity

rhitam30111985's Avatar
Member
 
Join Date: Aug 2007
Location: bangalore, india
Posts: 111
#1: Mar 4 '09
Hi all , i need some validation

I have an xml like this :

Expand|Select|Wrap|Line Numbers
  1. <root>
  2.     <url newurl="aTom Bomb" />
  3.     <url newurl ="tOm and Jerry" />
  4.     <url newurl ="TomBoy" />
  5.     <url newurl ="Random string" />
  6. </root>
Now , my aim is to select all the url elements where the newurl attribute contains the word "tom" despite the case. I am using the xpath like this :


Expand|Select|Wrap|Line Numbers
  1. var String ="TOM";
  2. var  xpath = "//url[contains(translate(@newurl, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'" +  String.toLowerCase()+"')]";
  3.  
  4.  
I am not sure since sometimes it returns correct result and sometime it doesnt ...

Would appreciate any help.

Moderator
 
Join Date: Mar 2006
Posts: 1,103
#2: Mar 4 '09

re: xpath substring with case insensitivity


Could you post examples of when it returns the correct result and when it doesn't? Can't see anything immediately wrong with what you've provided.
Reply


Similar XML bytes