Recently, I needed to evaluate XQuery in a Node HTML document. Basically, I needed to select all the elements with the href attribute from the first child of the body. I added a small example to explain:
<html>
<body>
<a href="http://www.google.be"/>
</body>
</html>
The desired extraction result in this case is obviously:
<a href="http://www.google.be"/>
My first idea was to use //body/*[1]//*[@href]because:
//body matches the body element, wherever it is./*[1] matches the first child of body//*[@href] matches all descendants or itself of the current element
I decided that this would work, but in the above example, XQuery does not produce any results.
However, I read a little and found the following (source: http://www.keller.com/xslt/8/ ):
Alternate notation for "//": descendant-or-self::node()
, XQuery //body/*[1]/descendant-or-self::node()[@href], .
: // -: node()? ( // node /descendant:: node xpath?) (http://www.w3.org/TR/xpath/#axes):
// /descendant-or-self::node()/. , //parashort /descendant-or-self::node()/child::para.
, // /descendant-or-self::node() (, - / ?), - , /descendant-or-self::node()?