Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
fontane-notizbuecher
SADE
Commits
e28a037b
Commit
e28a037b
authored
Aug 23, 2018
by
Mathias Goebel
🎠
Browse files
toc api
parent
20456fe3
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
modules/fontane/toc-api.xq
0 → 100644
View file @
e28a037b
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+"
,
""
)
}
}
}
}
}
}
}
}
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment