Damian wrote: > Hi, I'm from an ASP.NET background an am considering making the switch > to Python. I decided to develop my next project in tandem to test the > waters and everything is working well, loving the language, etc. > > What I've got is: > 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. I'm very new to the language and it's likely
The ASP one being MSXML, right? In that case that result doesn't surprise me. > that I'm doing something wrong here: Now wrong, but we can definitely simplify your API > from os import environ > from Ft.Lib.Uri import OsPathToUri > from Ft.Xml import InputSource > from Ft.Xml.Xslt import Processor > > def buildPage(): > try: > xsluri = OsPathToUri('xsl/plainpage.xsl') > xmluri = OsPathToUri('website.xml') > > xsl = InputSource.DefaultFactory.fromUri(xsluri) > xml = InputSource.DefaultFactory.fromUri(xmluri) > > proc = Processor.Processor() > proc.appendStylesheet(xsl) > > params = {"url":environ['QUERY_STRING'].split("=")[1]} > for i, v in enumerate(environ['QUERY_STRING'].split("/")[1:]): > params["selected_section%s" % (i + 1)] = "/" + v > > return proc.run(xml, topLevelParams=params) > except: > return "Error blah blah" > > print "Content-Type: text/html\n\n" > print buildPage() This should work: from os import environ from Ft.Xml.Xslt import Transform def buildPage(): try: params = {"url":environ['QUERY_STRING'].split("=")[1]} for i, v in enumerate(environ['QUERY_STRING'].split("/")[1:]): params["selected_section%s" % (i + 1)] = "/" + v return Transform('website.xml', 'xsl/plainpage.xsl', topLevelParams=params) except: return "Error blah blah" print "Content-Type: text/html\n\n" print buildPage() -- % -- For what it's worth I just developed, and switched to WSGI middleware that only does the transform on the server side if the client doesn't understand XSLT. It's called applyxslt and is part of wsgi.xml [1]. That reduces server load, and with caching (via Myghty), there's really no issue for me. For more on WSGI middleware see [2]. [1] http://uche.ogbuji.net/tech/4suite/wsgixml/ [2] http://www.ibm.com/developerworks/library/wa-wsgi/ -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://fourthought.com http://copia.ogbuji.net http://4Suite.org Articles: http://uche.ogbuji.net/tech/publications/ -- http://mail.python.org/mailman/listinfo/python-list