title: Get all ancestors of current node
body: <p>I want to get all ancestors of current node:</p>
  
  <p><img src="https://i.stack.imgur.com/ls5co.gif"></p>
  
  <p>XML:</p>
  
  <pre><code>&lt;root&gt;
     &lt;item title="a"&gt;
         &lt;item title="b"&gt;               
             &lt;item title="c"&gt;&lt;/item&gt; &lt;!--CURRENT--&gt;
             &lt;item title="d"&gt;&lt;/item&gt;                 
          &lt;/item&gt; 
         &lt;item title="x"&gt;             
             &lt;item title="y"&gt;&lt;/item&gt; 
             &lt;item title="z"&gt;&lt;/item&gt;  
         &lt;/item&gt;            
     &lt;/item&gt; 
  &lt;/root&gt;
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>&lt;item title="a"&gt;...&lt;/item&gt;
  &lt;item title="b"&gt;...&lt;/item&gt;
  </code></pre>
  
  <p>Edit:
  Answers with axes ancestor are fine. 
  My problem was elsewhere, in XSLT</p>
  
  <p>XSLT:</p>
  
  <pre><code>&lt;xsl:variable name="curr" select="//item[@title = 'c']"&gt;&lt;/xsl:variable&gt;
  &lt;xsl:variable name="test" select="$curr/ancestor::item"&gt;&lt;/xsl:variable&gt;
  
  &lt;xsl:for-each select="$test/item"&gt;
  &lt;xsl:value-of select="@title"&gt;&lt;/xsl:value-of&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>bcdx
  </code></pre>
  
  <hr>
  
  <p><strong>Edit2:</strong> for dimitre and for all who have a similar problem</p>
  
  <p>All the answers to my question were good.</p>
  
  <p>Just XSLT (up) returns to me a strange result and @Mads Hansen corrected me.</p>
  
  <p>FINAL WORKING EXAMPLE:</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;root&gt;
     &lt;item title="a"&gt;
         &lt;item title="b"&gt;               
             &lt;item title="c"&gt;&lt;/item&gt; 
             &lt;item title="d"&gt;&lt;/item&gt;                 
          &lt;/item&gt; 
         &lt;item title="x"&gt;             
             &lt;item title="y"&gt;&lt;/item&gt; 
             &lt;item title="z"&gt;&lt;/item&gt;  
         &lt;/item&gt;            
     &lt;/item&gt; 
  &lt;/root&gt;
  </code></pre>
  
  <p>XSLT:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:template match="/"&gt;
          &lt;xsl:variable name="curr" select="//item[@title = 'c']"&gt;&lt;/xsl:variable&gt;
          &lt;xsl:variable name="test" select="$curr/ancestor::item"&gt;&lt;/xsl:variable&gt;
  
          &lt;xsl:for-each select="$test"&gt;
              &lt;xsl:value-of select="@title"&gt;&lt;/xsl:value-of&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>ab
  </code></pre>