[lxml-dev] matches()
Ian Bicking
ianb at colorstudy.com
Tue May 29 09:18:58 CEST 2007
Ian Bicking wrote:
> Ian Bicking wrote:
>> Using lxml trunk:
>> doc.xpath('descendant-or-self::*[starts-with(lower-case(@href),
>> "javascript:")]')
>
> Well, maybe this one doesn't work either (returns 1/0). Now I'm just
> confused.
Adding to this, I'm trying to do the rel matching with:
etree.XPath("descendant-or-self::a[fn:lower-case(@rel)=$rel]")
I *have* to use fn:lower-case, not just lower-case, otherwise I get
XPathEvalError: Unregistered function. And it doesn't matter if I use
it or not, it doesn't effect the outcome at all. Similarly upper-case
doesn't change anything.
I also tried using XPath(r'...[translate(@class, "\n\t\r", " ")]) and
that didn't work. The \n etc doesn't seem to be interpreted; only if I
include the actual characters does it work. (I then noticed
normalize-whitespace, which is better, but it still seems odd.)
How literals are supposed to work in XPath is rather unclear to me, I
guess \ isn't an escape character? The spec says use 'something''
if you want to include a literal ' in a string. Which I assume in an
XML attribute you'd have to do as 'something'', since it
probably gets double-unescaped? Bah.
--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org
| Write code, do good | http://topp.openplans.org/careers
More information about the lxml-dev
mailing list