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

Last change on this file since 37099 was 37099, checked in by davidb, 16 months ago

Changes made after introduction of CGI arg 'excerptid-text' and testing to ensure the generated IIIF Manifest was valid syntax

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