XML/XSLT with Python
Colin Fox
cfox at cfconsulting.ca
Sun Sep 21 08:23:26 EDT 2003
On Sun, 21 Sep 2003 11:31:40 +0000, Colin Fox wrote:
Hmm. I think my news client buggered up the linefeeds. Let me try again:
#! /usr/bin/env python
import time
st = time.time()
import libxml2, libxslt
import cgi, os, sys
query = cgi.FieldStorage()
readtimestart = time.time()
styledoc = libxml2.parseFile("page.xsl")
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseFile(query['script'].value)
readtimeend = time.time()
start_converting = time.time()
result = style.applyStylesheet(doc, None)
done_converting = time.time()
html = result.serialize()
print "Content-type: text/html"
print
print html
style.freeStylesheet()
doc.freeDoc()
result.freeDoc()
et = time.time()
totaltime = et-st
print "<!-- Page served in %s seconds. -->" % totaltime
print "<!-- XML conversion took %s seconds. -->" %\
(done_converting-start_converting)
print "<!-- File reading took %s seconds. -->" %\
(readtimeend-readtimestart)
More information about the Python-list
mailing list