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

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第一个表达式匹配任何元素父元素。仅当父元素是
item
元素时,第二个表达式才匹配。这是唯一的区别。我无法想象任何重大的性能影响,因为两个节点测试都可以在恒定时间内执行。请注意 XPath 1.0 规范 中的这一行:
实际上,这意味着
parent::*
匹配除根元素之外的任何 父元素。为了进行演示,请考虑这个简单的示例文档:
然后:
//parent::*
将获取root
和item
元素(每个作为元素的父节点)//parent::item
将仅返回item
元素(作为item
的唯一父元素)/ /parent::node()
将为您提供父级root
(即根节点)以及root
和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.Note this line from the XPath 1.0 spec:
In practice this means that
parent::*
matches any parent except that of the root element.To demonstrate, consider this simple example document:
Then:
//parent::*
will get you theroot
anditem
elements (every parent node that is an element)//parent::item
will return only theitem
element (the only parent element that is anitem
)//parent::node()
will get you the parent ofroot
(i.e. the root node) as well as theroot
anditem
elements虽然不一样,但我怀疑性能会有显着差异。
使用
*
接受任何父元素,使用名称将要求父元素具有此名称,否则您将得到一个空节点集。因此,如果其中一个更快,则很可能是*
。另一种选择是使用
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..
简单地说:
给你直接父母。是否存在像最初的问题一样,一种方法与另一种方法的性能优势?
What about simply:
Gives you the immediate parent. Are there,as was the original question performance benefits in one method V another?