Home > OS >  What difference does a leading / (slash) make in XPath?
What difference does a leading / (slash) make in XPath?

Time:07-22

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.)

CodePudding user response:

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

  • Related