I don't speak XQuery well enough to do this off the top of my head
(plenty of others on this list can), but it is easy to do in XSLT,
so it is probably easy in XQuery, too.
But it is worth quickly pointing out that (what I think is) your
instinct is right: as I read the spec, an 'xml-model' processing
instruction is only used when it is a child of the document root that
occurs before the outermost element. So those that appear in every
TEI element may be useful to humans, but should be ignored by XML
 <xsl:processing-instruction name="xml-model">href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction>
> I've created an xquery file (see below) which generates a teiCorpus
> document from a collection of TEI files. I've also created a TEI
> customization. Is there a way to have xquery or eXist insert an <?xml-model
> ?> statement at the head of the corpus document, with the URL pointing to
> my TEI customization RNG file? I've noticed that inside the corpus file,
> these xml-model statements appear before every TEI element.