0

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.

dirkk
  • 6,160
  • 5
  • 33
  • 51
Honza Hejzl
  • 874
  • 8
  • 23

1 Answers1

1

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.

Honza Hejzl
  • 874
  • 8
  • 23
  • In XQuery, what you call "comma-separated argument lists" are known as "sequences". Functions can take sequences as arguments. To know for sure about any specific function, you can consult eXist's function documentation; for `compression:zip()` specifically, the docs are at http://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/compression&location=java:org.exist.xquery.modules.compression.CompressionModule#zip.2. Note that the `$sources` parameter must be **one or more** items of type xs:anyType (broad enough to include either database URIs or `` elements.) – Joe Wicentowski Jan 11 '16 at 18:40
  • 1
    And way to go in figuring this out! Compressing epubs in eXist works great once you've got it working. You can find more example code at https://github.com/wolfgangmm/tei-simple-pm/blob/master/modules/epub.xql. – Joe Wicentowski Jan 11 '16 at 18:41
  • Thanks, yes, the link is fll of inspiration! – Honza Hejzl Jan 12 '16 at 20:23