transform to lower case XPATH in C# for comparison
I am creating a web form to search for jobs. There are multiple criteria for the jobs including title, city, state, job type, etc. Currently I have a form that allows the user to fill out the search criteria. Then in the C# code behind of the user control I am dynamically building the xPath expression based on the form fields completed.
So i end up with an xPath expression that looks like this:
//*[@id=1114]/descendant::Job[@isDoc] [title[contains(.,'Nurse')]][city='Dalhart'][state='AR'][setting='Outpatient' or setting='Inpatient'][jobType='PartTime' or jobType='FullTime']
Then I am using uComponents to search for nodes by that path.
All of this works pretty well if the user uses the same case for job title as it exists in the database. What I need to add is the abilty to convert both the search term and the doc property to lower case for comparison. For the user entered text, I can just use .ToLowerInvariant() in C#, but I am having problems with the case in the xPath.
I looked at using Exslt.Extensions and translate methods, but I cannot get the syntax to work. Most samples I have seen are trying this inside an XSLT file, and I need to make this conversion in C#.
I tried things like this:
//*[@id=1114]/descendant::Job[@isDoc] [Exslt.ExsltStrings:lowercase(title)[contains(.,'Nurse')]][city='Dalhart'][state='AR'][setting='Outpatient' or setting='Inpatient'][jobType='PartTime' or jobType='FullTime']
and this
//*[@id=1114]/descendant::Job[@isDoc] [translate(title,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')[contains(.,'Nurse')]][city='Dalhart'][state='AR'][setting='Outpatient' or setting='Inpatient'][jobType='PartTime' or jobType='FullTime']
etc, but I keep getting parser errors.
Does anyone have suggestions on how to accomplish this?
Seems you've just misinterpreted the use of translate() and contains() - if you need to test if the lowercased version of title contains the string "nurse", you can do it like this:
transform to lower case XPATH in C# for comparison
I am creating a web form to search for jobs. There are multiple criteria for the jobs including title, city, state, job type, etc. Currently I have a form that allows the user to fill out the search criteria. Then in the C# code behind of the user control I am dynamically building the xPath expression based on the form fields completed.
So i end up with an xPath expression that looks like this:
//*[@id=1114]/descendant::Job[@isDoc] [title[contains(.,'Nurse')]][city='Dalhart'][state='AR'][setting='Outpatient' or setting='Inpatient'][jobType='PartTime' or jobType='FullTime']
Then I am using uComponents to search for nodes by that path.
All of this works pretty well if the user uses the same case for job title as it exists in the database. What I need to add is the abilty to convert both the search term and the doc property to lower case for comparison. For the user entered text, I can just use .ToLowerInvariant() in C#, but I am having problems with the case in the xPath.
I looked at using Exslt.Extensions and translate methods, but I cannot get the syntax to work. Most samples I have seen are trying this inside an XSLT file, and I need to make this conversion in C#.
I tried things like this:
//*[@id=1114]/descendant::Job[@isDoc] [Exslt.ExsltStrings:lowercase(title)[contains(.,'Nurse')]][city='Dalhart'][state='AR'][setting='Outpatient' or setting='Inpatient'][jobType='PartTime' or jobType='FullTime']
and this
//*[@id=1114]/descendant::Job[@isDoc] [translate(title,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')[contains(.,'Nurse')]][city='Dalhart'][state='AR'][setting='Outpatient' or setting='Inpatient'][jobType='PartTime' or jobType='FullTime']
etc, but I keep getting parser errors.
Does anyone have suggestions on how to accomplish this?
Thanks!
Hi Brad,
Seems you've just misinterpreted the use of translate() and contains() - if you need to test if the lowercased version of title contains the string "nurse", you can do it like this:
- so your complete XPath would read something like this:
/Chriztian
Chriztian,
Thanks very much. Your suggestion worked perfectly. I appreciate it.
Brad
is working on a reply...