Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Quick answer; yes, ../ and parent::* are equivalent but you get different results because your XPath expressions are different.</p> <p>Longer answer;</p> <p>The expressions parent::node() and .. are equivalent, the latter being an abbreviated form of the former according to the <a href="http://www.w3.org/TR/xpath" rel="nofollow noreferrer">W3C XPath Recommendation</a>.</p> <p>You will get similar behaviour from parent::*, because XML forms a tree, so any child can have at most one parent.</p> <p>The reason you will get different results is because they are different queries. The first has an extra * on the end (../../*), which is probably returning the child item sequence of your Node.</p> <p>The second gets specifically the parent of the parent of the context node (in abbreviated form ../..), which is your Node element of interest.</p> <p>Example:</p> <p>For the document</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;root&gt; &lt;Node&gt; &lt;id type="image"&gt; &lt;id attr1="myVal"&gt; &lt;/id&gt; &lt;/id&gt; &lt;/Node&gt; &lt;/root&gt; </code></pre> <p>The queries</p> <pre><code>//Node/id[@type='image']/id[@attr1='myVal']/../../* </code></pre> <p>and</p> <pre><code>//Node/id[@type='image']/id[@attr1='myVal']/parent::*/parent::*/* </code></pre> <p>return the node id[@type='image']</p> <p>Whereas the queries</p> <pre><code>//Node/id[@type='image']/id[@attr1='myVal']/../.. </code></pre> <p>and</p> <pre><code>//Node/id[@type='image']/id[@attr1='myVal']/parent::*/parent::* </code></pre> <p>return the node Node.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload