source: main/trunk/greenstone3/web/interfaces/default/transform/pages/document-iiif-manifest.xsl@ 37170

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

Changes to support IIIF Manifest searching

File size: 13.6 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 Key goal: generate a IIIF v2 compliant manifest file in JSON format based on the document
13 -->
14
15 <!-- Similar in spirit to document.xsl (catering for 'simple' and complex document structures such as 'pages'),
16 but considerably tailored down to produce the raw IIIF-manifest JSON format:
17 (i) focus on just the (potientailly hierachically nested) pages
18 (ii) so a bit like ed=1, but implied rather than needing to be set
19 -->
20
21 <xsl:include href="layouts/header-vars.xsl"/>
22
23 <!--
24 <xsl:include href="pages/document-shared.xsl" />
25 -->
26
27 <xsl:include href="pages/document-vars.xsl" />
28
29 <!-- Additional changes needed to GS3 Java runtine for the following output tag to operate correctly -->
30 <!-- Testing with o=xsl and the debug XML+XSL pair of files generated (when an error was encountred)
31 showed that the Greenstone3 runtime does not currently honour the output tag, in fact gslib.xsl
32 entries seem to turn up later on, and as this includes html-output.xsl, then a later xsl:output
33 tag is generated. The problems runner deeper than this however, with the XSLT output generated
34 having a DTD. Looks like gsdl3/TransformingReceptionist.java is geared to always generating
35 XML output of some form of other (e.g. RSS XML output). Generating raw text just doesn't
36 seem to get through. So to make progress have introduced CGI argument 'excerptid-text'
37 as a way of getting to the text that is generated within, say, a <pre> elemlent with an id attribute -->
38 <!--
39 <xsl:output method="text" version="1.0" encoding="utf-8" omit-xml-declaration="yes"/>
40 <xsl:strip-space elements="*"/>
41 -->
42
43 <!-- page/pageRequest[@baseURL]="//intermuse.sowemustthink.space/greenstone3/ -->
44 <!-- page/pageRequest[@fullURL]="//intermuse.sowemustthink.space/greenstone3/library?a=d.... -->
45 <!-- ***** need to work out domain name to use from raw XML message, say processing something from the above -->
46 <xsl:variable name="window-location-origin">https://intermuse.sowemustthink.space</xsl:variable>
47
48 <!-- optional cgi-params for links to document pages -->
49 <xsl:variable name="opt-doc-link-args"></xsl:variable>
50 <xsl:variable name="bookswitch"></xsl:variable>
51
52 <xsl:variable name="iiifPresentationRootIdentifier">http://ld.greenstone.org/<xsl:value-of select="$site_name"/>/<xsl:value-of select="$collNameChecked"/>/<xsl:value-of select="$docID"/></xsl:variable>
53
54 <xsl:template match="/">
55 <html>
56 <body>
57 <pre id="iiif-manifest">
58 <xsl:apply-templates select="/page/pageResponse/document" />
59 </pre>
60 </body>
61 </html>
62 </xsl:template>
63
64 <xsl:template match="/page/pageResponse/document">
65 <!-- display the document -->
66 <xsl:choose>
67 <xsl:when test="@docType='simple'">
68 <xsl:call-template name="documentContent"/>
69 </xsl:when>
70 <xsl:otherwise> <!-- kick off the recursive call for a more complex structured document-->
71 <xsl:call-template name="wrappedDocumentTopLevel"/>
72 </xsl:otherwise>
73 </xsl:choose>
74 </xsl:template>
75
76
77 <xsl:template name="wrappedDocumentTopLevel">
78 <!-- <xsl:call-template name="documentPre"/> -->
79 <xsl:call-template name="wrappedDocument"/> <!-- without ed=1, this template misses the binds in of documentPre and documentPost -->
80 <!-- <xsl:call-template name="documentPost"/> -->
81 </xsl:template>
82
83 <xsl:template name="wrappedDocument">
84 <xsl:call-template name="documentPre"/>
85 <xsl:for-each select="documentNode">
86 <xsl:call-template name="wrapDocumentNodes"/>
87 </xsl:for-each>
88 <xsl:call-template name="documentPost"/>
89 </xsl:template>
90
91
92 <xsl:template name="iiif-other-content">
93 <xsl:param name="optSection"/>
94 <xsl:variable name="baseURL">https:<xsl:value-of select="/page/pageRequest/@baseURL"/></xsl:variable> <!-- **** had to hardwire https: -->
95 <xsl:variable name="gsfOptionIncludeFileAssocOpenAnnotations"><xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeFileAssocOpenAnnotations']/@value"></xsl:value-of></xsl:variable>
96 <xsl:variable name="cgiParamIncludeFileAssocOpenAnnotations"><xsl:value-of select="/page/pageRequest/paramList/param[@name='includeFileAssocOpenAnnotations']/@value"></xsl:value-of></xsl:variable>
97 <xsl:if test="$gsfOptionIncludeFileAssocOpenAnnotations='true' or $cgiParamIncludeFileAssocOpenAnnotations='true'">
98 "otherContent": [{
99 "@id": "<xsl:value-of select="$baseURL"/><xsl:value-of select="$library_name"/>/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="$collNameChecked"/>/index/assoc/<gsf:metadata name="assocfilepath" select="root"/>/openannotation-list<xsl:value-of select="$optSection"/>.json",
100 "@type": "sc:AnnotationList"
101 }],
102 </xsl:if>
103 </xsl:template>
104
105
106 <xsl:template name="iiif-canvas-image">
107 <xsl:param name="identifier"/>
108 <xsl:param name="docType"/>
109 <!-- -->
110 <xsl:variable name="iiifImageRootIdentifier">
111 <xsl:text>/gs-cantaloupe/iiif/2/</xsl:text><xsl:value-of select="$site_name"/>:<xsl:value-of select="$collNameChecked"/>:<xsl:value-of select="$identifier"/>
112 </xsl:variable>
113
114 <xsl:variable name="section"><xsl:value-of select="position()" /></xsl:variable>
115 <xsl:variable name="optSection">
116 <xsl:choose>
117 <xsl:when test="$docType = 'simple'"></xsl:when><!-- i.e. empty -->
118 <xsl:otherwise><xsl:value-of select="position()" /></xsl:otherwise>
119 </xsl:choose>
120 </xsl:variable>
121 <xsl:variable name="chosenTitle">
122 <xsl:choose>
123 <xsl:when test="$docType = 'simple'">
124 <xsl:call-template name="choose-title"/>
125 </xsl:when>
126 <xsl:otherwise>page <xsl:value-of select="$section"/></xsl:otherwise>
127 </xsl:choose>
128 </xsl:variable>
129 <!-- The following is useful for debugging, nested in 'pre' tags -->
130 <!--
131 docType = <xsl:value-of select="$docType"/>
132 docID = <xsl:value-of select="$docID"/>
133 position = <xsl:value-of select="position()" />
134
135 identifer = <xsl:value-of select="$identifier"/>
136 section = <xsl:value-of select="$section"/>
137 optSection = <xsl:value-of select="$optSection"/>
138
139 iiifPresRootIdentifier = <xsl:value-of select="$iiifPresentationRootIdentifier" />
140 iiifImageRootIdentifier = <xsl:value-of select="$iiifImageRootIdentifier" />
141 -->
142 <!-- an array entry in 'canvases': { @content, @id, @type, label, width, height, images[{}], thumbnail {@id,@type} } -->
143 <!-- add a comma first, if it is not the first canvas element in the array -->
144 <xsl:if test="$section &gt; 1">
145 ,
146 </xsl:if>
147 {
148 "@context": "http://iiif.io/api/presentation/2/context.json",
149 "@id" : "<xsl:value-of select="$iiifPresentationRootIdentifier" />/canvas/<xsl:value-of select="$section"/>",
150 "@type" : "sc:Canvas",
151 "label" : "<xsl:value-of select="$chosenTitle"/>",
152 <xsl:call-template name="iiif-other-content">
153 <xsl:with-param name="optSection"><xsl:value-of select="$optSection"/></xsl:with-param>
154 </xsl:call-template>
155 "width" : <gsf:metadata name="ImageWidth"/>,
156 "height" : <gsf:metadata name="ImageHeight"/>,
157 "images": [{
158 "@context": "http://iiif.io/api/image/2/context.json",
159 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier" />/annotation/<xsl:value-of select="$section"/>",
160 "@type": "oa:Annotation",
161 "motivation": "sc:painting",
162 "on": "<xsl:value-of select="$iiifPresentationRootIdentifier" />/canvas",
163 "resource": {
164 "@id": "<xsl:value-of select="$window-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />/full/full/0/default.jpg",
165 "@type": "dctypes:Image",
166 "format": "image/jpeg",
167 "width": <gsf:metadata name="ImageWidth"/>,
168 "hieght": <gsf:metadata name="ImageHeight"/>,
169 "service": {
170 "@context": "http://iiif.io/api/image/2/context.json",
171 "@id": "<xsl:value-of select="$window-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />",
172 "profile": "https://iiif.io/api/image/2/profiles/level2.json"
173 }
174 }
175 }],
176 "thumbnail": {
177 "@id": "<xsl:value-of select="$window-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />/full/,150/0/default.jpg",
178 "@type": "dctypes:Image"
179 }
180 }
181 <!-- Another field to consider in the above JSON is: -->
182 <!-- "format": mime_type, // ???? or is it OK to always have this as image/jpeg and rely on IIIF Image Server coverting as/when needed??? -->
183 </xsl:template>
184
185
186 <xsl:template name="wrappedSectionPost">
187
188 <!-- add in IIIF Server link for section image -->
189 <xsl:variable name="nodeID" select="@nodeID"/>
190 <xsl:call-template name="iiif-canvas-image">
191 <xsl:with-param name="identifier" select="$nodeID" />
192 <xsl:with-param name="docType" select="@docType" />
193 </xsl:call-template>
194 </xsl:template>
195
196 <xsl:template name="sectionImage">
197 <!-- don't need this template to generate anything in the IIIF-Manifest JSON case -->
198 </xsl:template>
199
200 <xsl:template name="sectionContent">
201 <xsl:call-template name="wrappedSectionPost"/>
202 </xsl:template>
203
204
205 <xsl:template name="documentPre">
206 <xsl:variable name="httpCollection">library/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="/page/pageResponse/collection/@name"/></xsl:variable>
207
208 <xsl:variable name="toplevelChosenTitle">
209 <xsl:choose>
210 <xsl:when test="@docType='simple'">
211 <xsl:call-template name="choose-title"/>
212 </xsl:when>
213 <xsl:otherwise>
214 <xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/document/documentNode/metadataList/metadata[@name='Title']" />
215 </xsl:otherwise>
216 </xsl:choose>
217 </xsl:variable>
218
219 <xsl:variable name="toplevelSASShortID">
220 <xsl:choose>
221 <xsl:when test="@docType='simple'">
222 <gsf:metadata name="SASShortID" />
223 </xsl:when>
224 <xsl:otherwise>
225 <xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/document/documentNode/metadataList/metadata[@name='SASShortID']" />
226 </xsl:otherwise>
227 </xsl:choose>
228 </xsl:variable>
229
230
231 <!-- start of iiif_manifest: -->
232 {
233 "@context": "http://iiif.io/api/presentation/2/context.json",
234 "@type": "sc:Manifest",
235 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier"/>/manifest",
236 "label": "<xsl:value-of select="$toplevelChosenTitle"/>",
237 "attribution": "The Internet of Musical Events (InterMusE): Digital Scholarship, Community, and the Archiving of Performance",
238 "license": "https://**** To Be Determined ****",
239 "logo": "https://intermuse.datatodata.org/wp-content/uploads/sites/4/2021/03/cropped-cropped-cropped-1.png",
240 "metadata": [
241 { "label": "creator", "value": ["aaa1","aaa2"] },
242 { "label": "title", "value": ["chosen-title"] }
243 ],
244
245 "service": {
246 "profile": "http://iiif.io/api/search/0/search",
247 "@id": "https://intermuse.sowemustthink.space/simpleAnnotationStore/search-api/<xsl:value-of select="$toplevelSASShortID"/>/search",
248 "@context": "http://iiif.io/api/search/0/context.json"
249 },
250
251 <!-- trival IIIF sequences => has one IIIF canvas in it -->
252 "sequences": [{
253 "@context": "http://iiif.io/api/image/2/context.json",
254 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier"/>/sequence/normal",
255 "@type": "sc:Sequence",
256 "canvases": [
257 </xsl:template>
258
259
260 <xsl:template name="documentContentSimpleIIIFImage">
261 <xsl:call-template name="iiif-canvas-image">
262 <xsl:with-param name="identifier" select="$docID" />
263 <xsl:with-param name="docType" select="@docType" />
264 </xsl:call-template>
265 </xsl:template>
266
267 <xsl:template name="documentContent">
268 <!-- The way document.xsl templates are structured, only get to here is if @docType = 'simple' -->
269 <!-- A 'paged' (or 'hierarical') document goes throgh 'wrappedContent' -->
270 <xsl:call-template name="documentPre"/>
271 <xsl:call-template name="documentContentSimpleIIIFImage"/>
272 <xsl:call-template name="documentPost"/>
273 </xsl:template>
274
275
276 <xsl:template name="wrapDocumentNodes">
277
278 <xsl:if test="@nodeType = 'leaf'">
279 <!-- for iiif-manifest JSON, put out a flat-list of images => only interested in leaf nodes -->
280 <xsl:call-template name="sectionContent"/>
281 </xsl:if>
282
283 <xsl:if test="documentNode">
284 <xsl:for-each select="documentNode">
285 <xsl:call-template name="wrapDocumentNodes"/>
286 </xsl:for-each>
287 </xsl:if>
288 </xsl:template>
289
290 <xsl:template name="wrappedSectionImage">
291 <!-- don't need this template to generate anything in the IIIF-Manifest JSON case -->
292 </xsl:template>
293
294
295
296 <xsl:template name="documentPost">
297 <!-- end of iiif_manifest: -->
298 <!-- close of canvases, then close higher level blocks to complete the JSON file -->
299 ]
300 }]
301 }
302 </xsl:template>
303
304
305</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.