Solved

Case Insensitive search using XPath

Posted on 2006-10-31
22
294 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

9 Experts available now in Live!

Get 1:1 Help Now