XSLT 关键在推送转换,性能更好?
我在推送转换中使用
,在模板模式中使用它,例如:
<xsl:template match="key('div', 'MAIN')">
...
</xsl:template>
... 而不是:
<xsl:template match="html:div[upper-case(@id) = 'MAIN']">
...
</xsl:template>
但是,我不知道这是否有任何性能优势,并且最近我一直在想,既然这是一个推送变换,而且无论如何都会访问节点,那么密钥真的有用吗?
I am using <xsl:key>
in a push transformation, using it in template patterns, e.g.:
<xsl:template match="key('div', 'MAIN')">
...
</xsl:template>
... instead of:
<xsl:template match="html:div[upper-case(@id) = 'MAIN']">
...
</xsl:template>
However, I don't know if this has any performance benefits, and lately I've been thinking, since this is a push transformation, and the node is visited anyways, is the key really useful ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管性能差异可能可以忽略不计,但在比较:
与: 的
性能时,在
key()
函数选择的任何情况下,后者似乎都更有效大量的节点。说明:
匹配
key()
相当于匹配key() 功能。因此,XSLT 处理器必须决定当前节点是否属于该节点集。这可能是一个相当低效的操作,特别是当
key()
函数选择的节点集很重要时。在第二种情况下,我们有一个简单的匹配。判断当前节点是否与匹配表达式匹配仅涉及一个节点测试和简单条件的验证。这通常比检查当前节点到大型节点集的成员资格更简单。
Although the performance difference may be negligible, when comparing the performance of:
to that of:
it seems that the latter is more efficient in any case where the
key()
function selects a significant number of nodes.Explanation:
Matching a
key()
is equivalent to matching the union of the nodes in the node-set returned by thekey()
function. Thus, the XSLT processor has to decide if the current node belongs to that node-set. This can be a rather inefficient operation, especially if the set of nodes selected by thekey()
function is significant.In the second case we have a simple match. Deciding whether the current node is matched by the match expression involves just one node test and verification of a simple condition. This is generally going to be simpler than checking the membership of the current node to a large node-set.
我很少看到 key() 在匹配模式中使用。我认为它不太可能带来任何显着的性能优势,除非密钥的“使用”条件非常复杂并且密钥的使用频率足以分摊构建索引的成本。与性能问题一样,这取决于您所使用的处理器,而找出答案的唯一真正方法就是测量它。
I very rarely see key() used in a match pattern. I think it's very unlikely to give any significant performance benefits, unless perhaps the "use" condition of the key is very complex and the key is used often enough to amortize the cost of building the index. As always with performance questions, it depends on the processor you are using, and the only real way to find out is to measure it.