Re: [xml] Fwd: continued problem with Python, libxml2 and entities


You should tell libxml2 to resolve entities before doing any XSLT
processing. In your, use

sourcedoc = libxml2.readFile( 'test.xml', None, libxml2.XML_PARSE_NOENT

If you look at you will see that it does the same trick
with a global setting ( libxml2.substituteEntitiesDefault(1) ) but I
believe this way of doing is deprecated.


-----Original Message-----
From: xml-bounces gnome org [mailto:xml-bounces gnome org] On 
Behalf Of Mike Kneller
Sent: lundi 29 janvier 2007 15:29
To: xml gnome org
Subject: [xml] Fwd: continued problem with Python, libxml2 
and entities

It turns out that the same transform run through xsltproc 
gives the correct result. 

What I am expecting to see is: 
<?xml version="1.0"?>

When I run it using, the result I get is: 
<?xml version="1.0"?>

So, as the xsltproc version gives me the correct result, I 
guess I can eliminate the library as the source of the 
problem, instead it would appear to be a problem with my 
Python code, or the Python wrapper. 

Any ideas? 


From: "Mike Kneller" <ukchill mac com>
To: <xml gnome org>
Date: January 28, 2007 09:26:40 AM PST
Subject: [xml] continued problem with Python, libxml2 and entities

The continuing saga!

I seem to have moved the entity issue from libxml2 to libxslt...

Using the following testcase (using a standard identity
transformation) now loses the entity.

replacing <xsl:copy> with <xsl:copy-of> on the <p> node 
produces output 
with the entity, as does using <xsl:value-of> on the same node.
import libxml2
import libxslt

sourcedoc = libxml2.parseFile( 'test.xml' ) styledoc = 
libxml2.parseFile( 'test.xsl' ) style = 
result = style.applyStylesheet(sourcedoc, None) print 
style.saveResultToString( result )

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xsl" ?>

<!DOCTYPE content [
    <!ENTITY copy "&#169;">


<?xml version="1.0"?>
<xsl:stylesheet version="1.0"

<xsl:template match="/">
    <xsl:apply-templates match="." />

<xsl:template match="@*|node()">
            <xsl:apply-templates select="@*|node()"/>


Mike Kneller
ukchill mac com

xml mailing list, project page xml gnome org

xml mailing list, project page 
xml gnome org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]