1 # Due to a shocking number of bugs and incompatibilities between PyXML and 4Suite,
2 # this actually seems to be the easiest way to convert a XML document to HTML!
4 # (note: moved to XHTML now anyway)
5 # Validates the output.
8 from xml
.dom
.html
import HTMLDocument
9 from Ft
.Xml
.cDomlette
import implementation
10 from Ft
.Xml
.Xslt
.Processor
import Processor
11 from Ft
.Xml
import InputSource
12 doc
= implementation
.createDocument(None, 'root', None)
14 from cStringIO
import StringIO
16 # The HTML writer adds some header fields, so strip any existing ones out or we'll get
20 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
21 xmlns:h="http://www.w3.org/1999/xhtml">
22 <xsl:output method="xml" encoding="utf-8"
23 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
24 doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
26 <xsl:template match='/h:html/h:head/h:meta[@name="generator"]' priority='2'/>
27 <xsl:template match='/h:html/h:head/h:meta[@http-equiv="Content-Type"]'/>
29 <xsl:template match='@*|node()'>
31 <xsl:apply-templates select='@*'/>
32 <xsl:apply-templates/>
36 <xsl:template match='h:*'>
37 <xsl:element name='{local-name(.)}' namespace='http://www.w3.org/1999/xhtml'>
38 <xsl:apply-templates select='@*'/>
39 <xsl:apply-templates/>
45 proc
.appendStylesheet(InputSource
.InputSource(stream
))
50 data
= proc
.runNode(doc
, None, ignorePis
= 1)
51 cin
, cout
= os
.popen4('xmllint --postvalid --noout -')