Your first XPath expression (//body/*[1]//*[@href]
) actually represents what you described in natrual language: //body/*[1]
is the first child of the body element, and //*[@href]
selects the first element (below) having an @href
attribute.
In your example, there is no element below the anchor tag having such an attribute. Fore xample, this query would match
<html>
<body>
<p>
<a href="http://www.google.be"/>
</p>
</body>
</html>
The non-abbreviated version of this query is:
//body/*[1]/descendant-or-self::node()/*[@href]
Putting your second query in contrast, the problem should be easy to see:
//body/*[1]/descendant-or-self::node()[@href]