Add HTML as a save format.
[dom-editor.git] / Dome / to_html.py
blob60c8c385ed35024cb204d141cefbebde99ddb5ba
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
12 stream = StringIO('''
13 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
14 <xsl:output method="html"/>
16 <xsl:template match='@*|node()'>
17 <xsl:copy>
18 <xsl:apply-templates select='@*|node()'/>
19 </xsl:copy>
20 </xsl:template>
22 </xsl:stylesheet>
23 ''')
24 proc.appendStylesheet(InputSource.InputSource(stream))
26 def to_html(doc):
27 return proc.runNode(doc, None, ignorePis = 1)