view examples/transform/run.py @ 211:0a14c2a06be3

Fix another regression introduced in [258]: some kinds of cascaded match templates were broken, for example in the TurboGears example app.
author cmlenz
date Tue, 29 Aug 2006 21:14:58 +0000
parents 9cf42fb6b21e
children 24757b771651
line wrap: on
line source
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys

from markup.input import HTMLParser
from markup.template import Context, Template

def transform(html_filename, tmpl_filename):
    tmpl_fileobj = open(tmpl_filename)
    tmpl = Template(tmpl_fileobj, tmpl_filename)
    tmpl_fileobj.close()

    html_fileobj = open(html_filename)
    html = HTMLParser(html_fileobj, html_filename)
    print tmpl.generate(Context(input=html)).render('xhtml')
    html_fileobj.close()

if __name__ == '__main__':
    basepath = os.path.dirname(os.path.abspath(__file__))
    tmpl_filename = os.path.join(basepath, 'template.xml')
    html_filename = os.path.join(basepath, 'index.html')
    transform(html_filename, tmpl_filename)
Copyright (C) 2012-2017 Edgewall Software