Commit 41d306c7 authored by mrodzis's avatar mrodzis 🐸 Committed by Mathias Goebel
Browse files

Closes #89

parent a6c97c7c
xquery version "3.1";
(:~
: This module is responsible for getting an XML version of the abbreviations
: index which can be converted to TeX. This XML version is appended to
: fontane-full.xml during the creation of the intermediate format in etTransfo.xmq.
:
: @author Michelle Weidling
: @version 0.1
: @since v4.0.
:)
module namespace abbrev-index="http://fontane-nb.dariah.eu/abbrev-index";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../../config/config.xqm";
declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare function abbrev-index:main() as node() {
let $docs-coll := collection("/db/sade-projects/textgrid/data/xml/doku/")
let $file := $docs-coll[matches(base-uri(.), "verzeichnis_der_abkuerzungen")]/*
let $transformed :=
abbrev-index:transform($file)
=> abbrev-index:tidy()
return
element tei:div {
attribute type {"abbrev-index"},
$transformed
}
};
(:~
: Handles the transformation to XML.
:
: @param $nodes The nodes currently processed
: @return The transformed nodes
:)
declare function abbrev-index:transform($nodes as node()*) as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
if(matches($node, "important")
or matches($node, "Gesamtdokumentation")) then
()
else
$node
case element(xhtml:h2) return
()
case element(xhtml:h3) return
element tei:head {
attribute type {"table-head"},
abbrev-index:transform($node/node())
}
case element(xhtml:tr) return
element tei:row {
if($node/ancestor::xhtml:thead
or $node/child::xhtml:th) then
attribute role {"head"}
else
(),
abbrev-index:transform($node/node())
}
case element(xhtml:td) return
element tei:cell {
abbrev-index:transform($node/node())
}
case element(xhtml:th) return
element tei:cell {
abbrev-index:transform($node/node())
}
case element(xhtml:thead) return
abbrev-index:transform($node/node())
case element(xhtml:br) return
element tei:lb {
abbrev-index:transform($node/node())
}
case element(xhtml:i) return
()
case element(xhtml:a) return
if($node/text()) then
abbrev-index:transform($node/node())
else
()
case element(xhtml:span) return
abbrev-index:transform($node/node())
default return
element {QName("http://www.tei-c.org/ns/1.0", $node/local-name())} {
abbrev-index:transform($node/node())
}
};
(:~
: Removes empty elements.
:
: @param $nodes The nodes currently processed
: @return The transformed nodes
:)
declare function abbrev-index:tidy($nodes as node()*) as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
$node
default return
if($node//text()[matches(., "[\w\d]") and not(normalize-space(.) = "")]
or $node[self::tei:lb]) then
element {QName("http://www.tei-c.org/ns/1.0", $node/local-name())} {
$node/@*,
abbrev-index:tidy($node/node())
}
else
()
};
...@@ -16,6 +16,7 @@ module namespace etTransfo="http://fontane-nb.dariah.eu/etTransfo"; ...@@ -16,6 +16,7 @@ module namespace etTransfo="http://fontane-nb.dariah.eu/etTransfo";
declare namespace tei="http://www.tei-c.org/ns/1.0"; declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xi="http://www.w3.org/2001/XInclude"; declare namespace xi="http://www.w3.org/2001/XInclude";
import module namespace abbrev-index="http://fontane-nb.dariah.eu/abbrev-index" at "abbrev-index.xqm";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../../config/config.xqm"; import module namespace config="http://textgrid.de/ns/SADE/config" at "../../config/config.xqm";
import module namespace fontaneSimple="http://fontane-nb.dariah.eu/teisimple" at "tei2teisimple.xqm"; import module namespace fontaneSimple="http://fontane-nb.dariah.eu/teisimple" at "tei2teisimple.xqm";
import module namespace fsort="http://fontane-nb.dariah.eu/sort" at "sort.xqm"; import module namespace fsort="http://fontane-nb.dariah.eu/sort" at "sort.xqm";
...@@ -171,6 +172,12 @@ declare function etTransfo:create-print-tei() as xs:string { ...@@ -171,6 +172,12 @@ declare function etTransfo:create-print-tei() as xs:string {
etTransfo:get-literature() etTransfo:get-literature()
} catch * { } catch * {
error(QName("error", "ETTRANSFO06"), "An error occured while creating the bibliography.") error(QName("error", "ETTRANSFO06"), "An error occured while creating the bibliography.")
},
try {
abbrev-index:main()
} catch * {
error(QName("error", "ETTRANSFO07"), "An error occured while creating the index of abbreviations.")
} }
} }
return return
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment