基于前任属性值的属性的 XPath?

XPath for attribute based on predecessor's attribute value?

所以我有这样的东西

<img src="/icons/folder.gif" alt="[DIR]"> <a href="convobot-main/">convobot-main/</a>

并且我想 select 仅当 img 标签具有属性 alt = "[Dir]"a href。我怎样才能做到这一点?

这个 XPath,

//img[@alt='[DIR]']/following-sibling::a[1]/@href

将 select href 所有 img 元素的第一个 a 兄弟的属性 alt 属性值为 '[DIR]'