Created
September 3, 2018 12:07
-
-
Save tuurma/1c57890db2d5634edcf695be257db28d to your computer and use it in GitHub Desktop.
basic xquery typeswitch example, assumes play is encoded in TEI like http://firstfolio.bodleian.ox.ac.uk/download/xml/F-tem.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
declare namespace tei="http://www.tei-c.org/ns/1.0"; | |
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization"; | |
declare option output:method "html5"; | |
declare option output:media-type "text/html"; | |
declare function local:transform($item) { | |
for $node in $item | |
return | |
typeswitch ( $node ) | |
case element(tei:head) return | |
let $level := count($node/ancestor::tei:div) | |
return element {"h" || $level} { | |
for $child in $node/node() | |
return local:transform($child) | |
} | |
case element(tei:sp) return | |
<div> | |
{ | |
for $child in $node/node() | |
return local:transform($child) | |
} | |
</div> | |
case element(tei:speaker) return | |
<h4> | |
{ | |
for $child in $node/node() | |
return local:transform($child) | |
} | |
</h4> | |
case element(tei:stage) return | |
<h5> | |
{ | |
for $child in $node/node() | |
return local:transform($child) | |
} | |
</h5> | |
case text() | |
return $node | |
default return | |
for $child in $node/node() | |
return local:transform($child) | |
}; | |
let $doc := doc("/db/F-tem.xml")/tei:TEI | |
return local:transform($doc//tei:text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment