title: Return multiple values from multiple inputs in XQuery 3.0?
body: <p>I've tried a few things:</p>
  
  <pre><code>for $name in ('Hanz', 'Heinz', 'Hans', 'Huns', 'Hund')
  where $name contains text 'Hans' using fuzzy
  return $name | $name
  (: returns error: Stopped at line 3, column 20: [XPTY0004] 
  Union expression: node() expected, xs:string found. :)
  
  
  for $name in ('Hanz', 'Heinz', 'Hans', 'Huns', 'Hund')
  where $name contains text 'Hans' using fuzzy
  return $name and $name
  (: returns true :)
  
  for $name in ('Hanz', 'Heinz', 'Hans', 'Huns', 'Hund')
  where $name contains text 'Hans' using fuzzy
  return $name, $name
  (: returns error: Stopped at line 3, column 19: [XPST0008] 
  Undefined variable $name. :)
  </code></pre>
  
  <p>What I'm trying to do is just return the name variable twice.  Of course, I'd like to do something more complicated.  For example, given a doc (taken from w3):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  
  &lt;bookstore&gt;
  
  &lt;book category="COOKING"&gt;
    &lt;title lang="en"&gt;Everyday Italian&lt;/title&gt;
    &lt;author&gt;Giada De Laurentiis&lt;/author&gt;
    &lt;year&gt;2005&lt;/year&gt;
    &lt;price&gt;30.00&lt;/price&gt;
  &lt;/book&gt;
  
  &lt;book category="CHILDREN"&gt;
    &lt;title lang="en"&gt;Harry Potter&lt;/title&gt;
    &lt;author&gt;J K. Rowling&lt;/author&gt;
    &lt;year&gt;2005&lt;/year&gt;
    &lt;price&gt;29.99&lt;/price&gt;
  &lt;/book&gt;
  
  &lt;book category="WEB"&gt;
    &lt;title lang="en"&gt;XQuery Kick Start&lt;/title&gt;
    &lt;author&gt;James McGovern&lt;/author&gt;
    &lt;author&gt;Per Bothner&lt;/author&gt;
    &lt;author&gt;Kurt Cagle&lt;/author&gt;
    &lt;author&gt;James Linn&lt;/author&gt;
    &lt;author&gt;Vaidyanathan Nagarajan&lt;/author&gt;
    &lt;year&gt;2003&lt;/year&gt;
    &lt;price&gt;49.99&lt;/price&gt;
  &lt;/book&gt;
  
  &lt;book category="WEB"&gt;
    &lt;title lang="en"&gt;Learning XML&lt;/title&gt;
    &lt;author&gt;Erik T. Ray&lt;/author&gt;
    &lt;year&gt;2003&lt;/year&gt;
    &lt;price&gt;39.95&lt;/price&gt;
  &lt;/book&gt;
  
  &lt;/bookstore&gt;
  </code></pre>
  
  <p>I've tried to execute some queries I've seen in accepted answers across Stack Overflow, and I've yielded negative results.  For example:</p>
  
  <pre><code>let $sep := ','
  for $x in doc('test')/bookstore
    where fn:matches($x/book, 'XC')
    return fn:string-join( ($x/book/title/text(), $x/book/author/text(), 
    $x/book/price/text()), $sep)
  (: Stopped at line 3, column 31: [XPTY0004] Single item expected, 
  (element book { ... }, element book { ... }, ...) found. :)
  </code></pre>
  
  <p>--</p>
  
  <p>I'd like to return the author, year, and title of any book with the category attribute equal to "web", a title element whose language attribute is English and whose value is exactly "Learining XML" and whose any child contain the text "Erik T"; or whose year is later than 2003, whose any descendant contain the text XML, and whose price is less than 20.00USD.</p>
  
  <p>I think this shows the versatility of XQuery.  Without being able to return, and in fact input, a list of targets, the software is essentially useless.  I've found there is not a solid answer or tutorial that covers even a small portion of the above query; however, there are queries on how to do mathematical comparisons and order-by functions.  These are useful in their own way, but getting started, they aren't nearly as important as being able to return multiple columns of a table based on the results found therein.</p>