如何编写 xpath 以匹配除特定元素之外的所有元素 [英] How to write a xpath to match all elements except a particular element
问题描述
我正在编写 XSL 转换.我想编写一个模板,该模板匹配文档的所有子元素,但一个特定节点除外.我的 xml 看起来像这样 -
I am writing an XSL transformation. I want to write a template which matches all the child elements of the document except one particular node. My xml looks like this -
<Document>
<NodeA></NodeA>
<NodeB></NodeB>
<ServiceNode></ServiceNode>
<NodeX></NodeX>
</Document>
我想编写一个模板来匹配除 ServiceNode
之外的所有节点,即 NodeA
到 NodeX
.怎么写这个Xpath来获取-
I want to write a template that matches all nodes except ServiceNode
i.e. NodeA
to NodeX
. How to write this Xpath to get -
<xsl:template match="ALL Nodex Except ServiceNode">
推荐答案
我想写一个模板匹配除 ServiceNode 之外的所有节点即 NodeA 到 NodeX.
I want to write a template that matches all nodes except ServiceNode i.e. NodeA to NodeX.
如果节点"是指元素,则使用:
<xsl:template match="*[not(self::ServiceNode)]">
如果节点"是指任何节点(元素、文本、注释、处理指令类型):使用
<xsl:template match="node()[not(self::ServiceNode)]">
如果您只想匹配 Document
的子项,请使用:
If you want only children of Document
to be matched use:
<xsl:template match="Document/node()[not(self::ServiceNode)]">
如果您只想匹配顶部元素的子元素,请使用:
<xsl:template match="/*/node()[not(self::ServiceNode)]">
这篇关于如何编写 xpath 以匹配除特定元素之外的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!