[lxml-dev] xpath comparison

Olivier Collioud Olivier.Collioud at wipo.int
Fri Jun 6 15:10:14 CEST 2008


Thanks Stefan,

But I would have expected that:

def isin(context,symbol,start,end):
    return start <= symbol <= end
ns = ElementTree.FunctionNamespace('http://wipo.int/isin')
ns.prefix = 'ii'
ns['isin'] = isin

for mref in definitionsTree.xpath('//MREF[ii:isin(%s, at START, at END)]' %
symbol):
    ...

would be faster than:

for mref in definitionsTree.xpath('//MREF'):
    if mref.get('START') <= symbol <= mref.get('END'):
        ...

Because the first solution should visit less node.

But it seems that it is the contrary.

Why ?

Olivier

>>> Stefan Behnel <stefan_ml at behnel.de> 6/06/08 11:08 am >>>

Olivier Collioud wrote:
> is there any xpath equivalent in lxml to this:
> 
> (ms:string-compare(@START,$symbol)=-1 and
> ms:string-compare(@END,$symbol)=1)
> 
> which mean:
> 
> (START < symbol and symbol < END)

You can implement your own python function to do this.

http://codespeak.net/lxml/extensions.html 

Stefan

_______________________________________________
lxml-dev mailing list
lxml-dev at codespeak.net 
http://codespeak.net/mailman/listinfo/lxml-dev


------
World Intellectual Property Organization Disclaimer:

This electronic message may contain privileged, confidential and
copyright protected information. If you have received this e-mail
by mistake, please immediately notify the sender and delete this
e-mail and all its attachments. Please ensure all e-mail attachments
are scanned for viruses prior to opening or using.




More information about the lxml-dev mailing list