What does. // mean in XPath?
.
- the current node; it is smaller for self::node()
.
//
- descendant axis; it is smaller for /descendant-or-self::node()/
.
Together .//
will select along the offspring axis, starting at the current node. Contrast this with a help //
that starts at the document root.
Example
Consider the following HTML:
<html>
<body>
<div id="id1">
<p>First paragraph</p>
<div>
<p>Second paragraph</p>
</div>
</div>
<p>Third paragraph</p>
</body>
</html>
//p
will select all paragraphs:
<p>First paragraph</p>
<p>Second paragraph</p>
<p>Third paragraph</p>
On the other hand, if the current node is in an element div
(with @id
of "id1"
), then only paragraphs under the current node will be selected .//p
<p>First paragraph</p>
<p>Second paragraph</p>
Note that the third paragraph is not selected .//p
when the current node is id1
div
, because the third paragraph is not under this element div
.
source to share