Reputation: 491
Is it possible to either use xi:include to import the results of an external xquery document or to invoke xquery from within an xml document? I know that's not really what it's necessarily intended for, but I have a situation where a series of xml documents have been created and styled using xslt. I'd like to grab a small subset from across the xml documents (a single line from multiple versions of a poem) and display it at the bottom of the page. My xquery works, but I'm trying to figure out how best to handle the next step.
This xquery:
let $q:=collection('file:/users/matt/Documents/tei/Lydgate/Quis_Dabit?select=*.xml')
for $y in $q//tei:surface
let $g := concat(substring($y/tei:graphic/@url,1,string-length($y/tei:graphic/@url)-4), '.html')
let $z := $y/tei:zone[@n="EETS.QD.4"]
let $l := $z/tei:line[@n="l.1"]
let $o := $l/tei:orig/node()
where ($z//tei:line/@n = "l.1")
return <item><ref target="{$g}">{$o}</ref></item>
`grabs all the xml documents and generates this result:
<item>
<ref target="British_Library_Harley_2255_f67r.html">
<hi xmlns="http://www.tei-c.org/ns/1.0" rend="blue_pilcrow">¶</hi>O alle ye douħtren of <hi xmlns="http://www.tei-c.org/ns/1.0" rend="underline">ierusaleem</hi>
</ref>
</item>
<item>
<ref target="Jesus_Q_G_8_f20r.html">
<hi xmlns="http://www.tei-c.org/ns/1.0">A</hi>ll the <hi xmlns="http://www.tei-c.org/ns/1.0" rend="underline">doughtren </hi>of <hi xmlns="http://www.tei-c.org/ns/1.0" rend="underline">Ier</hi>
<hi xmlns="http://www.tei-c.org/ns/1.0" rend="underline">usa</hi>
<hi xmlns="http://www.tei-c.org/ns/1.0" rend="underline">l</hi>
<hi xmlns="http://www.tei-c.org/ns/1.0" rend="underline">e</hi>
<hi xmlns="http://www.tei-c.org/ns/1.0" rend="underline">m</hi> .</ref>
</item>
<item>
<ref target="Laud_683_f78v.html">O alle ẏe douhtren of jerusaleem</ref>
</item>
Because I have the xsl structure there, I want to style it with the same xsl sheets I do the static xml pages. Which means I'd like to be able to do something like this:
<TEI xmlns="http://www.tei-c.org/ns/1.0" version="5.0" xmlns:xi="http://www.w3.org/2001/XInclude">
<teiHeader>
<fileDesc>
<titleStmt>
<title/>
</titleStmt>
<publicationStmt>
<p/>>
</publicationStmt>
<sourceDesc>
<p/>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<list>
<xi:include href="test.xq"/>
</list>
</body>
</text>
with my xsl stylesheet declaration at the top. I know it's possible if I put everything into an eXist database, but I'd really rather not add an entire platform just for the sake of this search if I can help it. Also, if I'm barking up the entirely wrong tree I'd appreciate it if someone could let me know, as well.
Upvotes: 1
Views: 190
Reputation: 57149
Let's start with the beginning: XML itself does not know anything, so to answer your first question, whether you can include (and execute, I assume!) an XQuery query by just referencing it in XML is not possible.
A workaround exists but is not trivial:
This approach would mean that your XML can only be displayed properly if it is read using your EntityReader (you could even forgo an entity reader and simply use register an XInclude URIResolver, may be simpler, but the effect is the same).
If your requirement is to simply include the XQuery script, but not execute it, you already show a correct resolution, so my guess is this is no what you are after.
Since you mention that you parse your documents using XSLT, there is another solution, assuming that the XML you show above was generated by XSLT. In XSLT 3.0, you can import a package from XQuery. This is a (very) new feature and I'm sure we don't already support it in Exselt (and we aren't planning so in the near future), but Saxon might.
But, if you go this way, you can rewrite your XQuery as XSLT (assuming your infrastructure allows this) and you'll have a simpler implementation strategy.
A last thought: if your XQuery is static, that is, if it always returns the same, there should be no need to include the XQuery. If, however, your requirement is to make your XML be dynamic, the EntityReader or URIResolver are the ways to go, but in essence, XML itself is not meant to be dynamic, but it can be the input for a next process.
Upvotes: 2