XSLT 关键在推送转换,性能更好?

发布于 2024-10-24 08:43:05 字数 369 浏览 1 评论 0原文

我在推送转换中使用 ,在模板模式中使用它,例如:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栩栩如生 2024-10-31 08:43:05

尽管性能差异可能可以忽略不计,但在比较:

<xsl:template match="key('div', 'MAIN')"> 

与: 的

<xsl:template match="html:div[upper-case(@id) = 'MAIN']">

性能时,在 key() 函数选择的任何情况下,后者似乎都更有效大量的节点。

说明

  1. 匹配key()相当于匹配key() 功能。因此,XSLT 处理器必须决定当前节点是否属于该节点集。这可能是一个相当低效的操作,特别是当 key() 函数选择的节点集很重要时。

  2. 在第二种情况下,我们有一个简单的匹配。判断当前节点是否与匹配表达式匹配仅涉及一个节点测试和简单条件的验证。这通常比检查当前节点到大型节点集的成员资格更简单。

Although the performance difference may be negligible, when comparing the performance of:

<xsl:template match="key('div', 'MAIN')"> 

to that of:

<xsl:template match="html:div[upper-case(@id) = 'MAIN']">

it seems that the latter is more efficient in any case where the key() function selects a significant number of nodes.

Explanation:

  1. Matching a key() is equivalent to matching the union of the nodes in the node-set returned by the key() 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 the key() function is significant.

  2. 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.

韵柒 2024-10-31 08:43:05

我很少看到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文