title: Xpath selecting ancestors
body: <p>I am trying to find a formula that creates a URL for an element based on its position in the XML hierarchy.</p>
  
  <p>This is my sample xml:</p>
  
  <pre><code>&lt;Xml&gt;
      &lt;Site Url="http://mysite.abc"&gt;
          &lt;Content&gt;&lt;/Content&gt;
          &lt;SubSites&gt;
              &lt;Site Url="/sub1"&gt;
                  &lt;Content&gt;&lt;/Content&gt;
                  &lt;SubSites&gt;
                      &lt;Site Url="/sub2"&gt;
                          &lt;Content&gt;&lt;/Content&gt;
                          &lt;SubSites&gt;
                              &lt;Site Url="/sub3"&gt;
                                  &lt;Content&gt;&lt;/Content&gt;
                              &lt;/Site&gt;
                          &lt;/SubSites&gt;
                      &lt;/Site&gt;
                  &lt;/SubSites&gt;
              &lt;/Site&gt;
          &lt;/SubSites&gt;
      &lt;/Site&gt;
  &lt;/Xml&gt;
  </code></pre>
  
  <p>I have a function in Powershell that recursively iterates down from the top and on each 'Content' element I want to generate a concatenation of the ancestors Url values.
  So it should generate consecutively for each 'Content' Node:</p>
  
  <pre><code>http://mysite.abc
  http://mysite.abc/sub1
  http://mysite.abc/sub1/sub2
  http://mysite.abc/sub1/sub2/sub3
  </code></pre>
  
  <p>I use at the moment as a start:
  ( $Node = the 'Content' element )</p>
  
  <pre><code>$Sites = $Node | Select-XML -XPath  "//ancestor::Site"
  </code></pre>
  
  <p>But for every $Node it selects all the 'Site' elements.
  It would expect it to find more ancestors while going down in the xml structure.</p>
  
  <p>If someone would know how to concatenate the values directly with Xpath that would be especially great, but for starters, I would be happy to know what is going wrong with my current approach.</p>