Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TEI:lb and other empty elements in XQuery
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare function local:magic($nodes as node()*) {
(:let $test:= console:log($nodes/local-name()):)
(:return:)
for $node in $nodes return
typeswitch($node)
case element(*)
return element
{$node/local-name()}
{ attribute lbnum {count($node/preceding::tei:lb)},
local:magic($node/node())}
case attribute(*) return $node
case text() return element span {attribute lbnum {count($node/preceding::tei:lb)},$node}
case element(tei:lb) return ($node, attribute lbnum {count($node/preceding::tei:lb) + 1})
default return ($node)
};
let $input:=
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<!-- header removed for brevity -->
<text>
<body>
<p>
<del rend="overstrike">Card room where
<lb/>
nine out of ten had no inclination</del>
<add>some text</add>
<lb/>
some more text
</p>
</body>
</text>
</TEI>
let $output :=
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<text>
<body>
<p>
<lb>
<del rend="overstrike">Card room where</del>
</lb><lb>
<del rend="overstrike">nine out of ten had no inclination</del>
</lb>
</p>
</body>
</text>
</TEI>
return
local:magic($input)
(: $input//node()[preceding-sibling::tei:lb]:)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment