获取没有特定祖先 xml xpath 的节点
我想要 xpath,它获取没有祖先的节点,它是特定节点的第一个后代。
假设我们有这样的 xml 文档:
<a>
<b>This node</b>
<c>
<a>
<b>not this</b>
<g>
<b>not this</b>
</g>
</a>
<a>
<b>This node</b>
<c/>
</a>
</c>
</a>
<a>
<c>
<a>
<b>not this</b>
</a>
<a>
<b>This node</b>
</a>
<a>
<b>This node</b>
</a>
<a>
<b>This node</b>
</a>
</c>
</a>
<d>
<b>This node</b>
</d>
我想选择文档中没有 //a/c/a[1] 作为祖先节点的所有 b 节点。
I would like to have xpath, that obtains nodes, that don't have ancestor, which is first descendant of specific node.
Let's assume we have xml document like this:
<a>
<b>This node</b>
<c>
<a>
<b>not this</b>
<g>
<b>not this</b>
</g>
</a>
<a>
<b>This node</b>
<c/>
</a>
</c>
</a>
<a>
<c>
<a>
<b>not this</b>
</a>
<a>
<b>This node</b>
</a>
<a>
<b>This node</b>
</a>
<a>
<b>This node</b>
</a>
</c>
</a>
<d>
<b>This node</b>
</d>
I would like to select all b nodes in document that don't have as their ancestor node //a/c/a[1].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此 XPath 表达式:
这会选择文档中不存在的所有
b
元素具有祖先a
,其父级c
具有父级a
和a
具有父代c
的祖先不是其父代的第一个a
子代。给定以下 XML 文档(基于所提供的,但格式良好,并且还在应选择的节点中放置了标识文本):
正是想要的 6
b 元素。
使用 XSLT 进行验证:
当此转换应用于上述 XML 文档时,将选择所需的
b
元素,并且复制到输出。产生了想要的正确结果:Use this XPath expression:
This selects all
b
elements in the document that don't have ancestora
that has a parentc
that has parenta
and thea
ancestor that has parentc
is not the firsta
child of its parent.Given the following XML document (based on the provided, but made well-formed and also put identifying text in the nodes that should be selected):
exactly the wanted 6
b
elements are selected.Verification using XSLT:
when this transformation is applied on the above XML document, exactly the wanted
b
elements are selected and copied to the output. The wanted, correct result is produced: