Since some people seem to be actually reading this and some progress has been made, I thought I'd give a report of what's been happening with lxml. Since last week, I've added a lot more of the ElementTree API, such
as the .find() function and friends, by directly using the code
from ElementTree. I actually am running the ElementTree and cElementTree test suites
now. I still need to disable some tests, but a significant fraction
is indeed running. I've improved the way libxml2's parser functionality gets used, in
order to implement libxml2's top-level parse() function. I've added XPath support to lxml.etree! An example of what you can
do: I've added the start of XSLT support to lxml.etree. An example:
Fri Jan 14 2005 19:15 lxml progress:
[More]
>>> from lxml import etree
>>> tree = etree.parse('ot.xml')
>>> tree.xpath('(//v)[5]/text()')
[u'And God called the light Day, and the darkness he called Night.
And the evening and the morning were the first day.\n']
or, say, this, modifying the elements returned:
>>> result = tree.xpath('(//v)[5]')
>>> result[0].text = 'The day and night verse.'
>>> tree.xpath('(//v)[5]/text()')
[u'The day and night verse.']
test.xslt
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*" />
<xsl:template match="/">
<day><xsl:value-of select="(//v)[5]" /></day>
</xsl:template>
</xsl:stylesheet>
>>> from lxml import etree
>>> style_xml= etree.parse('test.xslt')
>>> style = etree.XSLT(style_xml)
>>> ot = etree.parse('ot.xml')
>>> result = style.apply(ot)
>>> style.tostring(result)
u'<?xml version="1.0"?>\n<day>And God called the light Day, and the
darkness he called Night. And the evening and the morning were the
first day.\n</day>\n'
>>> result.getroot().tag
u'day'
