XSLT 1.0 : how to go for the "parent" axis

标签 xslt xpath parent

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

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

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

如果我使用“*”或如果我使用节点元素的名称,这对性能有影响吗?两者都有效,但我想知道有什么区别。

最佳答案

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

请注意 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.

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

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

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

然后:

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

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

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

关于XSLT 1.0 : how to go for the "parent" axis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9006929/

相关文章:

css - 将父级悬停在当前父级 css 之外

xml - 带有 XML 的 Excel 电子表格

C++ XLST 转换无法使用 MSXML 3.0

xml - 用 XSLT 替换节点文本?

xslt - XSL 中的测试参数值类型

php - 如何在 PHP 中为父元素添加 XML 命名空间

jquery - 如果选中复选框,则将类添加到父元素

xslt - Cocoon逃逸查询参数问题

xpath - 从一组xpath中找到共同祖先?

xpath - 这个 XPATH 表达式的作用是什么?