title: Select distinct-values according to child node in XQuery
body: <p>Let's say I have the following XML:</p>
  
  <pre><code>&lt;info&gt;
      &lt;channel&gt;
          &lt;A&gt;
            &lt;X&gt;
              &lt;title&gt;title1&lt;/title&gt;
            &lt;/X&gt;
            &lt;Y value="20"/&gt;
          &lt;/A&gt;
      &lt;/channel&gt;
      &lt;channel&gt;
          &lt;A&gt;
            &lt;X&gt;
              &lt;title&gt;title1&lt;/title&gt;
            &lt;/X&gt;
            &lt;Y value="20"/&gt;
          &lt;/A&gt;
          &lt;A&gt;
            &lt;X&gt;
              &lt;title&gt;title2&lt;/title&gt;
            &lt;/X&gt;
            &lt;Y value="20"/&gt;
          &lt;/A&gt;
      &lt;/channel&gt;
  &lt;/info&gt;
  </code></pre>
  
  <p>and the following XQuery</p>
  
  <pre><code>{
  for $A in doc('test.xml')//A
  let $TITLE := $A/X/title
  where string($A/Y/value) &gt; 20
  return
    string($TITLE)
  }
  </code></pre>
  
  <p>this, of course, outputs:</p>
  
  <pre><code>title1
  title1
  title2
  </code></pre>
  
  <p>How can I use <code>distinct-values</code> in order to remove duplicates? I wonder because <code>for</code> essentially only gives me one item per iteration and I can't call <code>distinct-values</code> on <code>$A</code>. Or is there any other way to remove duplicate output?</p>
  
  <p>The problem is that I need to refer to another node, so basically calling <code>distinct-values(doc...)</code> doesn't work, as it doesn't return nodes.</p>