title: XSL 1.0 difference of two node sets
body: <p>I have got an XML file with a structure similar to</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
   &lt;medias&gt;
    &lt;media&gt;
      &lt;id&gt;34500&lt;/id&gt;
      &lt;refid/&gt;
    &lt;/media&gt;
    &lt;media&gt;
      &lt;id&gt;34501&lt;/id&gt;
      &lt;refid&gt;34500&lt;/refid&gt;
    &lt;/media&gt;
    &lt;media&gt;
      &lt;id&gt;34502&lt;/id&gt;
      &lt;refid&gt;34500&lt;/refid&gt;
    &lt;/media&gt;
    &lt;media&gt;
      &lt;id&gt;34503&lt;/id&gt;
      &lt;refid&gt;34501&lt;/refid&gt;
    &lt;/media&gt;
   &lt;media&gt;
      &lt;id&gt;34504&lt;/id&gt;
      &lt;ref/&gt;
   &lt;/media&gt;   
   &lt;media&gt;
      &lt;id&gt;34505&lt;/id&gt;
      &lt;refid&gt;34502&lt;/refid&gt;
   &lt;/media&gt;   
  &lt;/medias&gt;
  </code></pre>
  
  <p>With XSL 1.0, I want to access all nodes that are not referenced by others.
  So I created two variables</p>
  
  <pre><code>&lt;xsl:variable name="origID" select="media/id/text()"/&gt;
  &lt;xsl:variable name="refID" select="media/refid/text()"/&gt;
  </code></pre>
  
  <p>and looked up on how to perform a difference operation between these two element sets</p>
  
  <pre><code>&lt;xsl:variable name="diffID" select="$origID[count(. | $refID) != count($refID)]"/&gt;
  </code></pre>
  
  <p>The result was:</p>
  
  <p><em>origID contains 34500, 34501, 34502, 34503, 34504, 34505</em></p>
  
  <p><em>refID contains 34500, 34500, 34501, 34502</em></p>
  
  <p>I expected that</p>
  
  <p><em>diffID would contain 34503, 34504, 34505</em> </p>
  
  <p>but </p>
  
  <p><em>diffID still contains 34500, 34501, 34502, 34503, 34504, 34505.</em></p>
  
  <p>What would be the best approach to accomplish my objective to get all nodes whose ID is referenced by other nodes.</p>
  
  <p>Thanks in advance</p>
  
  <p>Andre</p>