title: Getting position of elements in XML that refers to the element's attribute
body: <p>I have this XML.</p>
  
  <pre><code>&lt;root&gt;
      &lt;item id="first"&gt;&lt;/item&gt;
      &lt;item id="second"&gt;&lt;/item&gt;
      &lt;item id="third"&gt;&lt;/item&gt;
  
      &lt;ref ids="first"&gt;&lt;/ref&gt;
      &lt;ref ids="first second"&gt;&lt;/ref&gt;
      &lt;ref ids="third"&gt;&lt;/ref&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I want to find position of <code>&lt;ref&gt;</code> elements which are refering to <code>&lt;item&gt;</code>.
  It should look like this for XML above.</p>
  
  <pre><code>1,2
  2
  3
  </code></pre>
  
  <p>I tried to write XSLT for this but I have some problems.</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
      &lt;xsl:output method="text" encoding="utf-8" indent="no"/&gt;
  
      &lt;xsl:template match="item"&gt;
          &lt;xsl:variable name="thisId" select="@id" /&gt;
          &lt;xsl:variable name="references" select="/root/ref[contains(@ids, $thisId)]/position()" /&gt;
          &lt;xsl:value-of select="$references" separator=", " /&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <ol>
  <li>If some id is substring of other one, contains() matches it - How
  can I avoid it? </li>
  <li>position() always starts from 1 but I want real position of <code>&lt;ref&gt;</code> in XML.</li>
  </ol>
  
  <p>Do you have any ideas how to ensure this? Thank you.</p>