通过xpath选择除少数节点以外的所有节点

时间:2012-10-01 10:48:11

标签: xpath orbeon xforms

只是一点帮助。请告诉我这个

的正确xpath表达式

我有像这样的xml doc

<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

2 个答案:

答案 0 :(得分:1)

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

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

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

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

答案 1 :(得分:1)

使用

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

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