lorenzog lorenzog - 3 months ago 19
Linux Question

Same xpath returns different values on Centos, Ubuntu

We're trying to port our application from a Centos environment into other linuxes, in particular Ubuntu. The application is python-based so there should be no problems, however we noticed an odd behaviour when parsing XPATHs.

Sample file:



from lxml import etree
r = etree.parse('foo.xml')
print 'One: ', r.xpath('.//el[2]')
print 'Two: ', r.xpath('(.//el)[2]')

On Centos (python 2.7.5):

One: [<Element el at 0x25fdcf8>]
New version: [<Element el at 0x25fdcf8>]

On RedHat Enterprise 6.6 (python 2.7.11)

One: []
Two: [<Element el at 0x7fa27198cd40>]

On Debian and Ubuntu (python 2.7.9 and 2.7.12):

One: []
Two: [<Element el at 0x7f94ed6cf200>]

This is the same code trying to access the second element

Debian, Ubuntu and Cents environment have lxml (installed from
) version 3.6.4. When installing lxml it compiles it against libxml2 which is

On debian:

$ dpkg -l | grep libxml2-dev
ii libxml2-dev:amd64 2.9.1+dfsg1-5+deb8u2 amd64

On centos:

$ rpm -q libxml2-devel

RedHat runs etree 3.6.0:

$ rpm -q libxml2-devel

What's going on here?


The result on CentOS is incorrect.

libxml2 2.9.0 introduced a regression, see libxml 2.9.0 XPath evaluation issue. It is fixed in 2.9.2 but not in 2.9.1.

Debian has integrated the patch in version 2.9.1+dfsg1-3:

libxml2 (2.9.1+dfsg1-3) unstable; urgency=low

  • debian/patches/0007-Fix-XPath-optimization-with-predicates.patch:
    • Upstream patch to fix XPath evaluation issue. (Closes: #713146)