【问题标题】:select all except few nodes by xpath通过 xpath 选择除少数节点之外的所有节点
【发布时间】:2012-10-01 10:48:10
【问题描述】:

只是一点帮助。请告诉我正确的 xpath 表达式

我有这样的 xml 文档

<parent>
                    <child id='1' show='true' />
                    <child id='2' show='true' />
                    <child id='3' show='true' />
                    <child id='4' show='true' />
                    <child id='5' show='true' />
                    <child id='6' show='true' />
                </parent>

我想选择除第 2 个和第 5 个孩子之外的所有 show 属性,以便我可以将它们的值转换为 false

【问题讨论】:

  • 我会说聪明的表达方式

标签: xpath orbeon xforms


【解决方案1】:

您可以在 XPath 表达式中使用布尔 and

/parent/child[@id != '2' and @id != '5']

如果你真的想要第二个和第五个元素,你可以使用position()函数:

/parent/child[position() != 2 and position() != 5]

【讨论】:

    【解决方案2】:

    使用

    /*/*[not(position() = 2 or position() = 5)]/@show
    

    这会选择 xml 文档顶部元素的任何子元素的任何 show 属性,而不是其父元素的第二个或第五个子元素。

    【讨论】: