-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabels.xq
62 lines (58 loc) · 2.51 KB
/
labels.xq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
xquery version "3.1";
import module namespace cc = "http://history.state.gov/ns/xquery/apps/consular-cards" at "consular-cards.xqm";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare option output:method "html";
declare option output:html-version "5";
declare option output:media-type "text/html";
let $title := "All Labels"
let $cards-doc := collection("/db/apps/consular-cards/data")
let $cards := $cards-doc//tei:surfaceGrp
let $content :=
<div class="container">
<h2>{$title}</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Label</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{
for $card-g in $cards
let $faces := $card-g/tei:surface
let $labels := $faces//tei:f[@name eq "label"]/tei:string
let $start-years := $card-g//tei:f[@name eq "year"]/tei:string[. ne ""]
group by $label := $labels[1]
order by $label
return
<tr>
<td><a href="label.xq?label={encode-for-uri($label)}">{$label/string()}</a>
{
let $other-labels := $labels[. ne $label] => distinct-values()
return
if (exists($other-labels)) then
<ul>{
$other-labels ! <li>{.}</li>
}</ul>
else
()
}
</td>
<td>{count($card-g)} cards ({count($faces)} faces) {
let $min := min($start-years)
let $max := max($start-years)
return
if ($min eq $max) then
">" || $min
else
">" || $min || "~" || $max
}</td>
</tr>
}
</tbody>
</table>
</div>
return
cc:wrap-html($title, $content)