title: How to check if ancestor is last element of that type in his ancestor
body: <p>I have a following XML:</p>
  
  <pre><code>&lt;TABLE&gt;
    &lt;ROW&gt;
      &lt;ENTRY/&gt;
      &lt;ENTRY/&gt;
    &lt;/ROW&gt;
    &lt;ROW&gt;
      &lt;ENTRY&gt;xxx&lt;/ENTRY&gt;
      &lt;ENTRY&gt;yyy&lt;/ENTRY&gt;
    &lt;/ROW&gt;
    &lt;Z&gt;
      &lt;ROW&gt;
        &lt;ENTRY/&gt;
        &lt;ENTRY/&gt;
      &lt;/ROW&gt;
    &lt;/Z&gt;
    &lt;ROW&gt;
      &lt;ENTRY/&gt;
      &lt;ENTRY/&gt;
    &lt;/ROW&gt;
  &lt;/TABLE&gt;
  </code></pre>
  
  <p>The table structure can change, so I could have last row wrapped in Z element, or there could be no Z element at all.</p>
  
  <p>My goal is to remove the bottom border in entries of the last row in table.
  (TABLE maps to HTML table, ROW to HTML tr, ENTRY to HTML td)</p>
  
  <p>so I try to use xslt template:</p>
  
  <pre><code>&lt;xsl:template match="ENTRY"&gt;
    &lt;td&gt;
      &lt;xsl:if test="(ancestor::ROW[1] = ancestor::TABLE[1]/descendant::ROW[last()])"&gt;
        &lt;!-- remove the bottom border of td --&gt;
      &lt;/xsl:if&gt;  
    &lt;/td&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>But it removes the border from almost all the cells in table (the border is not removed from cells that have text content). So i guess the mechanism checks if the nodes have the same value (name, text content, children and so on) - not references.
  I've tried to use some external function in java, but I always get a new reference of node (even for the same nodes) so I can't compare it.</p>
  
  <p>So my question is - how to compare the references of nodes...
  or do the job in any other way.</p>
  
  <p>Thanks in advance :).</p>