I'm trying convert a xml document, organized in divisions and paragraph, with page break and line breaks as milestones into a xml document that wraps pages and lines in page and line elements.
To do this I'm trying to use util:get-fragment-between.
To first get all the lines on a page into a fragment and then turn each line into a fragment.
The first step works, but in the second step, I get the following error org.exist.dom.memtree.ElementImpl cannot be cast to org.exist.dom.persistent.StoredNode which I do not understand.
Below is the xquery file and below that of an excerpt of the xml file I'm trying to convert.
xquery version "3.1";
let $doc := doc($docpath)
(: Build first fragment of containing only lines on page:)
let $begp-node := $doc//tei:pb[@n="15-v"]
let $endp-node := $doc//tei:pb[@n="16-r"]
let $p-fragment := util:get-fragment-between($begp-node, $endp-node, $make-fragment, $display-root-namespace)
let $p-node := util:parse($p-fragment)
(: so far so good, print out of p-node gives me an xml document with just the text on page 15-v :)
(: next step. here I attempt to build a fragment for each line in the newly created page fragment :)
let $lines := $p-node//tei:lb
for $line at $pos in $lines
let $make-fragment1 := true()
let $display-root-namespace1 := true()
let $beginning-node := $line
let $ending-node := $line/following::tei:lb[1]
let $fragment := util:get-fragment-between($beginning-node, $ending-node, $make-fragment1, $display-root-namespace1)
let $node := util:parse($fragment)
return $node
I would expect $node to be a new xml document that just contains the line fragment. But instead I get the error:
org.exist.dom.memtree.ElementImpl cannot be cast to org.exist.dom.persistent.StoredNode
Here is an excerpt of the original document:
<p>
<lb ed="#L"/>dilectio <choice>
<orig>dependant</orig>
<reg>dependant</reg>
</choice> causaliter a cognitione tamen quaelibet obiecti apprehensio vel cognitio
<lb ed="#L"/>cum voluntatis libertate sufficit dilectionem causare <g ref="#slash"/> prima
probatur quia si non sequitur quod dilec
<lb ed="#L"/>tio
<lb ed="#L"/>posset poni seu elici naturaliter a voluntate seclusa omni cognitione consequens
est falsum
<pb ed="#L" n="15-v"/>
<lb ed="#L" n="1"/> quia tunc voluntas posset diligere in infinitum contra <ref>
<name ref="#Augustine">augustinum</name> in libro 8 2 10 <title ref="#deTrinitate">de
trinitate</title>
</ref> patet consequentia quia positis omnibus causis ad productionem <sic>ad productionem</sic>
alicuius effectus re
<lb ed="#L" n="2"/>quisitis
<lb ed="#L" n="3"/>omni alio secluso talis effectus posset naturaliter poni in esse <g
ref="#slash"/>2a pars probatur quia
<lb ed="#L" n="4"/>quia si sola obiecti cognitio etc sequitur quod stante iudicio vel
apprehensione alicuius
<lb ed="#L" n="5"/>obiecti sub ratione <corr>
<del rend="strikethrough">boni</del>
<add place="inLine">mali</add>
</corr> seclusa omnia existentia vel apparentia bonitatis
<lb ed="#L" n="6"/>voluntas posset tale obiectum velle vel diligere consequentia nota sed
consequens est contra <ref>
<name ref="#Aristotle">philosophum</name>
</ref> et <ref>
<name ref="#Averroes">commentatorem</name>
<lb ed="#L" n="7"/>primo <name ref="#Ethics">ethicorum</name>
</ref> quia omnia bonum appetunt
<p xml:id="pgb1q2-d1e3692">
<g ref="#pilcrow"/>primum corollarium
<lb ed="#L" n="8"/>
Any advice is much appreciated.
util:get-fragment-betweensays "This function works only on documents which are stored in eXist DB" so your attempt to apply it on the in-memory nodes you created earlier withutil:parse($p-fragment)is not possible. As for alternatives, does exist-db support thewindow clause? Seems like a use case for that with e.g. xqueryfiddle.liberty-development.net/jyyiVhq - Martin Honnenmilestone-chunkfunction; see wiki.tei-c.org/index.php/Milestone-chunk.xquery. However, if you would rework your question to be completely self-contained, well-formed, and reproducible, I'd be happy to take a closer look. - Joe Wicentowski