XSLT 1.0:如何寻找“父级”轴

发布于 2024-12-29 02:51:31 字数 250 浏览 3 评论 0原文

我有一个关于在 XPATH 中调用“父”轴的 XSLT 性能的问题。 我可以使用“::*”调用父轴,或者使用“::”和元素名称调用它

parent::*/MVKE/item/VMSTA='Z2'

,或者

parent::item/MVKE/item/VMSTA='Z2'

如果我使用“*”或使用节点元素的名称,性能是否重要?两者都有效,但我想知道有什么区别。

I have a question concerning the performance of an XSLT calling the "parent" axis in an XPATH.
I can call the parent axis using "::*" or I call it using "::" and the name of the element

parent::*/MVKE/item/VMSTA='Z2'

or

parent::item/MVKE/item/VMSTA='Z2'

Does it matter performance wise if I use the "*" or if I use the name of the node element? Both work but I was wondering what the difference is.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

美煞众生 2025-01-05 02:51:31

第一个表达式匹配任何元素父元素。仅当父元素是 item 元素时,第二个表达式才匹配。这是唯一的区别。我无法想象任何重大的性能影响,因为两个节点测试都可以在恒定时间内执行。

请注意 XPath 1.0 规范 中的这一行:

除根节点之外的每个节点都只有一个父节点,即
元素节点或根节点。

实际上,这意味着 parent::* 匹配除根元素之外的任何 父元素。

为了进行演示,请考虑这个简单的示例文档:

<root>
    <one/>
    <item>
        <two/>
    </item>
</root>

然后:

  • //parent::* 将获取 rootitem 元素(每个作为元素的父节点)

  • //parent::item 将仅返回 item 元素(作为 item 的唯一父元素)

  • / /parent::node() 将为您提供父级root(即根节点)以及rootitem元素

The first expression matches any element parent. The second expression only matches when the parent is an item element. That's the only difference. I can't imagine any significant performance impact, since both node tests can be performed in constant time.

Note this line from the XPath 1.0 spec:

Every node other than the root node has exactly one parent, which is
either an element node or the root node.

In practice this means that parent::* matches any parent except that of the root element.

To demonstrate, consider this simple example document:

<root>
    <one/>
    <item>
        <two/>
    </item>
</root>

Then:

  • //parent::* will get you the root and item elements (every parent node that is an element)

  • //parent::item will return only the item element (the only parent element that is an item)

  • //parent::node() will get you the parent of root (i.e. the root node) as well as the root and item elements

后知后觉 2025-01-05 02:51:31

虽然不一样,但我怀疑性能会有显着差异。

使用 * 接受任何父元素,使用名称将要求父元素具有此名称,否则您将得到一个空节点集。因此,如果其中一个更快,则很可能是 *

另一种选择是使用 parent::node() 或其缩写形式 ..

It's not the same, but I doubt that there will be a significant performance difference.

Using the *accepts any parent element, using the name will require that the parent has this name or you'll get an empty node-set. Therefore, if one were faster it would likely be the * one.

Another option would be to use parent::node(), or its short form ..

染柒℉ 2025-01-05 02:51:31

简单地说:

<xsl:value-of select="../node()"/>

给你直接父母。是否存在像最初的问题一样,一种方法与另一种方法的性能优势?

What about simply:

<xsl:value-of select="../node()"/>

Gives you the immediate parent. Are there,as was the original question performance benefits in one method V another?

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