Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Case Insensitive search using XPath

Posted on 2006-10-31
22
Medium Priority
?
310 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

926 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