-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.xqm
More file actions
68 lines (61 loc) · 2.31 KB
/
Copy pathview.xqm
File metadata and controls
68 lines (61 loc) · 2.31 KB
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
63
64
65
66
67
68
module namespace view = 'http://localhost/view';
import module namespace ead3 = 'http://localhost/ead3' at "EAD3.xqm" ;
(: NOTE: Only stylesheet locations for EAD2002 have been updated in this module
Others would need to be updated to display other document types.
:)
(:~ Parses a XTF-like view URL i.e. a single docId param with additional params separated by ";" : ?docId=document-path;chunk.id=c2;toc.id=t2 :)
declare
%rest:path( '/view')
%rest:query-param( "docId", "{$query}", "")
%rest:query-param( "ead3", "{$ead3}", "" )
%rest:GET
%output:method('html')
%output:version( '5.0')
function view:view( $query as xs:string, $ead3 as xs:string? ) {
let $params := map:merge( for $p in tokenize( concat( 'docId=', $query), ';' )
return apply( map:entry#2, array{ tokenize($p, '=') }) )
let $doc := doc( $params('docId'))
return switch( view:doctype( $params('docId') ))
case 'EAD2002'
return
if ( $ead3 ) then
ead3:EAD2002toHTML( view:xinclude($doc) )
else
xslt:transform( util:strip-namespaces( xslt:transform( view:xinclude($doc), 'static/xslt/EAD2002-cToCn.xsl' ) ),
"https://ead.lib.virginia.edu/vivaxtf/style/dynaXML/docFormatter/VIVAead/eadDocFormatter.xsl" ,
$params )
case 'EAD3'
return ead3:EAD3toHTML( $doc )
default return $doc
};
(:~ dispatch on doctype: first try namespace and then root element :)
declare
function view:doctype( $path as xs:string ) {
let $doc := doc($path)
let $node := $doc/*
let $ns := namespace-uri($node)
return switch ( $ns )
case 'urn:isbn:1-931666-22-9'
return 'EAD2002'
case 'http://ead3.archivists.org/schema/'
return 'EAD3'
case 'http://www.tei-c.org/ns/1.0' (: TEIP5 :)
return 'TEIP5'
case 'http://www.w3.org/1999/xhtml' (: XHTML :)
return 'xhtml'
default return typeswitch ($node)
case element(ead) (: no namespace, assume EAD2002 :)
return "EAD2002"
case element(TEI) (: TEIP5 :)
return "TEIP5"
case element(TEI.2) (: TEIP4 :)
return "TEIP4"
case element(HTML) (: html :)
return "html"
case element(html) (: html :)
return "html"
default return name($node)
};
declare function view:xinclude( $doc ) {
xslt:transform( $doc, 'static/xslt/xipr.xsl' )
};