XPath to find nearest ancestor element that contains an element that has an attribute with a certain value

This should work:

//*[ancestor::foo[bar[@attr="val"]]]

or alternatively

root/foo/bar[ancestor::foo[bar[@attr="val"]]]

matches the second <bar> element

<root>
    <foo>
        <bar attr="xxx"></bar>
    </foo>
    <foo>
        <bar attr="val"></bar>
    </foo>
    <foo>
        <bar attr="zzz"></bar>
    </foo>
</root>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)