我正在编写XSL转换。我想编写一个模板,该模板匹配文档的所有子元素(一个特定节点除外)。我的xml看起来像这样-

<Document>
    <NodeA></NodeA>

    <NodeB></NodeB>

    <ServiceNode></ServiceNode>

    <NodeX></NodeX>
</Document>

我想写一个模板来匹配除ServiceNode以外的所有节点,即NodeANodeX。如何编写此Xpath以获得-
<xsl:template match="ALL Nodex Except ServiceNode">

最佳答案



如果通过“节点”表示元素,则使用:

<xsl:template match="*[not(self::ServiceNode)]">

如果通过“节点”表示任何节点(元素类型,文本,注释,处理指令类型):请使用
<xsl:template match="node()[not(self::ServiceNode)]">

如果只希望匹配Document的子代,请使用:
<xsl:template match="Document/node()[not(self::ServiceNode)]">

如果只希望匹配顶部元素的子代,请使用:
<xsl:template match="/*/node()[not(self::ServiceNode)]">

10-06 06:26