XSLT 1.0:如何寻找“父"轴 [英] XSLT 1.0: how to go for the "parent" axis

查看:72
本文介绍了XSLT 1.0:如何寻找“父"轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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'

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. Can please someone explain that to me?

非常感谢您的帮助和最好的问候,彼得

Thank you very much for your help and best regards, Peter

推荐答案

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

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.

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

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

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

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

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>

那么:

  • //parent::* 将为您提供 rootitem 元素(作为元素的每个父节点)

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

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

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

//parent::node() 将获得 root 的父节点(即根节点)以及 rootitem 元素

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

这篇关于XSLT 1.0:如何寻找“父"轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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