XSLT speed comparisons

Ross Ridge rridge at csclub.uwaterloo.ca
Thu Sep 28 00:15:09 CEST 2006


Damian wrote:
> two websites, one in ASP.NET v2 and one in Python 2.5 (using 4suite for
> XML/XSLT)
> both on the same box (Windows Server 2003)
> both using the same XML, XSLT, CSS
>
> The problem is, the Python version is (at a guess) about three times
> slower than the ASP one.

It could just be that 4suite is slower than MSXML.  If so, you can use
MSXML in Python if you want.  You'll need to install the Python for
Windows extensions.  Something like this:

	from os import environ
	import win32com.client

	def buildPage():
		xsluri = 'xsl/plainpage.xsl'
		xmluri = 'website.xml'

		xsl = win32com.client.Dispatch("Msxml2.FreeThreadedDOMDocument.4.0")
		xml = win32com.client.Dispatch("Msxml2.DOMDocument.4.0")
		xsl.load(xsluri)
		xml.load(xmluri)

		xslt = win32com.client.Dispatch("Msxml2.XSLTemplate.4.0")
		xslt.stylesheet = xsl
		proc = xslt.createProcessor()
		proc.input = xml

		params = {"url":environ['QUERY_STRING'].split("=")[1]}
		for i, v in enumerate(environ['QUERY_STRING'].split("/")[1:]):
		    params["selected_section%s" % (i + 1)] = "/" + v

		for param, value in params.items():
			proc.addParameter(param, value)
		proc.transform()
		return proc.output

	print "Content-Type: text/html\n\n"
	print buildPage()


                                             Ross Ridge




More information about the Python-list mailing list