title: How to use only distinct values within XSLT for-each loop
body: <p>I am trying to retrieve only distinct values of an element. This is my XML:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;LaunchedMeterClass id="584e348b-2a06-42d0-a858-b8909f579238-St-4M-Template-Standard-cF"&gt;
      &lt;property key="ClusterContractUUID" value="c2cebd90-9265-4cea-8018-0aac6efcced2"/&gt;
      &lt;property key="MeterClassTypeCode" value="cF"/&gt;
  &lt;/LaunchedMeterClass&gt;
  &lt;LaunchedMeterClass id="584e348b-2a06-42d0-a858-b8909f579238-St-4M-Template-Standard-cE"&gt;
      &lt;property key="ClusterContractUUID" value="c2cebd90-9265-4cea-8018-0aac6efcced2"/&gt;
      &lt;property key="MeterClassTypeCode" value="cE"/&gt;
  &lt;/LaunchedMeterClass&gt;
  &lt;LaunchedMeterClass id="584e348b-2a06-42d0-a858-b8909f579238-St-4M-Template-Standard-cC"&gt;
      &lt;property key="ClusterContractUUID" value="d0c9f440-172c-49ad-9b95-cddce23f16fa"/&gt;
      &lt;property key="MeterClassTypeCode" value="cC"/&gt;
  &lt;/LaunchedMeterClass&gt;
  &lt;LaunchedMeterClass id="584e348b-2a06-42d0-a858-b8909f579238-St-4M-Template-Standard-cD"&gt;
      &lt;property key="ClusterContractUUID" value="d0c9f440-172c-49ad-9b95-cddce23f16fa"/&gt;
      &lt;property key="MeterClassTypeCode" value="cD"/&gt;
  &lt;/LaunchedMeterClass&gt;
  </code></pre>
  
  <p>I want to create an XPath to get only those "LaunchedMeterClass" nodes having an unique value for <code>&lt;property key="ClusterContractUUID"&gt;</code>. At the moment, I am using the following:</p>
  
  <pre><code>&lt;xsl:for-each select="./descendant::LaunchedMeterClass"&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test="./property/@key='ClusterContractUUID'"&gt;
              &lt;contract-type&gt;
                  &lt;property&gt;
                      &lt;xsl:attribute name="key"&gt;ClusterContractUUID&lt;/xsl:attribute&gt;
                      &lt;xsl:attribute name="value"&gt;
                          &lt;xsl:value-of select="./property[@key='ClusterContractUUID']/@value"/&gt;
                      &lt;/xsl:attribute&gt;
                  &lt;/property&gt;
              &lt;/contract-type&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
              &lt;contract-type&gt;
                  &lt;property&gt;
                      &lt;xsl:attribute name="key"&gt;contractTypeCategory&lt;/xsl:attribute&gt;
                  &lt;/property&gt;
              &lt;/contract-type&gt;
          &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>But this gives me all the elements including duplicates:</p>
  
  <pre><code>&lt;contract-type&gt;
      &lt;property key="ClusterContractUUID" value="c2cebd90-9265-4cea-8018-0aac6efcced2"/&gt;
  &lt;/contract-type&gt;
  &lt;contract-type&gt;
      &lt;property key="ClusterContractUUID" value="c2cebd90-9265-4cea-8018-0aac6efcced2"/&gt;
  &lt;/contract-type&gt;
  &lt;contract-type&gt;
      &lt;property key="ClusterContractUUID" value="d0c9f440-172c-49ad-9b95-cddce23f16fa"/&gt;
  &lt;/contract-type&gt;
  &lt;contract-type&gt;
      &lt;property key="ClusterContractUUID" value="d0c9f440-172c-49ad-9b95-cddce23f16fa"/&gt;
  &lt;/contract-type&gt;
  </code></pre>
  
  <p>How can I write an XPath which gives only distinct values? My desired output is:</p>
  
  <pre><code>&lt;contract-type&gt;
      &lt;property key="ClusterContractUUID" value="c2cebd90-9265-4cea-8018-0aac6efcced2"/&gt;
  &lt;/contract-type&gt;
  &lt;contract-type&gt;
      &lt;property key="ClusterContractUUID" value="d0c9f440-172c-49ad-9b95-cddce23f16fa"/&gt;
  &lt;/contract-type&gt;
  </code></pre>
  
  <p>Thank you in advance for your help!</p>