REXML translate (XPath?)

A

Andrew C.

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
 
M

Mark Thomas

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.
 
A

Andrew C.

That appears to work for REXML. Thanks Mark.

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top