          c_doc = tree.xmlCopyDoc(doc._c_doc, 1)
          # XXX work around bug in xmlCopyDoc (fix is upcoming in new release
          # of libxml2)
-@@ -1401,11 +1608,13 @@
+@@ -1401,8 +1612,10 @@
          # this cleans up copy of doc as well
          xslt.xsltFreeStylesheet(self._c_style)
          
 -    def apply(self, _ElementTree doc, **kw):
 +    def apply(self, _ElementTree etree, **kw):
-+        cdef _Document doc, result_doc
++        cdef _Document result_doc
          cdef xmlDoc* c_result
++        cdef xmlDoc* c_doc
          cdef char** params
          cdef int i
          cdef int j
-+        doc = etree._doc
-         if kw:
-             # encode as UTF-8; somehow can't put this in main params
-             # array construction loop..
-@@ -1436,14 +1645,17 @@
+@@ -1427,7 +1640,11 @@
+             params[i] = NULL
+         else:
+             params = NULL
+-        c_result = xslt.xsltApplyStylesheet(self._c_style, doc._c_doc, params)
++
++        c_doc = _fakeRootDoc(etree._doc._c_doc, etree._context_node._c_node)
++        c_result = xslt.xsltApplyStylesheet(self._c_style, c_doc, params)
++        _destroyFakeDoc(etree._doc._c_doc, c_doc)
++
+         if params is not NULL:
+             # deallocate space for parameters again
+             cstd.free(params)
+@@ -1436,15 +1653,21 @@
          # XXX should set special flag to indicate this is XSLT result
          # so that xsltSaveResultTo* functional can be used during
          # serialize?

Index: src/lxml/tests/test_etree.py
===================================================================
--- src/lxml/tests/test_etree.py	(Revision 18810)
+++ src/lxml/tests/test_etree.py	(Arbeitskopie)
@@ -1544,7 +1544,29 @@
         e = etree.Element('foo')
         e.set('bar', 'Bar')
         self.assertEquals(False, bool(e))

         
         xpathCtxt = xpath.xmlXPathNewContext(doc._c_doc)
         if xpathCtxt is NULL:
@@ -1122,40 +1299,21 @@
         self._doc = doc
         self._c_ctxt = xpathCtxt
         self._c_ctxt.userData = <void*>self
