Skip to content

Instantly share code, notes, and snippets.

@jonathanrobie
Created June 18, 2014 00:00
Show Gist options
  • Save jonathanrobie/760032f9c9a304be7045 to your computer and use it in GitHub Desktop.
Save jonathanrobie/760032f9c9a304be7045 to your computer and use it in GitHub Desktop.
declare default element namespace "http://www.tei-c.org/ns/1.0";
declare function local:is-person($s as element(stage), $who as xs:string)
as xs:boolean
{
$s/@who ! tokenize(., "(#)|( #)") = $who
};
declare function local:next-exit($scene as element(div2), $entrance as element(stage), $who as xs:string)
as element(stage)
{
let $following := $entrance/following::stage[local:is-person(., $who)][@type='exit' or (@type='business' and .//w='dies')]
let $same-scene := $following intersect $scene//stage
return ($same-scene)[1]
};
declare function local:enter-and-exit($act as element(div1), $scene as element(div2), $who as xs:string)
{
for $entrance in $scene//stage
where local:is-person($entrance, $who)
and $entrance/@type='entrance'
let $exit := local:next-exit($scene, $entrance, $who)
return
<window act="{$act/@n}" scene="{$scene/@n}">
<enter>{ $entrance/@n, $entrance/@who, normalize-space($entrance) }</enter>
<exit>{ $exit/@n, $exit/@who, normalize-space($exit) }</exit>
</window>
};
for $act in //div1[@type='act']
for $scene in $act//div2[@type='scene']
return local:enter-and-exit($act, $scene, 'Caesar_JC')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment