title: XSLT - XPath, deepest element of certain type
body: <p>I'm trying to find out a way that ensure that the element of interest does not (recursively) contain a "identical" element. E.g.:</p>
  
  <pre><code>&lt;Ev&gt;
     &lt;Ev attr="0"&gt;
        &lt;Ev someOtherAttr="str1"&gt;
           &lt;Ev attr="1"&gt;
              &lt;Ev&gt;
              &lt;/Ev&gt;
           &lt;/Ev&gt;
        &lt;/Ev&gt;
     &lt;/Ev&gt;
  &lt;/Ev&gt;
  </code></pre>
  
  <p>Here, I would like to make sure that the element I have is the deepest one with attribute named attr (The attribute value is could be arbitrary and should not be matched nor taken into consideration).</p>
  
  <p>So, in this case I would like to select <code>&lt;Ev attr="1"&gt;</code> out of the two "indentical" elements:</p>
  
  <p><code>&lt;Ev attr="0"&gt;</code> and <code>&lt;Ev atttr="1"&gt;</code></p>
  
  <p><strong>What I've been aiming at:</strong></p>
  
  <pre><code>&lt;xsl:for-each select="//Ev/@attr"&gt;
      &lt;xsl:if select="//*[not(child::Ev/@attr)]"&gt;
          &lt;xsl:value-of select="count(ancestor::node())"/&gt;
      &lt;/xsl:if&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>But the <strong>if</strong> part is not good of course, perhaps a for-each <code>select="&lt;condition_a&gt; and not(&lt;condition_b&gt;)"</code> would be the way to go?</p>
  
  <p><strong>(Edited the question with what I've tried)</strong></p>
  
  <p>Best Regards,
  Mr. Pistol</p>