是否有一种技术可以将 XSL 转换管道合并为单个转换?
我已经编写了一个使用 15 个 XSL 样式表管道的应用程序,并且我开始致力于调整其性能。它被设计为可移植的,因此可以在 Web 浏览器环境和桌面上运行。在桌面上,我认为将样式表作为多个转换的管道分开可能是有意义的,因为这允许每个单独的转换在自己的线程中运行,这在具有多核的 CPU 上非常高效。然而,不仅浏览器环境是单线程的,在大多数浏览器中,暴露给 JavaScript 的 XSL 处理 API 都需要将每个单独转换的结果解析回 DOM 对象,这似乎效率低下。因此,我认为,如果可能的话,在浏览器环境上下文中运行时将所有样式表组合成单个样式表将是有利的。我知道如何使用 exsl:node-set (大多数浏览器支持)来实现这一点,但我不清楚我想象的技术是否可以推广。是否有一种通用技术可以将 XSL 样式表管道转换为单个 XSL 样式表,从而保留完整管道的语义?自动化解决方案将是理想的。
I have written an application which uses a pipeline of 15 XSL stylesheets, and I'm beginning to work on tuning its performance. It's designed to be portable, so that it can be run in both the web browser environment, and on the desktop. On the desktop, I think it may make sense to keep the stylesheets separated out as a pipeline of multiple transformations, as this allows each individual transformation to be run in its own thread, which can be very efficient on CPUs with multiple cores. However, not only is the browser environment is single-threaded, in most browsers, the XSL processing API exposed to JavaScript requires parsing the result of each individual transformation back into a DOM object, which seems inefficient. I think it would therefore be advantageous to combine all of the stylesheets into a single stylesheet when running in the context of the browser environment, if that is possible. I have an idea of how this may be accomplished with exsl:node-set (which most browsers support), but it's not clear to me if the technique I'm imagining is generalizable. Is there a general technique for transforming a pipeline of XSL stylesheets into a single XSL stylesheet, such that the semantics of the complete pipeline are preserved? An automated solution would be ideal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一种技术允许将独立的变换链接在一起,其中第 k 个变换的输出是第 (k+1) 个变换的输入。
这是一个简单的示例:
当此转换应用于以下 XML 文档时:
想要的结果(第一遍添加元素
作为顶部元素的子元素,然后第二遍添加另一个子元素,紧接着在第一遍中创建的元素
`)生成 :FXSL中有一个非常合适的模板/函数来执行此操作:这就是
compose-flist
模板。它采用初始数据参数和 N 个函数(模板)作为参数,并生成这些函数/模板的链式组合。这是 FXSL 库的测试示例:
当此转换应用于任何 xml 文档(未使用)时,会生成所需的正确结果:
执行注意:在 XSLT 2.0 及更高版本中,不需要
xxx:node-set()
扩展,并且任何链式转换都可以包含在实际函数中。There is a technique that allows independent transformations to be chained together where the output of the k-th transformation is the input of the (k+1)-th transformation.
Here is a simple example:
when this transformation is applied on the following XML document:
the wanted result (the first pass addds the element
<one/>
as a child of the top element, then the second pass adds another child,, immediately after the element
` that was created in the first pass) is produced:There is a very suitable template/function in FXSL to do this: this is the
compose-flist
template. It takes as parameters an initial data argument and N functions (templates) and produces the chained composition of these functions/templates.Here is the test example from the FXSL library:
when this transformation is applied on any xml document (not used), the wanted, correct result is produced:
Do note: In XSLT 2.0 and later no
xxx:node-set()
extension is necessary, and any of the chained transformations can be contained in a real function.一种方法是使用模式 http://www.w3.org/TR/xslt#modes 但你是对的,这需要将每个步骤转换为变量,并使用节点集扩展函数才能将下一步应用于变量内容。
One approach is to use modes http://www.w3.org/TR/xslt#modes but you are right that that requires transforming each step into a variable and to use a node-set extension function to be able to apply the next step to the variable contents.