title: Counting distinct first child value element of each parent in XSLT
body: <p>Using a XSLT stylesheet, I am trying to count the distinct values for each first child node of the parent element.</p>
  
  <p>Example XML:</p>
  
  <pre><code>&lt;Root&gt;
  &lt;Parent&gt;
      &lt;Child&gt;
              &lt;Child2&gt;
                &lt;Child3&gt;Value2&lt;/Child3&gt;
              &lt;/Child2&gt;
      &lt;/Child&gt;
      &lt;Child&gt;
              &lt;Child2&gt;
                &lt;Child3&gt;Value3&lt;/Child3&gt;
              &lt;/Child2&gt;
      &lt;/Child&gt;
  &lt;/Parent&gt;
   &lt;Parent&gt;
      &lt;Child&gt;
              &lt;Child2&gt;
                &lt;Child3&gt;Value2&lt;/Child3&gt;
              &lt;/Child2&gt;
      &lt;/Child&gt;
      &lt;Child&gt;
              &lt;Child2&gt;
                &lt;Child3&gt;Value2&lt;/Child3&gt;
              &lt;/Child2&gt;
      &lt;/Child&gt;
  &lt;/Parent&gt;
   &lt;Parent&gt;
      &lt;Child&gt;
              &lt;Child2&gt;
                &lt;Child3&gt;Value2&lt;/Child3&gt;
              &lt;/Child2&gt;
      &lt;/Child&gt;
      &lt;Child&gt;
              &lt;Child2&gt;
                &lt;Child3&gt;Value2&lt;/Child3&gt;
              &lt;/Child2&gt;
      &lt;/Child&gt;
  &lt;/Parent&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <p>Using my above XML example, the expected result would be 1.
  I have managed to count the distinct values for all the children by using the count function, but I can't figure out how to do it for each first child.</p>
  
  <pre><code>count(//Parent/Child/Child2/Child3[not(.=following::Child3)])
  </code></pre>