source: gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes-and-performers/transform/pages/document.xsl@ 37155

Last change on this file since 37155 was 37155, checked in by davidb, 15 months ago

Reworking of template so it doesn't need as much copy-and-paste syntax

File size: 15.0 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:java="http://xml.apache.org/xslt/java"
5 xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
6 xmlns:gslib="http://www.greenstone.org/skinning"
7 xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat"
8 extension-element-prefixes="java util"
9 exclude-result-prefixes="java util gsf">
10
11
12 <xsl:variable name="httpDocument">
13 <xsl:value-of select="$library_name"/>
14 <xsl:text>/collection/</xsl:text>
15 <xsl:value-of select="/page/pageResponse/collection/@name"/>
16 <xsl:text>/document/</xsl:text>
17 <xsl:value-of select="/page/pageRequest/paramList/param[@name = 'd']/@value"/> <!-- or use $docID from default/transform/pages/document.xsl ???? -->
18 </xsl:variable>
19
20
21 <xsl:template name="iiif-links">
22 <xsl:param name="identifier"/>
23
24 <gsf:variable name="iiifImageRootIdentifier">
25 <xsl:text>/gs-cantaloupe/iiif/2/</xsl:text><xsl:value-of select="$site_name"/>:<xsl:value-of select="$collNameChecked"/>:<xsl:value-of select="$identifier"/>
26 </gsf:variable>
27
28 <!--
29 <gsf:variable name="iiifPresentationRootIdentifier"><xsl:value-of select="$docID"/></gsf:variable>
30 -->
31
32 <gsf:variable name="iiifPresentationRootIdentifier">http-greenstone://<xsl:value-of select="$site_name"/>/<xsl:value-of select="$collNameChecked"/>/<xsl:value-of select="$docID"/></gsf:variable>
33
34 <gsf:script>
35 var chosen_title = "untitled";
36
37 if (gs.variables.chosenTitle &amp;&amp; !gs.variables.docNodeID) {
38 // simple doc
39 chosen_title = gs.variables.chosenTitle;
40 }
41 else {
42 var docNodeID = gs.variables.docNodeID;
43 var page_pos = docNodeID.indexOf('.');
44 chosen_title = (page_pos>=0) ? "page " + docNodeID.substring(page_pos+1) : docNodeID;
45 }
46
47 var iiif_doc_image = {
48 "id": document.location.origin + gs.variables.iiifImageRootIdentifier,
49 //"format": mime_type, // ???? or is it OK to always have this as image/jpeg and rely on IIIF Image Server coverting as/when needed???
50 //"chosen_title": gs.variables.chosenTitle,
51 "chosen_title": chosen_title,
52 "x_dim": gs.variables.imageWidth,
53 "y_dim": gs.variables.imageHeight,
54 };
55
56 IIIF_Doc_Images.push(iiif_doc_image);
57
58 </gsf:script>
59
60 </xsl:template>
61
62
63 <xsl:template name="opt-googlevision-ocr-json">
64 <xsl:param name="assocfilepath"/>
65
66 <gsf:variable name="GVDocumentOCRJSON"><gsf:metadata name="GVDocumentOCRJSON"/></gsf:variable>
67 <gsf:variable name="docSectionID"><xsl:value-of select="util:replace(@nodeID, '.', '_')"/></gsf:variable>
68
69 <gsf:switch>
70 <gsf:metadata name="HasGoogleVisionDocumentOCRJSON"/>
71 <gsf:when test='equals' test-value="1">
72
73 <gsf:script>
74 // Load in the Google Vision OCR JSON file and display bounding boxes for this document (docType=simple) or page (docType=paged)
75 load_gv_dococr_json(gs.variables.GVDocumentOCRJSON,gs.variables.docSectionID,display_gv_ocr_bounding_boxes);
76 </gsf:script>
77 </gsf:when>
78 </gsf:switch>
79
80 </xsl:template>
81
82
83 <xsl:template name="wrappedSectionPost">
84
85 <!-- add in IIIF Server link for section image -->
86 <xsl:variable name="nodeID" select="@nodeID"/>
87 <xsl:call-template name="iiif-links">
88 <xsl:with-param name="identifier" select="$nodeID" />
89 </xsl:call-template>
90
91 <!-- add in Google Vision OCR JSON link for section image -->
92 <xsl:call-template name="opt-googlevision-ocr-json">
93 <xsl:with-param name="assocfilepath"><gsf:metadata name="assocfilepath" select="root"/></xsl:with-param>
94 </xsl:call-template>
95
96 </xsl:template>
97
98 <xsl:template name="sectionImage">
99 <xsl:if test="$bookswitch != 'mirador'">
100 <gsf:image type="screen"/>
101 </xsl:if>
102 </xsl:template>
103
104 <xsl:template name="sectionContent">
105
106 <xsl:choose>
107 <xsl:when test="$bookswitch = 'mirador'">
108 <gsf:variable name="screenImageWidth"><gsf:metadata name="ScreenWidth"/></gsf:variable>
109 <gsf:variable name="screenImageHeight"><gsf:metadata name="ScreenHeight"/></gsf:variable>
110 <gsf:variable name="imageWidth"><gsf:metadata name="ImageWidth"/></gsf:variable>
111 <gsf:variable name="imageHeight"><gsf:metadata name="ImageHeight"/></gsf:variable>
112 <gsf:variable name="docNodeID"><xsl:value-of select="@nodeID"/></gsf:variable> <!-- used to make each 'tidyDiv' unique -->
113 </xsl:when>
114
115 <xsl:otherwise>
116 <xsl:call-template name="wrappedSectionImage"/>
117
118 <div style="padding: 10px 0px 10px 0px">Ocr'd Text:</div>
119 <i>
120 <xsl:call-template name="wrappedSectionText"/>
121 </i>
122 </xsl:otherwise>
123 </xsl:choose>
124
125 <xsl:call-template name="wrappedSectionPost"/>
126 </xsl:template>
127
128 <xsl:template name="sectionContentForEditing">
129 <xsl:call-template name="wrappedSectionImage"/>
130 <xsl:call-template name="wrappedSectionTextForEditing"/>
131 </xsl:template>
132
133 <xsl:template name="documentHeadingOLD">
134 <xsl:if test="$bookswitch != 'mirador'">
135 <span style="font-weight:bold; font-size: 120%;">
136 <xsl:call-template name="choose-title"/>
137 </span>
138 </xsl:if>
139
140 <gsf:metadata-table>
141 <gsf:metadata name="ex.im.No">Catalogue No:</gsf:metadata>
142 <gsf:metadata name="ex.im.Work">Work:</gsf:metadata>
143 <gsf:metadata name="ex.im.Artist">Artist(s):</gsf:metadata>
144 <gsf:metadata name="ex.im.Venue">Venue:</gsf:metadata>
145 <gsf:metadata name="ex.im.Composer">Composer:</gsf:metadata>
146 </gsf:metadata-table>
147
148 </xsl:template>
149
150
151 <xsl:template name="documentPre">
152 <xsl:variable name="httpCollection">library/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="/page/pageResponse/collection/@name"/></xsl:variable>
153
154 <gsf:variable name="optionIncludeFileAssocOpenAnnotations">
155 <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeFileAssocOpenAnnotations']/@value"/>
156 </gsf:variable>
157 <gsf:variable name="optionIncludeEditableOpenAnnotations">
158 <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@value"/>
159 </gsf:variable>
160 <gsf:variable name="optionIncludeEditableOpenAnnotationsEndpointURL">
161 <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@endpointURL"/>
162 </gsf:variable>
163
164
165 <gsf:variable name="chosenTitle"><xsl:call-template name="choose-title"/></gsf:variable>
166 <!-- <gsf:variable name="toplevelTitle"><gsf:metadata name="Title" select="root"/></gsf:variable> -->
167 <gsf:variable name="imageWidth"><gsf:metadata name="ImageWidth"/></gsf:variable>
168 <gsf:variable name="imageHeight"><gsf:metadata name="ImageHeight"/></gsf:variable>
169
170 <gsf:script>
171 console.log("**** chosenTitle = " + gs.variables.chosenTitle);
172 </gsf:script>
173
174 <!--
175 <gsf:script src="{$httpCollection}/js/document_viewer.js"/>
176 -->
177
178 <gsf:script src="ext/structured-image/js/document_extra.js"/>
179 <style>
180 div.ocr-boundingbox-overlay {
181 position: absolute;
182 left: 0;
183 top: 0;
184 }
185
186 div.ocr-boundingbox {
187 position: absolute;
188 border: solid black 1px;
189 }
190
191 </style>
192
193 <xsl:if test="$bookswitch = 'mirador'">
194 <gsf:script src="ext/structured-image/mirador3/dist/mirador-with-annotations.js"/>
195 <!-- Mirador, by default, uses Roboto font, so load it in -->
196 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" />
197 </xsl:if>
198
199 <gsf:script>
200 var IIIF_Doc_Images = [];
201 </gsf:script>
202
203 </xsl:template>
204
205 <xsl:template name="documentNodeTextIntermuse">
206 <xsl:param name="force">0</xsl:param>
207 <xsl:variable name="im_programme"><gsf:metadata name="im.Programme" select="root"/></xsl:variable>
208 <xsl:choose>
209 <xsl:when test="$im_programme != 'true'">
210 <gsf:switch>
211 <gsf:metadata name="ex.im.GSFriendlyProg"/>
212 <gsf:when test="exists">
213
214 <xsl:variable name="im_prognum"><gsf:metadata name="ex.im.GSFriendlyProg"/></xsl:variable>
215 <xsl:variable name="im_pagenum"><gsf:metadata name="ex.im.GSFriendlyPage"/></xsl:variable>
216 <style>
217 div.progandpage {
218 padding-top: 8px;
219 padding-bottom: 8px;
220 }
221 </style>
222 <div class="progandpage">
223 <span style="display: inline-block; width: 160px;">Greenstone Viewer:</span>
224 <a href="https://intermuse.sowemustthink.space/greenstone3/library/collection/{$collNameChecked}/document/HMS_{$im_prognum}.{$im_pagenum}">
225 Programme HMS#<xsl:value-of select="$im_prognum"/>, Page <xsl:value-of select="$im_pagenum"/>
226 </a>
227 </div>
228 <div class="progandpage">
229 <span style="display: inline-block; width: 160px;">Mirador Viewer:</span>
230 <a href="https://intermuse.sowemustthink.space/greenstone3/library/collection/{$collNameChecked}/document/HMS_{$im_prognum}?book=mirador&amp;ed=1&amp;gotoPage={$im_pagenum}">
231 Programme HMS#<xsl:value-of select="$im_prognum"/>, Page <xsl:value-of select="$im_pagenum"/>
232 </a>
233 </div>
234 </gsf:when>
235 </gsf:switch>
236
237 </xsl:when>
238 <xsl:otherwise>
239 <!-- The following is directly from default/transform/page/document.xsl -->
240 <!-- **** consider replacing with <gsf:text> ???? ... or change the name of this outer template so it can still call the default inner one -->
241 <xsl:call-template name="documentNodeText">
242 <xsl:with-param name="force" select="$force"/>
243 </xsl:call-template>
244
245 </xsl:otherwise>
246 </xsl:choose>
247 </xsl:template>
248
249
250 <xsl:template name="documentContentMirador3">
251 <xsl:if test="@docType='simple'">
252 <gsf:script>$('#tocLoadingImage').hide()</gsf:script>
253 <!-- add in IIIF Server link for simple page image -->
254 <xsl:call-template name="iiif-links">
255 <xsl:with-param name="identifier" select="$docID" />
256 </xsl:call-template>
257 </xsl:if>
258 </xsl:template>
259
260 <xsl:template name="documentContent">
261 <!-- The way document.xsl tempaltes are structured, only get to here is if @docType = 'simple' -->
262 <!-- A 'paged' (or 'hierarical') document goes throgh 'wrappedContent' -->
263
264 <div id="gs-document">
265
266 <xsl:choose>
267 <xsl:when test="$bookswitch = 'mirador'">
268 <xsl:call-template name="documentPre"/>
269 <xsl:call-template name="documentContentMirador3"/>
270 <xsl:call-template name="documentPost"/>
271 <xsl:call-template name="documentPostMirador3"/>
272 </xsl:when>
273
274 <xsl:otherwise>
275 <xsl:call-template name="documentPre"/>
276 <xsl:call-template name="wrappedSectionImage"/>
277 <div id="gs-document-text">
278 <xsl:call-template name="documentNodeTextIntermuse"/>
279 </div>
280 <xsl:call-template name="documentPost"/>
281 </xsl:otherwise>
282
283 </xsl:choose>
284 </div>
285
286 </xsl:template>
287
288
289 <xsl:template name="documentPost">
290
291 <xsl:if test="@docType='simple'">
292 <xsl:call-template name="opt-googlevision-ocr-json">
293 <xsl:with-param name="assocfilepath"><gsf:metadata name="assocfilepath" pos="first"/></xsl:with-param>
294 </xsl:call-template>
295 </xsl:if>
296 </xsl:template>
297
298 <xsl:template name="documentPostMirador3">
299
300 <!-- Container element of Mirador whose id should be passed to the instantiating call as "id" -->
301 <div style="position: relative; width: 100%; height: 800px;">
302 <div id="mirador3-viewer"><xsl:comment>filler</xsl:comment></div>
303 </div>
304
305 <!--
306 <gsf:variable name="endpointURL">
307 <xsl:choose>
308 <xsl:when test="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@value='true'">
309 <xsl:choose>
310 <xsl:when test="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@endpointURL">
311 <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@endpointURL"/>
312 </xsl:when>
313 <xsl:otherwise>
314 <xsl:text>localStorage</xsl:text> < ! - - default - - >
315 </xsl:otherwise>
316 </xsl:choose>
317 </xsl:when>
318 <xsl:otherwise></xsl:otherwise>
319 </xsl:choose>
320 </gsf:variable>
321 -->
322
323 <gsf:script>
324 var iiifpres_root_id = gs.variables.iiifPresentationRootIdentifier;
325 console.log(gs);
326 var iiifpres_label = (gs.variables.toplevelTitle) ? gs.variables.toplevelTitle : gs.variables.chosenTitle;
327
328 var iiif_manifest = initIIIFManifest(iiifpres_root_id,iiifpres_label, IIIF_Doc_Images);
329
330 var mirador3 = createMirador3Viewer();
331 </gsf:script>
332
333 </xsl:template>
334
335 <xsl:template name="wrappedDocumentTopLevel">
336 <gsf:variable name="toplevelTitle"><xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/document/documentNode/metadataList/metadata[@name='Title']" /></gsf:variable>
337 <xsl:choose>
338 <xsl:when test="$bookswitch = 'mirador'">
339 <!-- <xsl:call-template name="documentPre"/> -->
340 <div style="display:none;">
341 <xsl:call-template name="wrappedDocument"/> <!-- without ed=1, this template misses the binds in of documentPre and documentPost -->
342 </div>
343 <!-- <xsl:call-template name="documentPost"/> -->
344 <xsl:call-template name="documentPostMirador3"/>
345 </xsl:when>
346 <xsl:otherwise>
347 <xsl:call-template name="wrappedDocument"/> <!-- without ed=1, this template misses the binds in of documentPre and documentPost -->
348 </xsl:otherwise>
349 </xsl:choose>
350 </xsl:template>
351
352
353 <!-- content of a simple document. Will not be used for editing mode -->
354 <xsl:template name="documentPostInProgress">
355
356
357 <!--
358 canDoEditing = <xsl:value-of select="$canDoEditing"/> <br />
359 editingTurnedOn = <xsl:value-of select="$editingTurnedOn"/>
360 -->
361
362 <!--
363
364 <xsl:choose>
365 <xsl:when test="$canDoEditing = 'true' and $editingTurnedOn = 'true'">
366
367 <xsl:when test="$canDoEditing = 'true'">
368-->
369 <gsf:script src="https://unpkg.com/mirador@latest/dist/mirador.min.js"/>
370
371
372 <!-- By default uses Roboto font. Be sure to load this or change the font -->
373 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" />
374 <!-- Container element of Mirador whose id should be passed to the instantiating call as "id" -->
375
376 <div style="position: relative; width: 100%; height: 800px;">
377 <div id="my-mirador"> <xsl:comment>filler</xsl:comment></div>
378 </div>
379
380 <gsf:script>
381
382var mirador = Mirador.viewer({
383 "id": "my-mirador",
384 "manifests": {
385 "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json": {
386 "provider": "IntermusE"
387 }
388 },
389 "window" : { "panels" : { "annotations": true, "attribution": false } },
390 "annotations": {
391 "htmlSanitizationRuleSet": 'iiif', // See src/lib/htmlRules.js for acceptable values
392 "filteredMotivations": ['oa:commenting', 'oa:tagging', 'sc:painting', 'commenting', 'tagging'],
393 },
394 "windows": [
395 {
396 "loadedManifest": "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json",
397 "canvasIndex": 1,
398 "thumbnailNavigationPosition": 'far-bottom'
399 }
400 ]
401});
402 </gsf:script>
403
404 <!--
405 </xsl:when>
406 </xsl:choose>
407-->
408
409 </xsl:template>
410
411
412</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.