Don't draw far-away ref nodes.
[dom-editor.git] / Dome / to_html.py
blob5a5b3288f8c971dd36bf85caadb0be839cba7145
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 import sys
5 from xml.dom.html import HTMLDocument
6 from Ft.Xml.cDomlette import implementation
7 from Ft.Xml.Xslt.Processor import Processor
8 from Ft.Xml import InputSource
9 doc = implementation.createDocument(None, 'root', None)
10 proc = Processor()
11 from cStringIO import StringIO
13 # The HTML writer adds some header fields, so strip any existing ones out or we'll get
14 # two lots...
16 stream = StringIO('''
17 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
18 xmlns:h="http://www.w3.org/1999/xhtml">
19 <xsl:output method="html"/>
21 <xsl:template match='/h:html/h:head/h:meta[@name="generator"]' priority='2'/>
22 <xsl:template match='/h:html/h:head/h:meta[@http-equiv="Content-Type"]'/>
24 <xsl:template match='@*|node()'>
25 <xsl:copy>
26 <xsl:apply-templates select='@*'/>
27 <xsl:apply-templates/>
28 </xsl:copy>
29 </xsl:template>
31 </xsl:stylesheet>
32 ''')
33 proc.appendStylesheet(InputSource.InputSource(stream))
35 def to_html(doc):
36 return proc.runNode(doc, None, ignorePis = 1)