XSLT速度比较 [英] XSLT speed comparisons

查看:86
本文介绍了XSLT速度比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自ASP.NET背景,我正在考虑将这个开关转换为Python。我决定开发我的下一个项目以测试

水域,一切运行良好,喜欢语言等等。


我有什么得到的是:

两个网站,一个在ASP.NET v2中,一个在Python 2.5中(使用4suite for

XML / XSLT)

both在同一个盒子上(Windows Server 2003)

都使用相同的XML,XSLT,CSS


问题是,Python版本是(猜测) )大约三倍

比ASP一慢。我对这门语言很陌生,而且我很可能在这里做错了什么:

来自os import environ的
来自Ft.Lib.Uri的
导入OsPathToUri

来自Ft.Xml导入InputSource
来自Ft.Xml.Xslt导入处理器的

< br $>
def buildPage():

试试:

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


返回proc.run(xml,topLevelParams = params)

除外:

return" error blah blah"


print" Content-Type:text / html\\\
\\\
"

print buildPage()


你可以在这里比较开发网站:

asp: http://consultum.pointy.co.nz/about/team

python: http://python.pointy.co.nz/about/team


干杯!

解决方案

Damian写道:


两个网站,一个在ASP.NET v2中和Python 2.5中的一个(使用4suite for

XML / XSLT)

在同一个盒子上(Windows Server 2003)

两者都使用相同的XML,XSLT,CSS

问题是,Python版本是(猜测)关于t好几次

比ASP一个慢。



可能只是4suite比MSXML慢。如果是这样,你可以在Python中使用

MSXML。你需要安装Python for

Windows扩展。这样的事情:


来自os import environ

import win32com.client


def buildPage():

xsluri =''xsl / plainpage.xsl''

xmluri =''website.xml''


xsl = win32com .client.Dispatch(" Msxml2.FreeThreadedDOMDo cument.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()

返回proc.output


print" Content-Type:text / html\\\
\\\
"

print buildPage()

Ross Ridge


Ross Ridge写道:


可能只是4suite比MSXML慢。如果是这样,你可以在Python中使用

MSXML。你需要安装Python for

Windows扩展。这样的事情:



感谢Ross。这是有道理的,我会读到某个地方

4suite代码有点慢但是想确定它不是b / b
只是我'' d做错了。


我已经尝试了你提供的代码,并在安装了

必需品后遇到了一系列错误的砖墙。


可以在 http中看到错误://python.pointy.co.nz/test (我要离开

现在运行的较慢版本,其余的

site)。


我必须重新开始做一些工作,但今晚会进一步研究这个




感谢您的帮助!我真的很感激。


Damian写道:


错误可以在< a rel =nofollowhref =http://python.pointy.co.nz/testtarget =_ blank> http://python.pointy.co.nz/test (我是我要离开

这个现有的,较慢的版本,目前为其余的

网站运行)。



嗯...好像你没有在你的

机器上安装MSXML 4.0。我错过了你正在使用ASP.NET的事实,所以你的ASP代码可能是使用.NET XML实现而不是
MSXML。在这种情况下,另一种选择可能是使用IronPython

并将你的ASP脚本翻译成Python。


Ross Ridge


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
that I''m doing something wrong here:

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()

You can compare the development sites here:
asp: http://consultum.pointy.co.nz/about/team
python: http://python.pointy.co.nz/about/team

Cheers!

解决方案

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.FreeThreadedDOMDo cument.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


Ross Ridge wrote:

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:

Thanks for that Ross. That would make sense, I''d read somewhere that
the 4suite code was a little slower but wanted to be sure it wasn''t
just something I''d done wrong.

I''ve experimented with the code you supplied and after installing the
necessaries have run into a brick wall with a series of errors.

The errors can be seen at http://python.pointy.co.nz/test (I''m leaving
the existing, slower version running at the moment for the rest of the
site).

I''ve got to get back on with some work but will look further into this
tonight.

Thanks for your help! I really appreciate it.


Damian wrote:

The errors can be seen at http://python.pointy.co.nz/test (I''m leaving
the existing, slower version running at the moment for the rest of the
site).

Hmm... it seems that you don''t have MSXML 4.0 installed on your
machine. I missed the fact that you''re using ASP.NET, so your ASP code
probably is probably using the .NET XML implementation instead of
MSXML. In that case, another alternative might be to use IronPython
and just translate your ASP script into Python.

Ross Ridge


这篇关于XSLT速度比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆