xml 如何使用Xpath(using XSLT)查询遍历回XML文件中的父节点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3676169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:16:39  来源:igfitidea点击:

How to traverse back to the parent node in the XML file by using Xpath(using XSLT) query?

xmlxpathxpathnavigator

提问by Santosh kumar

Let us have a xml tree of depth N. I have traveresd the last node means i am at last note. Now i wanted to go back to some level up (say at N-3) in the xml tree from that last node.

让我们有一个深度为 N 的 xml 树。我已经遍历了最后一个节点意味着我在最后一个音符。现在我想从最后一个节点回到 xml 树中的某个级别(比如 N-3)。

Please let me know the syntax for the XPATH query so that i can reached at intended node in the xml tree.

请让我知道 XPATH 查询的语法,以便我可以到达 xml 树中的预期节点。

回答by Dimitre Novatchev

Use:

使用

ancestor::node()[3]

or

或者

../../..