REXML translate (XPath?)

Discussion in 'Ruby' started by Andrew C., Feb 12, 2010.

  1. Andrew C.

    Andrew C. Guest

    Can somebody explain or put me to an explanation of how to use
    REXML::Functions::translate ?

    I'd like to turn this: group_list.elements["entry[title='#{name}']"]

    .. . . into a case insensitive lookup. Do I put the translation into
    the XPath in that line? Do I need a separate translation line?


    Thanks,
    Andrew
    Andrew C., Feb 12, 2010
    #1
    1. Advertising

  2. Andrew C.

    Mark Thomas Guest

    On Feb 11, 7:42 pm, "Andrew C." <> wrote:
    > Can somebody explain or put me to an explanation of how to use
    > REXML::Functions::translate ?
    >
    > I'd like to turn this: group_list.elements["entry[title='#{name}']"]
    >
    > . . . into a case insensitive lookup.  Do I put the translation into
    > the XPath in that line?  Do I need a separate translation line?
    >
    > Thanks,
    > Andrew


    This would be the correct XPath:

    group_list.elements["entry[translate(title,
    'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
    'abcdefghijklmnopqrstuvwxyz')='#{name.downcase}']"]

    but I don't know if REXML can handle it, because it's not fully XPath
    compliant. I'd use an XPath-compliant parser like Nokogiri if this is
    an issue.

    -- Mark.
    Mark Thomas, Feb 12, 2010
    #2
    1. Advertising

  3. Andrew C.

    Andrew C. Guest

    That appears to work for REXML. Thanks Mark.

    On Feb 12, 12:12 pm, Mark Thomas <> wrote:
    > On Feb 11, 7:42 pm, "Andrew C." <> wrote:
    >
    > > Can somebody explain or put me to an explanation of how to use
    > > REXML::Functions::translate ?

    >
    > > I'd like to turn this: group_list.elements["entry[title='#{name}']"]

    >
    > > . . . into a case insensitive lookup.  Do I put the translation into
    > > the XPath in that line?  Do I need a separate translation line?

    >
    > > Thanks,
    > > Andrew

    >
    > This would be the correct XPath:
    >
    > group_list.elements["entry[translate(title,
    > 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
    > 'abcdefghijklmnopqrstuvwxyz')='#{name.downcase}']"]
    >
    > but I don't know if REXML can handle it, because it's not fully XPath
    > compliant. I'd use an XPath-compliant parser like Nokogiri if this is
    > an issue.
    >
    > -- Mark.
    Andrew C., Feb 12, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Damphyr
    Replies:
    2
    Views:
    131
    Damphyr
    Jul 16, 2003
  2. Han Holl

    Rexml xpath question

    Han Holl, Feb 22, 2004, in forum: Ruby
    Replies:
    7
    Views:
    135
    Han Holl
    Mar 6, 2004
  3. Alexey Verkhovsky
    Replies:
    0
    Views:
    169
    Alexey Verkhovsky
    Aug 3, 2004
  4. Daniel Berger

    rexml error - REXML::Validation

    Daniel Berger, Oct 12, 2004, in forum: Ruby
    Replies:
    2
    Views:
    145
    Henrik Horneber
    Oct 12, 2004
  5. Phlip
    Replies:
    0
    Views:
    135
    Phlip
    Jan 15, 2008
Loading...

Share This Page