Commit e28a037b authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

toc api

parent 20456fe3
xquery version "3.1";
(:~
: Provides a REST-API to get table of contents
:
: @author Mathias Göbel
: @version 1.0
: @since 2.6
: :)
module namespace toc="https://fontane-nb.dariah.eu/tocapi";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace test="http://exist-db.org/xquery/xqsuite";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
import module namespace rest="http://exquery.org/ns/restxq";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../config/config.xqm";
declare variable $toc:dataPath := "/db/sade-projects/textgrid/data/xml/data/";
declare
%rest:GET
%rest:path("fontane/toc/{$uri}")
%output:method("html")
%test:name("entities per page")
function toc:table-of-contents($uri as xs:string)
{
let $doc := doc($toc:dataPath || $uri || ".xml")
let $toc := $doc//tei:TEI/tei:teiHeader/tei:fileDesc/tei:sourceDesc/tei:msDesc/tei:msContents/tei:ab/tei:list[@type="editorial"]
return
element div {
attribute class {"container"},
element div {
attribute class {"panel-group"},
for $item at $pos in $toc/tei:item
let $heading := string($item) => substring-before(" (")
return
element div {
attribute class {"panel panel-default"},
element div { (: heading :)
attribute class {"panel-heading"},
element h4 {
attribute class {"panel-title"},
element a {
attribute href { "#collapse" || $pos },
attribute data-parent {"#accordion"},
attribute data-toggle { "collapse" },
text {$heading}
}
}
}, (: end heading :)
element div {
attribute class { "panel-collapse collapse" },
attribute id { "collapse" || $pos },
element div {
attribute class {"panel-body tocview"},
element ul {
for $ref in $item//tei:ref
let $targetPage := $ref/@target => substring-after("[@n='") => substring-before("']")
return
element li {
attribute class { "target" || $targetPage },
element a {
attribute href { "edition.html?id=/xml/data/" || $uri || ".xml&page=" || $targetPage },
text { string($ref) => replace("\s*Blatt\s+", "") }
}
}
}
}
}
}
}
}
};
Markdown is supported
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