Search code examples
xpathorbeonxforms

select all except few nodes by xpath


Just little help. Please let me know the correct xpath expression for this

I have xml doc like this

<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>

I want to select all show attributes except 2nd and 5th childs so that i can turn their values to false


Solution

  • You can use boolean and in your XPath expression:

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

    If you really want the second and fifth element, you can use the position() function:

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