Q:

XQuery – passing a list of parameters

I can’t figure out a bit trivial thing!
I need to automatize packing of ePubs from TEI XML. I know how to use compression but can’t pass list of arguments programmatically. The problem is I want to take a list made from a set of divs and pass it to the function as arguments.
Instead of
let $entries := (<entry>x</entry>, <entry>y</entry>)
compression:zip($entries, true())

I need to do something like
let $header := (<header>xyz</header>)
let $divs := (
  for $book in doc('./file.xml')
  return $book//tei:div[@n='1']
)
let $entries := (
  for $div in $divs
  return <entry>{$div}</entry>
 )
compression:zip($entries, $header, true())

I simply can’t pass extracted divs as a comma-separated list of arguments (as the compressing needs). If I could use something like array iteration or path joining, it would be fine!
I am very close with
for $chapter at $count in doc('./bukwor.xml')//tei:div[@n='1']
  return
    <entry name="chapter-{$count}"> type="xml">{$chapter}</entry>

but still can’t do the magic.

A:

Got it (thanks to https://en.wikibooks.org/wiki/XQuery/DocBook_to_ePub).
The compression:zip function takes comma-separated argument lists as well as lists unseparated. It is legal to do
let $chaps := 
(
  for $chapter at $count in doc('./file.xml')//tei:div[@n='1']
  return
    <entry name="OEBPS/chapter-{$count}.xhtml" type="xml">{$chapter}</entry>
)
let $entries := 
(
  <entry name="mimetype" type="text" method="store">application/epub+zip</entry>,
  <entry>XYZ</entry>,
  $chaps
)

The last $chaps entry gathers right files and adds them to the archive.

