title: Selecting unique records in XSLT/XPath
body: <p>I have to <strong>select only unique records</strong> from an XML document, in the context of an <code>&lt;xsl:for-each&gt;</code> loop. I am limited by Visual Studio to using <strong>XSL 1.0</strong>.</p>
  
  <pre><code>    &lt;availList&gt;
          &lt;item&gt;
            &lt;schDate&gt;2010-06-24&lt;/schDate&gt;              
            &lt;schFrmTime&gt;10:00:00&lt;/schFrmTime&gt;
            &lt;schToTime&gt;13:00:00&lt;/schToTime&gt;
            &lt;variousOtherElements&gt;&lt;/variousOtherElements&gt;
          &lt;/item&gt;
          &lt;item&gt;
            &lt;schDate&gt;2010-06-24&lt;/schDate&gt;              
            &lt;schFrmTime&gt;10:00:00&lt;/schFrmTime&gt;
            &lt;schToTime&gt;13:00:00&lt;/schToTime&gt;
            &lt;variousOtherElements&gt;&lt;/variousOtherElements&gt;
          &lt;/item&gt;
          &lt;item&gt;
            &lt;schDate&gt;2010-06-25&lt;/schDate&gt;              
            &lt;schFrmTime&gt;10:00:00&lt;/schFrmTime&gt;
            &lt;schToTime&gt;12:00:00&lt;/schToTime&gt;
            &lt;variousOtherElements&gt;&lt;/variousOtherElements&gt;
          &lt;/item&gt;
          &lt;item&gt;
            &lt;schDate&gt;2010-06-26&lt;/schDate&gt;              
            &lt;schFrmTime&gt;13:00:00&lt;/schFrmTime&gt;
            &lt;schToTime&gt;14:00:00&lt;/schToTime&gt;
            &lt;variousOtherElements&gt;&lt;/variousOtherElements&gt;
          &lt;/item&gt;
          &lt;item&gt;
            &lt;schDate&gt;2010-06-26&lt;/schDate&gt;              
            &lt;schFrmTime&gt;10:00:00&lt;/schFrmTime&gt;
            &lt;schToTime&gt;12:00:00&lt;/schToTime&gt;
            &lt;variousOtherElements&gt;&lt;/variousOtherElements&gt;
          &lt;/item&gt;
      &lt;/availList&gt;
  </code></pre>
  
  <p>The uniqueness must be based on the value of the three child elements: <code>schDate</code>, <code>schFrmTime</code> and <code>schToTime</code>. If two <code>item</code> elements have the same values for all three child elements, they are duplicates. In the above XML, <strong>items one and two are duplicates</strong>. The rest are unique. As indicated above, <strong>each item contains other elements that we do not wish to include in the comparison</strong>. 'Uniqueness' should be a factor of those three elements, and those alone.</p>
  
  <p>I have attempted to accomplish this through the following:</p>
  
  <pre><code>availList/item[not(schDate = preceding:: schDate and schFrmTime = preceding:: schFrmTime and schToTime = preceding:: schToTime)]
  </code></pre>
  
  <p>The idea behind this is to select records where there is no preceding element with the same <code>schDate</code>, <code>schFrmTime</code> and <code>schToTime</code>. However, its output is <strong>missing the last item</strong>. This is because my XPath is actually excluding items where <strong>all of the child element values are matched within the entire preceding document</strong>. No single <code>item</code> matches all of the last item's child elements - but because each element's value is individually present in another item, the last item gets excluded.</p>
  
  <p>I could get the correct result by comparing <strong>all child values as a concatenated string</strong> to <strong>the same concatenated values for each preceding item</strong>. Does anybody know of a way I could do this?</p>