title: How to get the value of a sibling node in XSLT within a for-each loop
body: <p>I am trying to get the value stored in a sibling node in a for-each loop with distinct values of another sibling node:</p>
  
  <p>My XML:</p>
  
  <pre><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="OVClustered" value="true"/&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="OVClustered" value="true"/&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="OVClustered" value="false"/&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="OVClustered" value="false"/&gt;
  &lt;/LaunchedMeterClass&gt;
  </code></pre>
  
  <p>My XSLT (doesn't work):</p>
  
  <pre><code>&lt;xsl:choose&gt;
  &lt;xsl:when test="//LaunchedMeterClass/property/@key='ClusterContractUUID'"&gt;
      &lt;xsl:for-each select="distinct-values(descendant::property[@key='ClusterContractUUID']/@value)"&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="."/&gt;
                  &lt;/xsl:attribute&gt;
              &lt;/property&gt;
              &lt;property&gt;
                  &lt;xsl:attribute name="key"&gt;OVClustered&lt;/xsl:attribute&gt;
                  &lt;xsl:attribute name="value"&gt;
                      &lt;xsl:value-of select="following-sibling::*[1]/property[@key='OVClustered']/@value"/&gt;
                  &lt;/xsl:attribute&gt;
              &lt;/property&gt;
          &lt;/contract-type&gt;
      &lt;/xsl:for-each&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;xsl:attribute name="value"&gt;service&lt;/xsl:attribute&gt;
          &lt;/property&gt;
      &lt;/contract-type&gt;
  &lt;/xsl:otherwise&gt;
  </code></pre>
  
  <p></p>
  
  <p>My desired result:</p>
  
  <pre><code>&lt;contract-type&gt;
      &lt;property key="ClusterContractUUID" value="c2cebd90-9265-4cea-8018-0aac6efcced2"/&gt;
      &lt;property key="OVClustered" value="true"/&gt;
  &lt;/contract-type&gt;
  &lt;contract-type&gt;
      &lt;property key="ClusterContractUUID" value="d0c9f440-172c-49ad-9b95-cddce23f16fa"/&gt;
      &lt;property key="OVClustered" value="false"/&gt;
  &lt;/contract-type&gt;
  </code></pre>
  
  <p>I also tried ancestor::, descendant:: and preceding-sibling:: etc. but I always got this error: Required item type of the context item for the following-sibling axis is node(); supplied value has item type xs:anyAtomicType.</p>
  
  <p>Thank you in advance for your help!</p>