2

What is the difference (if exists) between the following expressions ?

  1. /descendant-or-self::node()
  2. descendant-or-self::node()

I don't understand what is the meaning of the / in this case in the beginning of the first expression.

According to the explanation from the class, the meaning of / is go down a level in the tree.

So how is this reflected here?

(According to checks that I did, it's seen that a difference does not exist, but I don't understand why according to the explain mentioned above given by my lecturer.)

kjhughes
  • 106,133
  • 27
  • 181
  • 240

1 Answers1

4

The difference is that of absolute vs relative selection.

  • An XPath starting with / is absolute (based on the root node of the document).

  • An XPath starting with an axis, or ./, is relative to the context node.

See also

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • 1
    Which means, of course, that in the common case where the context node is the same as the root node, then there is no difference between the expressions. – Michael Kay Jul 22 '22 at 09:24
  • @MichaelKay: Yes, thanks for explicitly accounting for OP's observation that there were no differences in cases he checked. JobProcessTask, a common case where the difference would manifest would be within predicates ( `[` *inside here* `]` ). – kjhughes Jul 22 '22 at 11:05