0

In eXist-db (4.7) I have a long TEI-XML file from which I am creating thousands of unique TEI-XML files. I am using a function like this:

let $list := doc(concat($globalvar:URIdata,"list_collections.xml"))
let $makefile := for $bib in $list//tei:bibl[@type="collection"]
                  let $newdoc := 
                            <listBibl xmlns="http://www.tei-c.org/ns/1.0" type="collection">{$bib}</listBibl>
             return xmldb:store($globalvar:URIdata, concat($bib//@xml:id,".xml"),$newdoc)
return $makefile

Everything works fine.

However, I'd like to add a prologue to the top of each new file which points to my custom TEI schema:

<?xml-model href="../dictionaries/tei_thema.rng" 
            type="application/xml" 
            schematypens="http://relaxng.org/ns/structure/1.0"?>

Is there a way to do this within the function above? If not, is there a secondary process I can create to insert this at the top of the new file?

Many thanks in advance.

jbrehr
  • 775
  • 6
  • 19

2 Answers2

2

To construct a new document explicitly use document { } e.g. in your case

let $newdoc := document { <?xml-model href="../dictionaries/tei_thema.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>, <listBibl xmlns="http://www.tei-c.org/ns/1.0" type="collection">{$bib}</listBibl> }
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
0

To add the processing-instruction just add it as the first member of a sequence consisting of it and your content.

 let $doc = <demo></demo>
 let $newdoc := (<?xml-model href="../dictionaries/tei_thema.rng" 
        type="application/xml" 
        schematypens="http://relaxng.org/ns/structure/1.0"?>, $demo)
 return $newdoc
chrisis
  • 1,983
  • 5
  • 20
  • 17
  • The function `xmldb:store()` does not accept a sequence for the `$contents` parameter (in eXist at least): "Error....The actual cardinality for parameter 3 does not match the cardinality declared in the function's signature: xmldb:store($collection-uri as xs:string, $resource-name as xs:string?, $contents as item()) xs:string?. Expected cardinality: exactly one, got 2." – jbrehr Aug 05 '19 at 11:18
  • 1
    @jbrehr, does `let $newdoc := document { , {$bib}}` work? – Martin Honnen Aug 05 '19 at 11:32
  • @MartinHonnen thank you, works perfect! If you post it up as an answer, I'll accept. – jbrehr Aug 05 '19 at 11:36