title: What is the order returned by descendants-or-self, and how does it work with child axis?
body: <p>I am reading the standard for XPath and trying to understand how a portion of it works.</p>
  
  <p><a href="http://www.w3.org/TR/xpath/" rel="nofollow">http://www.w3.org/TR/xpath/</a></p>
  
  <p>The xpath standard does not seem to call out the order in which descendants-or-self gets evaluated (context node first, or descendants first). At one stage in the RFC it says it returns all the descendants and the context if it exists. At another stage it says the opposite - that it returns the context node and all the descendants.</p>
  
  <p>My question is: What's the behavior of this XPath:</p>
  
  <pre><code>/a//c
  </code></pre>
  
  <p>From a logical point of view, this is supposed to do a depth-first search. And thus, for the following XML:</p>
  
  <pre><code>&lt;a&gt;
    &lt;b&gt;
      &lt;c v="1"/&gt;
    &lt;/b&gt;
    &lt;c v="2"/&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>The logical (and the one that seems to be the actual one) behavior here seems to be that the result would be:</p>
  
  <pre><code>c (v="1")
  c (v="2")
  </code></pre>
  
  <p>However, according to the RFC, //c is equivalent to:</p>
  
  <pre><code>/descendant-or-self::node()/child::c
  </code></pre>
  
  <p>Which means, if I am getting this right, that the behavior can be different depending on how descendants-or-self is evaluated.</p>
  
  <p>If the context node is returned first, then it would seem like the result should be:</p>
  
  <pre><code>c(v="2")
  c(v="1")
  </code></pre>
  
  <p>Since the first node returned off "//" when applied to <code>a</code> is self (which is <code>a</code>). Then <code>child::c</code> is evaluated which, I think, would return <code>c(v="2")</code> since that's the first child of <code>a</code> that is <code>c</code>...</p>
  
  <p>Can someone point to the RFC part that explains why <code>c(v="1")</code> should actually be returned first?</p>