且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何编写 xpath 以匹配除特定元素之外的所有元素

更新时间:2023-02-19 20:31:30

我想写一个模板匹配除 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)]">