title: How can I remove duplicate nodes in XQuery?
body: <p>I have an XML document I generate on the fly, and I need a function to eliminate any duplicate nodes from it.</p>
  
  <p>My function looks like:</p>
  
  <pre><code>declare function local:start2() {
      let $data := local:scan_books()
      return &lt;books&gt;{$data}&lt;/books&gt;
  };
  </code></pre>
  
  <p>Sample output is:</p>
  
  <pre><code>&lt;books&gt;
    &lt;book&gt;
      &lt;title&gt;XML in 24 hours&lt;/title&gt;
      &lt;author&gt;Some Guy&lt;/author&gt;  
    &lt;/book&gt;
    &lt;book&gt;
      &lt;title&gt;XML in 24 hours&lt;/title&gt;
      &lt;author&gt;Some Guy&lt;/author&gt;  
    &lt;/book&gt;
  &lt;/books&gt;
  </code></pre>
  
  <p>I want just the one entry in my books root tag, and there are other tags, like say pamphlet in there too that need to have duplicates removed. Any ideas?</p>
  
  <hr>
  
  <p>Updated following comments. By unique nodes, I mean remove multiple occurrences of nodes that have the exact same content and structure.</p>