[xslt] transformation removes DOCTYPE declaration form original document




I don't know if it is specific to Python bindings or whole lib{xml2,xslt}.

Consider simple example:

import libxml2, libxslt

doc = '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML" "http://pyxml.sourceforge.net/topics/dtds/xbel-1.0.dtd";>
<xbel>
</xbel>
'''
xsl = '''<?xml version="1.0" encoding="ISO-8859-2"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


 <xsl:output method="xml" indent="yes" encoding="iso-8859-2"/>

 <xsl:template match='/'>
  <xsl:apply-templates/>
 </xsl:template>

 <xsl:template match='/xbel'>
   <z/>
 </xsl:template>

</xsl:stylesheet>
'''

xdoc = libxml2.parseDoc(doc)
print xdoc.serialize('UTF-8', 1)

xxsl = libxml2.parseDoc(xsl)
xxsl = libxslt.parseStylesheetDoc(xxsl)
xxsl.applyStylesheet(xdoc, None)

print xdoc.serialize('UTF-8', 1)


and result:

$ python ex.py
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML" "http://pyxml.sourceforge.net/topics/dtds/xbel-1.0.dtd";>
<xbel version="1.0">
</xbel>


<?xml version="1.0" encoding="UTF-8"?>
<xbel version="1.0">
</xbel>

It is a proper behavior? I use:

$ rpm -q libxml2 libxslt
libxml2-2.6.19-1
libxslt-1.1.14-1

Regards
Radek



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