Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brad Hunt 26 posts 57 karma points
    Dec 26, 2011 @ 16:29
    Brad Hunt
    0

    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!

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 27, 2011 @ 01:15
    Chriztian Steinmeier
    0

    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:

    contains(translate(title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'nurse')
    

    - so your complete XPath would read something like this:

    //*[@id=1114]//Job[@isDoc]
    [contains(translate(title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'nurse')]
    [city = 'Dalhart']
    [state = 'AR']
    [setting = 'Outpatient' or setting = 'Inpatient']
    [jobType = 'PartTime' or jobType = 'FullTime']
    
    (Each predicate on its own line for readability - can be one line in the source.)

    /Chriztian

  • Brad Hunt 26 posts 57 karma points
    Dec 27, 2011 @ 01:39
    Brad Hunt
    0

    Chriztian,

    Thanks very much. Your suggestion worked perfectly. I appreciate it.

    Brad

Please Sign in or register to post replies

Write your reply to:

Draft