title: XQuery/XPath: Using count() and max() function for return of element with highest count
body: <p>I have an XML file that contains authors and editors.</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;?oxygen RNGSchema=&quot;file:textbook.rnc&quot; type=&quot;compact&quot;?&gt;
  &lt;books xmlns=&quot;books&quot;&gt;
  
      &lt;book ISBN=&quot;i0321165810&quot; publishername=&quot;OReilly&quot;&gt;
          &lt;title&gt;XPath&lt;/title&gt;
          &lt;author&gt;
              &lt;name&gt;
                  &lt;fname&gt;Priscilla&lt;/fname&gt;
                  &lt;lname&gt;Walmsley&lt;/lname&gt;
              &lt;/name&gt;
          &lt;/author&gt;
          &lt;year&gt;2007&lt;/year&gt;
          &lt;field&gt;Databases&lt;/field&gt;
      &lt;/book&gt;
  
      &lt;book ISBN=&quot;i0321165812&quot; publishername=&quot;OReilly&quot;&gt;
          &lt;title&gt;XQuery&lt;/title&gt;
          &lt;author&gt;
             &lt;name&gt;
                 &lt;fname&gt;Priscilla&lt;/fname&gt;
                 &lt;lname&gt;Walmsley&lt;/lname&gt;
              &lt;/name&gt;
          &lt;/author&gt;
          &lt;editor&gt;
              &lt;name&gt;
                  &lt;fname&gt;Lisa&lt;/fname&gt;
                  &lt;lname&gt;Williams&lt;/lname&gt;
              &lt;/name&gt;
          &lt;/editor&gt;
          &lt;year&gt;2003&lt;/year&gt;
          &lt;field&gt;Databases&lt;/field&gt;
      &lt;/book&gt;
  
      &lt;publisher publishername=&quot;OReilly&quot;&gt;
          &lt;web-site&gt;www.oreilly.com&lt;/web-site&gt;
          &lt;address&gt;
              &lt;street_address&gt;hill park&lt;/street_address&gt;
              &lt;zip&gt;90210&lt;/zip&gt;
              &lt;state&gt;california&lt;/state&gt;
          &lt;/address&gt;
          &lt;phone&gt;400400400&lt;/phone&gt;
          &lt;e-mail&gt;oreilly@oreilly.com&lt;/e-mail&gt;
          &lt;contact&gt;
              &lt;field&gt;Databases&lt;/field&gt;
              &lt;name&gt;
                  &lt;fname&gt;Anna&lt;/fname&gt;
                  &lt;lname&gt;Smith&lt;/lname&gt;
              &lt;/name&gt;
          &lt;/contact&gt;
      &lt;/publisher&gt;
  &lt;/books&gt;
  </code></pre>
  <p>I'm looking for a way to return the person who has been listed the most times as an author and/or editor. The solution should be XQuery 1.0 (XPath 2.0) compatible.</p>
  <p>I was thinking about using a FLWOR query to iterate through all authors and editors, then doing a count of unique authors/editors, then returning the author(s)/editor(s) that match the highest count. But I haven't been able to find the proper solution.</p>
  <p>Does anyone have any suggestion as to how such a FLWOR query would be written?
  Could this be done in a simpler way, using XPath?</p>