.// 和 // 在 xpath 中间使用时有什么区别?

What is the difference between .// and // when they are used in the middle of the xpath?

使用有什么区别

htmlElement.getByXPath("//section")

htmlElement.getByXPath(".//section")

它们是否都意味着仅在 htmlElement 内部搜索 section 元素? (而不是从 dom 根开始的整个 xml)

第一个 //section 将检索所有 <section> 元素在文档中的任何位置,并且与上下文无关。

第二个 .//section 将考虑您当前所在的元素(通常在 XSL 转换中),因此它将仅检索 <section> 所代表的节点中的 htmlElement变量。我不知道 htmlunit,但在 XPath 中,等效项是 descendant::section.