Solved

Case Insensitive search using XPath

Posted on 2006-10-31
22
295 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSL Grouping 7 38
D3, SVG, javascript, grouping 2 95
XML error 2 41
surrogate key in database world 6 83
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

15 Experts available now in Live!

Get 1:1 Help Now