title: XSLT 2.0: Get elements where attributes are distinct
body: <p>I have an XML format as follows:</p>
  
  <pre><code>&lt;Items&gt;
    &lt;Item id="1"&gt;
    &lt;/Item&gt;
    &lt;Item id="2"&gt;
    &lt;/Item&gt;
    &lt;Item id="1"&gt;
    &lt;/Item&gt;
    &lt;Item id="3"&gt;
    &lt;/Item&gt;
  &lt;/Items&gt;
  </code></pre>
  
  <p>I am trying to declare an XSLT 2.0 variable that will contain all  elements where "id" is unique. If the "id" is NOT unique, only the first instance should be output, such that the variable will store:</p>
  
  <pre><code>&lt;Item id="1"&gt;
  &lt;/Item&gt;
  &lt;Item id="2"&gt;
  &lt;/Item&gt;
  &lt;Item id="3"&gt;
  &lt;/Item&gt;
  </code></pre>
  
  <p>The following code will give me all of the unique @id attributes, but NOT their parent (Item):</p>
  
  <pre><code>&lt;xsl:variable name="uniqueItems" select="distinct-values(/Items/Item/@id)"/&gt;
  </code></pre>
  
  <p>I want to do somelike this:</p>
  
  <pre><code>&lt;xsl:variable name="uniqueItems" select="distinct-values(/Items/Item/@id)/parent::node()"/&gt;
  </code></pre>
  
  <p>But this is obviously not correct.</p>