[Lxml-checkins] r32720 - in lxml/trunk/src/lxml: . tests

scoder at codespeak.net scoder at codespeak.net
Fri Sep 29 08:58:59 CEST 2006


Author: scoder
Date: Fri Sep 29 08:58:58 2006
New Revision: 32720

Modified:
   lxml/trunk/src/lxml/tests/test_xslt.py
   lxml/trunk/src/lxml/xslt.pxi
Log:
always return ElementTree from XSLTPI.parseXSL() - resembles parse()

Modified: lxml/trunk/src/lxml/tests/test_xslt.py
==============================================================================
--- lxml/trunk/src/lxml/tests/test_xslt.py	(original)
+++ lxml/trunk/src/lxml/tests/test_xslt.py	Fri Sep 29 08:58:58 2006
@@ -574,6 +574,19 @@
         root[:] = result.getroot()[:]
         del root # segfaulted before
         
+    def test_xslt_pi(self):
+        tree = self.parse('''\
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="%s"?>
+<a>
+  <b>B</b>
+  <c>C</c>
+</a>''' % fileInTestDir("test1.xslt"))
+
+        style_root = tree.getroot().getprevious().parseXSL().getroot()
+        self.assertEquals("{http://www.w3.org/1999/XSL/Transform}stylesheet",
+                          style_root.tag)
+        
     def test_xslt_pi_embedded_xmlid(self):
         # test xml:id dictionary lookup mechanism
         tree = self.parse('''\
@@ -591,11 +604,11 @@
   </xsl:stylesheet>
 </a>''')
 
-        style = tree.getroot().getprevious().parseXSL()
+        style_root = tree.getroot().getprevious().parseXSL().getroot()
         self.assertEquals("{http://www.w3.org/1999/XSL/Transform}stylesheet",
-                          style.tag)
+                          style_root.tag)
 
-        st = etree.XSLT(style)
+        st = etree.XSLT(style_root)
         res = st.apply(tree)
         self.assertEquals('''\
 <?xml version="1.0"?>
@@ -625,11 +638,11 @@
 
         tree.getroot().append(style.getroot())
 
-        style = tree.getroot().getprevious().parseXSL()
+        style_root = tree.getroot().getprevious().parseXSL().getroot()
         self.assertEquals("{http://www.w3.org/1999/XSL/Transform}stylesheet",
-                          style.tag)
+                          style_root.tag)
 
-        st = etree.XSLT(style)
+        st = etree.XSLT(style_root)
         res = st.apply(tree)
         self.assertEquals('''\
 <?xml version="1.0"?>

Modified: lxml/trunk/src/lxml/xslt.pxi
==============================================================================
--- lxml/trunk/src/lxml/xslt.pxi	(original)
+++ lxml/trunk/src/lxml/xslt.pxi	Fri Sep 29 08:58:58 2006
@@ -557,14 +557,16 @@
 
 cdef class _XSLTProcessingInstruction(PIBase):
     def parseXSL(self, parser=None):
-        """Try to parse the stylesheet referenced by this PI and return its
-        root node.  If the stylesheet is embedded in the same document
-        (referenced via xml:id), find and return the stylesheet Element.
+        """Try to parse the stylesheet referenced by this PI and return an
+        ElementTree for it.  If the stylesheet is embedded in the same
+        document (referenced via xml:id), find and return an ElementTree for
+        the stylesheet Element.
 
         The optional ``parser`` keyword argument can be passed to specify the
         parser used to read from external stylesheet URLs.
         """
         cdef _Document result_doc
+        cdef _Element  result_node
         cdef char* c_href
         cdef xmlAttr* c_attr
         if self._c_node.content is NULL:
@@ -590,7 +592,8 @@
         c_href = c_href+1 # skip leading '#'
         c_attr = tree.xmlGetID(self._c_node.doc, c_href)
         if c_attr is not NULL and c_attr.doc is self._c_node.doc:
-            return _elementFactory(self._doc, c_attr.parent)
+            result_node = _elementFactory(self._doc, c_attr.parent)
+            return _elementTreeFactory(result_node._doc, result_node)
 
         # try XPath search
         root = _findStylesheetByID(self._doc, id=funicode(c_href))
@@ -598,7 +601,8 @@
             raise ValueError, "reference to non-existing embedded stylesheet"
         elif len(root) > 1:
             raise ValueError, "ambiguous reference to embedded stylesheet"
-        return root[0]
+        result_node = root[0]
+        return _elementTreeFactory(result_node._doc, result_node)
 
 
 ################################################################################


More information about the lxml-checkins mailing list