Solved

Case Insensitive search using XPath

Posted on 2006-10-31
22
296 Views
Last Modified: 2012-05-05
I am trying to make the search case insensitive

existing snippet:
if (frmMain.txtName.value)
{
query += "@Name='" + frmMain.txtName.value + "'";
}

I modified the code as below


if (frmMain.txtName.value)
{
query += "translate(@Name,'ABC','abc')='" + frmMain.txtName.value.toLower() + "'";
}

it does not seem to work.  

what i am missing in the above code

any help would be appreciated.
anagm
0
Comment
Question by:anagm
  • 12
  • 8
  • 2
22 Comments
 

Author Comment

by:anagm
ID: 17844605
I tried like this:

if (frmMain.txtName.value)
{
query += ["translate(@Name,'ABC','abc')='" + frmMain.txtName.value + "'"];
}

i get an error:
msxml3.dll: Unknown method.

//Property[-->translate(@<--Name,'ABC','abc')='liberty' and so on ....
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17844616
try

query +="frmMain.txtName.value.toLower() = translate(@Name,'ABC','abc')";

or

query += [Name = translate(frmMain.txtName.value.toLower() , 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')]";

0
 
LVL 35

Expert Comment

by:YZlat
ID: 17844619
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 9

Expert Comment

by:owenli27
ID: 17844628
What if you have upper case 'D', 'E'... ?    
Does translate(@Name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') work?
0
 

Author Comment

by:anagm
ID: 17844708
Right now if i give as string for example 'NEBRASKA' . It gives me a single record from the database.  But if i give 'nebraska' then it does not give me any record.

I want that to be case insensitive like for example
whether i give 'NEBRASKA'  or 'nebraska'.  

I should get a record from the database.

so,  owenli27

Should i try with all the alphabets in the translate function?

translate(@Name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')



YZlat,  i am still trying your solution






0
 
LVL 9

Expert Comment

by:owenli27
ID: 17844819
is that JavaScript or VB?
It should be toLower() Or toLowerCase()
0
 

Author Comment

by:anagm
ID: 17844877
owenli27 , it is javascript
0
 

Author Comment

by:anagm
ID: 17845136
YZlat,  the 'Name' field is associated with some other business logic.

Now i am trying for 'Code' field, which is txtCode

for the below code
if (frmMain.txtCode.value)
{
if (code.substr(0, frmMain.txtCode.value.length) == frmMain.txtCode.value)
{
//logic
}

I am giving the Code, which is txtCode as 'YZLAT' and i get a record

but if i give 'yzlat' it gives me a message saying, 'no records are found'

i want to make this case insensitive,

YZlat, i need some more help please

anagm
0
 
LVL 9

Expert Comment

by:owenli27
ID: 17845189
Your database may store data with all upper case.  If so, you need to do translation to upper case, something like:
query += "translate(@Name,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + frmMain.txtName.value.toUpperCase() + "'";
0
 

Author Comment

by:anagm
ID: 17845322
yes, you are right.  in the database the 'name' is in the upper case

so i will be using as follows for 'Name'

query += "translate(@Name,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + frmMain.txtName.value.toUpper() + "'";

Can i get some help for the 'Code' field

below is the code:

if (frmMain.txtCode.value)
{
if (code.substr(0, frmMain.txtCode.value.length) == frmMain.txtCode.value)
{
//logic
}


how can i make this case insensitive.  
the 'Code's are in the upper case in the database too

any help would be greatly appreciated
anagm

0
 
LVL 9

Expert Comment

by:owenli27
ID: 17845505
Try this to see if it work.
if (code.toUpperCase().substr(0, frmMain.txtCode.value.length) == frmMain.txtCode.value.toUpperCase())
0
 

Author Comment

by:anagm
ID: 17845935
yup, it works for the 'txtCode'


I tried with the below code for the 'txtName'

query += "translate(@Name,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + frmMain.txtName.value.toUpperCase() +"'";

and i get this error  'msxml3.dll: Unknown method.'

the syntax seems to be correct, what modification i should do?

please help
0
 

Author Comment

by:anagm
ID: 17846114
This is for the 'txtName'.  


In the database the field value is stored as, for example 'United States'.

That is the first letter is the capital letter.

when i do the search by 'United States', i get a record.
But if i do a search with a keyword 'united states', i DO NOT get a record.

i am trying with the below code:

query += "translate(@Name,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + frmMain.txtName.value.toUpperCase() +"'";

i get an error ''msxml3.dll: Unknown method'


0
 
LVL 9

Expert Comment

by:owenli27
ID: 17846765
Did you run xmlinst.exe after you installed msxsml3.dll?  And what is namespace in your xslt?
0
 
LVL 9

Expert Comment

by:owenli27
ID: 17847130
Is "@Name" an attribute which is in a xml element Or it just is a constant string which is used in SQL to query database?
Can you post more snppet code?  I wonder if we can assign "@Name" to a Javascript variable if it stands for an attribute name.
0
 

Author Comment

by:anagm
ID: 17847324
owenli27,

this is how i am getting the error for the below code:

if (frmMain.txtName.value)
{
query += "translate(@Name,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + frmMain.txtName.value.toUpperCase() +"'";
}

var xpathQuery = "//Property"
if (query)
{
xpathQuery += "[" + query + "]";
}

get the following error:                        

msxml3.dll: Unknown method.

//Property[-->translate(@<--abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='UNITED STATES' and @Language='ENGLISH']

how do i run xmlinst.exe after you installed msxsml3.dll?

need some more help please
0
 

Author Comment

by:anagm
ID: 17847517
owenli27,

It is the name of the column in the table,

that is i have column with name 'Name' in the table

0
 
LVL 9

Expert Comment

by:owenli27
ID: 17847965
I just made a test by using

<xsl:if test="customerName=//customer[translate(@member,'yesxz','YESXZ') = 'YES']/customerName">
    <xsl:value-of select ="." />
</xsl:if>

Against my xml like:

<customer member="yes">
    <customerName>Mary</customerName>
    <gender>Female</gender>
</customer>

The test works fine when I use ActiveXObject("Microsoft.XMLDOM").  But it doesn't work if I use ActiveXObject("MSXML2.DOMDocument").
Weird, the different processor cause problems.  So, I guess that we may have to give up translate() and try other way.
0
 
LVL 9

Accepted Solution

by:
owenli27 earned 500 total points
ID: 17847974
Your database store 'Name' with frist character being uppercase. I create a javascript function to convert txtName input to match database name column format.

function convert(txtStr)
{
      var tmpName = txtStr.toLowerCase();
      var result  = "";
      var flag = 0;
      for (var i = 0; i < tmpName.length; i++)
      {
            if(i == 0){
                result += tmpName.charAt(i).toUpperCase()
                continue;
            }
             if (tmpName.charAt(i) == " "){
                  result += tmpName.charAt(i)
                   flag = 1;
                  continue;
            }
            if(flag == 1){
                result += tmpName.charAt(i).toUpperCase();
                flag = 0;
            }
            else
                result += tmpName.charAt(i);
       }
       return result;
}

if (frmMain.txtName.value)
{
      var temp = convert(frmMain.txtName.value);
      query += "@Name='" + temp + "'";
}
0
 

Author Comment

by:anagm
ID: 17849978
yup, it worked.  Thank you so much owenli27

YZlat,  I am able to get this done by owenli27 solution.  I am going to give full points to him/her.

Thank you for helping me, YZLat.



 
0
 

Author Comment

by:anagm
ID: 17850109
I need some more help from both of you,

I am posting another questions with Subject:  "Searching the database with the given text" in the textbox field

thank you
0
 

Author Comment

by:anagm
ID: 17850133
sorry, its going to be

"Searching the table with the given text"
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Merge XML into DOM 5 44
Removing information on Duplicate XML Nodes 24 77
Post xml via PHP Soap Client 3 47
.net and XML report from SCCM 5 20
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now