Debian Codegraph @

xslt/docbook/html/db2html-media.xsl

raw
1 <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
2 <!--
3 This program is free software; you can redistribute it and/or modify it under
4 the terms of the GNU Lesser General Public License as published by the Free
5 Software Foundation; either version 2 of the License, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 details.
12
13 You should have received a copy of the GNU Lesser General Public License
14 along with this program; see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/>.
15 -->
16
17 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
18 xmlns:db="http://docbook.org/ns/docbook"
19 xmlns:mml="http://www.w3.org/1998/Math/MathML"
20 xmlns:str="http://exslt.org/strings"
21 xmlns="http://www.w3.org/1999/xhtml"
22 exclude-result-prefixes="db mml str"
23 version="1.0">
24
25 <!--!!==========================================================================
26 DocBook to HTML - Images and Media
27 Handle DocBook media elements.
28 @revision[version=3.8 date=2012-11-13 status=final]
29
30 This stylesheet contains templates for handling DocBook `mediaobject` and
31 `inlinemediaobject` elements, as well as the various `object` and `data`
32 elements found in these elements. This stylesheet also handles the deprecated
33 DocBook 4 `graphic` and `inlinegraphic` elements.
34 -->
35
36
37 <!--**==========================================================================
38 db2html.audiodata
39 Output an HTML `audio` element for a `audiodata` element.
40 @revision[version=3.8 date=2012-11-12 status=final]
41
42 [xsl:params]
43 $node: The `audiodata` element.
44
45 This template creates an `audio` element in the HTML output. This template
46 calls {db2html.mediaobject.fallback} for the contents of the `audio` element.
47 -->
48 <xsl:template name="db2html.audiodata">
49 <xsl:param name="node" select="."/>
50 <xsl:variable name="media" select="($node/ancestor::mediaobject[1] |
51 $node/ancestor::inlinemediaobject[1] |
52 $node/ancestor::db:mediaobject[1] |
53 $node/ancestor::db:inlinemediaobject[1]
54 )[last()]"/>
55 <audio preload="auto">
56 <xsl:attribute name="src">
57 <xsl:choose>
58 <xsl:when test="$node/@fileref">
59 <xsl:value-of select="$node/@fileref"/>
60 </xsl:when>
61 <xsl:when test="$node/@entityref">
62 <xsl:value-of select="unparsed-entity-uri($node/@entityref)"/>
63 </xsl:when>
64 </xsl:choose>
65 </xsl:attribute>
66 <xsl:call-template name="db2html.mediaobject.fallback">
67 <xsl:with-param name="node" select="$media"/>
68 </xsl:call-template>
69 </audio>
70 <xsl:call-template name="html.media.controls">
71 <xsl:with-param name="type" select="'audio'"/>
72 </xsl:call-template>
73 </xsl:template>
74
75
76 <!--**==========================================================================
77 db2html.imagedata
78 Output an HTML `img` element for a `imagedata` element.
79 @revision[version=3.10 date=2013-08-11 status=final]
80
81 [xsl:params]
82 $node: The `imagedata` or other graphic element.
83
84 This template creates an `img` element in the HTML output. This template
85 is called not only for `imagedata` elements, but also for `graphic` and
86 `inlinegraphic` elements. Note that `graphic` and `inlinegraphic` are
87 deprecated and should not be used in any newly-written DocBook files. Use
88 `mediaobject` instead.
89
90 This template looks for a `textobject` with a `phrase` child in an ancestor
91 `mediaobject` or `inlinemediaobject` element. It uses the first available,
92 taking conditional processing into consideration.
93 -->
94 <xsl:template name="db2html.imagedata">
95 <xsl:param name="node" select="."/>
96 <img>
97 <xsl:attribute name="src">
98 <xsl:choose>
99 <xsl:when test="$node/@fileref">
100 <xsl:value-of select="$node/@fileref"/>
101 </xsl:when>
102 <xsl:when test="$node/@entityref">
103 <xsl:value-of select="unparsed-entity-uri($node/@entityref)"/>
104 </xsl:when>
105 </xsl:choose>
106 </xsl:attribute>
107 <xsl:if test="$node/@contentwidth">
108 <xsl:attribute name="width">
109 <xsl:value-of select="$node/@contentwidth"/>
110 </xsl:attribute>
111 </xsl:if>
112 <xsl:if test="$node/@contentdepth">
113 <xsl:attribute name="height">
114 <xsl:value-of select="$node/@contentdepth"/>
115 </xsl:attribute>
116 </xsl:if>
117 <xsl:variable name="media" select="(self::imagedata/ancestor::mediaobject[1] |
118 self::imagedata/ancestor::inlinemediaobject[1] |
119 self::db:imagedata/ancestor::db:mediaobject[1] |
120 self::db:imagedata/ancestor::db:inlinemediaobject[1]
121 )[last()]"/>
122 <xsl:variable name="alt" select="$media/textobject[phrase] | $media/db:textobject[db:phrase]"/>
123 <xsl:variable name="altpos">
124 <xsl:for-each select="$alt">
125 <xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
126 <xsl:if test="$if != ''">
127 <xsl:value-of select="concat(',', position())"/>
128 </xsl:if>
129 </xsl:for-each>
130 </xsl:variable>
131 <xsl:if test="$altpos != ''">
132 <xsl:attribute name="alt">
133 <xsl:variable name="obj" select="$alt[position() = number(str:split($altpos, ',')[1])]"/>
134 <xsl:value-of select="$obj/phrase | $obj/db:phrase"/>
135 </xsl:attribute>
136 </xsl:if>
137 </img>
138 </xsl:template>
139
140
141 <!--**==========================================================================
142 db2html.videodata
143 Output an HTML `video` element for a `videodata` element.
144 @revision[version=3.8 date=2012-11-12 status=final]
145
146 [xsl:params]
147 $node: The `videodata` element.
148
149 This template creates a `video` element in the HTML output. If the containing
150 `mediaobject` or `inlinemediaobject` element has an `imageobject` with the
151 `role` attribute set to `"poster"`, that image will be used for the `poster`
152 attribute on the HTML `video` element. This template calls
153 {db2html.mediaobject.fallback} for the contents of the `video` element.
154 -->
155 <xsl:template name="db2html.videodata">
156 <xsl:param name="node" select="."/>
157 <xsl:variable name="media" select="($node/ancestor::mediaobject[1] |
158 $node/ancestor::inlinemediaobject[1] |
159 $node/ancestor::db:mediaobject[1] |
160 $node/ancestor::db:inlinemediaobject[1]
161 )[last()]"/>
162 <video preload="auto">
163 <xsl:attribute name="src">
164 <xsl:choose>
165 <xsl:when test="$node/@fileref">
166 <xsl:value-of select="$node/@fileref"/>
167 </xsl:when>
168 <xsl:when test="$node/@entityref">
169 <xsl:value-of select="unparsed-entity-uri($node/@entityref)"/>
170 </xsl:when>
171 </xsl:choose>
172 </xsl:attribute>
173 <xsl:if test="$node/@contentwidth">
174 <xsl:attribute name="width">
175 <xsl:value-of select="$node/@contentwidth"/>
176 </xsl:attribute>
177 </xsl:if>
178 <xsl:if test="$node/@contentdepth">
179 <xsl:attribute name="height">
180 <xsl:value-of select="$node/@contentdepth"/>
181 </xsl:attribute>
182 </xsl:if>
183 <xsl:variable name="poster"
184 select="$media/imageobject[@role = 'poster']/imagedata |
185 $media/db:imageobject[@role = 'poster']/db:imagedata"/>
186 <xsl:if test="$poster">
187 <xsl:attribute name="poster">
188 <xsl:choose>
189 <xsl:when test="$poster/@fileref">
190 <xsl:value-of select="$poster/@fileref"/>
191 </xsl:when>
192 <xsl:when test="$poster/@entityref">
193 <xsl:value-of select="unparsed-entity-uri($poster/@entityref)"/>
194 </xsl:when>
195 </xsl:choose>
196 </xsl:attribute>
197 </xsl:if>
198 <xsl:call-template name="db2html.mediaobject.fallback">
199 <xsl:with-param name="node" select="$media"/>
200 </xsl:call-template>
201 </video>
202 <xsl:call-template name="html.media.controls">
203 <xsl:with-param name="type" select="'video'"/>
204 </xsl:call-template>
205 </xsl:template>
206
207
208 <!--**==========================================================================
209 db2html.mediaobject
210 Outputs HTML for a `mediaobject` element.
211 @revision[version=3.10 date=2013-08-11 status=final]
212
213 [xsl:params]
214 $node: The `mediaobject` element.
215
216 This template processes a `mediaobject` element and outputs the appropriate
217 HTML. DocBook allows multiple objects to be listed in a `mediaobject` element.
218 Processing tools are expected to choose the earliest suitable object. This
219 template will select the first audio, image, or video object it can handle,
220 filtering out images in non-web formats, and taking conditional processing
221 into consideration. If no suitable non-text objects are found, this template
222 calls {db2html.mediaobject.fallback}.
223
224 This template also detects MathML embedded in a DocBook 5 `imagedata` element
225 with the `format` attribute `"mathml"`, and passes it to the templates in
226 {db2html-math}.
227 -->
228 <xsl:template name="db2html.mediaobject">
229 <xsl:param name="node" select="."/>
230 <xsl:variable name="objs" select="
231 $node/audioobject | $node/db:audioobject |
232 $node/videoobject | $node/db:videoobject |
233 $node/imageobject[imagedata[
234 @format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or
235 @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or
236 not(@format)]] |
237 $node/imageobjectco[imageobject/imagedata[
238 @format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or
239 @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or
240 not(@format)]] |
241 $node/db:imageobject[db:imagedata[
242 @format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or
243 @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or
244 not(@format)]] |
245 $node/db:imageobject[db:imagedata[@format = 'mathml'][mml:math]] |
246 $node/db:imageobjectco[db:imageobject/db:imagedata[
247 @format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or
248 @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or
249 not(@format)]] "/>
250 <xsl:variable name="objspos">
251 <xsl:for-each select="$objs">
252 <xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
253 <xsl:if test="$if != ''">
254 <xsl:value-of select="concat(',', position())"/>
255 </xsl:if>
256 </xsl:for-each>
257 </xsl:variable>
258 <xsl:choose>
259 <xsl:when test="$objspos != ''">
260 <xsl:apply-templates select="$objs[position() = number(str:split($objspos, ',')[1])]"/>
261 </xsl:when>
262 <xsl:otherwise>
263 <xsl:call-template name="db2html.mediaobject.fallback">
264 <xsl:with-param name="node" select="$node"/>
265 </xsl:call-template>
266 </xsl:otherwise>
267 </xsl:choose>
268 </xsl:template>
269
270
271 <!--**==========================================================================
272 db2html.mediaobject.fallback
273 Outputs fallback HTML for a `mediaobject` element.
274 @revision[version=3.10 date=2013-08-11 status=final]
275
276 [xsl:params]
277 $node: The `mediaobject` element.
278
279 This template outputs HTML for the first suitable `textobject` child element
280 of $node. If $node is an `inlinemediaobject`, it looks for a `textobject`
281 that contains a `phrase` element. Otherwise, it looks for a `textobject` with
282 normal block content. It also handles conditional processing on the `textobject`
283 elements.
284 -->
285 <xsl:template name="db2html.mediaobject.fallback">
286 <xsl:param name="node" select="."/>
287 <xsl:choose>
288 <xsl:when test="local-name($node) = 'inlinemediaobject'">
289 <xsl:variable name="alt" select="$node/textobject[phrase] | $node/db:textobject[db:phrase]"/>
290 <xsl:variable name="altpos">
291 <xsl:for-each select="$alt">
292 <xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
293 <xsl:if test="$if != ''">
294 <xsl:value-of select="concat(',', position())"/>
295 </xsl:if>
296 </xsl:for-each>
297 </xsl:variable>
298 <xsl:if test="$altpos != ''">
299 <xsl:variable name="obj" select="$alt[position() = number(str:split($altpos, ',')[1])]"/>
300 <xsl:apply-templates select="$obj/phrase | $obj/db:phrase"/>
301 </xsl:if>
302 </xsl:when>
303 <xsl:otherwise>
304 <xsl:variable name="alt" select="$node/textobject[not(phrase or textdata)] |
305 $node/db:textobject[not(db:phrase or db:textdata)]"/>
306 <xsl:variable name="altpos">
307 <xsl:for-each select="$alt">
308 <xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
309 <xsl:if test="$if != ''">
310 <xsl:value-of select="concat(',', position())"/>
311 </xsl:if>
312 </xsl:for-each>
313 </xsl:variable>
314 <xsl:if test="$altpos != ''">
315 <xsl:apply-templates select="$alt[position() = number(str:split($altpos, ',')[1])]/*"/>
316 </xsl:if>
317 </xsl:otherwise>
318 </xsl:choose>
319 </xsl:template>
320
321
322 <!-- == Matched Templates == -->
323
324 <!-- = audiodata = -->
325 <xsl:template match="mediaobject/audioobject/audiodata |
326 db:mediaobject/db:audioobject/db:audiodata">
327 <div>
328 <xsl:call-template name="html.class.attr">
329 <xsl:with-param name="class" select="'media media-audio'"/>
330 </xsl:call-template>
331 <div class="inner">
332 <xsl:call-template name="db2html.audiodata">
333 <xsl:with-param name="inline" select="false()"/>
334 </xsl:call-template>
335 </div>
336 </div>
337 </xsl:template>
338 <xsl:template match="inlinemediaobject/audioobject/audiodata |
339 db:inlinemediaobject/db:audioobject/db:audiodata">
340 <span>
341 <xsl:call-template name="html.class.attr">
342 <xsl:with-param name="class" select="'media media-audio'"/>
343 </xsl:call-template>
344 <xsl:call-template name="db2html.audiodata"/>
345 </span>
346 </xsl:template>
347
348 <!-- = audioobject = -->
349 <xsl:template match="audioobject | db:audioobject">
350 <xsl:apply-templates select="audiodata | db:audiodata"/>
351 </xsl:template>
352
353 <!-- = graphic = -->
354 <xsl:template match="graphic">
355 <div>
356 <xsl:call-template name="html.class.attr">
357 <xsl:with-param name="class" select="'graphic'"/>
358 </xsl:call-template>
359 <xsl:call-template name="db2html.anchor"/>
360 <xsl:call-template name="db2html.imagedata"/>
361 </div>
362 </xsl:template>
363
364 <!-- = imagedata = -->
365 <xsl:template match="imagedata | db:imagedata">
366 <xsl:choose>
367 <xsl:when test="@format = 'mathml' and mml:math">
368 <xsl:apply-templates select="mml:math"/>
369 </xsl:when>
370 <xsl:otherwise>
371 <div>
372 <xsl:call-template name="html.class.attr">
373 <xsl:with-param name="class" select="'media media-image'"/>
374 </xsl:call-template>
375 <div class="inner">
376 <xsl:call-template name="db2html.imagedata"/>
377 </div>
378 </div>
379 </xsl:otherwise>
380 </xsl:choose>
381 </xsl:template>
382
383 <!-- = imageobject = -->
384 <xsl:template match="imageobject | db:imageobject">
385 <xsl:apply-templates select="imagedata | db:imagedata"/>
386 </xsl:template>
387
388 <!-- = inlinegraphic = -->
389 <xsl:template match="inlinegraphic">
390 <span>
391 <xsl:call-template name="html.class.attr">
392 <xsl:with-param name="class" select="'inlinegraphic'"/>
393 </xsl:call-template>
394 <xsl:call-template name="db2html.anchor"/>
395 <xsl:call-template name="db2html.imagedata"/>
396 </span>
397 </xsl:template>
398
399 <!-- = inlinemediaobject = -->
400 <xsl:template match="inlinemediaobject | db:inlinemediaobject">
401 <xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
402 <xsl:if test="$if != ''">
403 <span>
404 <xsl:call-template name="html.class.attr">
405 <xsl:with-param name="class" select="'inlinemediaobject'"/>
406 </xsl:call-template>
407 <xsl:call-template name="db2html.anchor"/>
408 <xsl:call-template name="db2html.mediaobject"/>
409 </span>
410 </xsl:if>
411 </xsl:template>
412
413 <!-- = mediaojbect = -->
414 <xsl:template match="mediaobject | db:mediaobject">
415 <xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
416 <xsl:if test="$if != ''">
417 <div>
418 <xsl:call-template name="html.class.attr">
419 <xsl:with-param name="class" select="'mediaobject'"/>
420 </xsl:call-template>
421 <xsl:call-template name="db2html.anchor"/>
422 <xsl:call-template name="db2html.mediaobject"/>
423 <!-- When a figure contains only a single mediaobject, it eats the caption -->
424 <xsl:if test="not(../self::figure or ../self::informalfigure or
425 ../self::db:figure or ../self::db:informalfigure) or
426 ../*[not(self::blockinfo) and not(self::title) and
427 not(self::db:info) and not(self::db:title) and
428 not(self::titleabbrev) and not(self::db:titleabbrev) and
429 not(. = current()) ]">
430 <xsl:apply-templates select="caption | db:caption"/>
431 </xsl:if>
432 </div>
433 </xsl:if>
434 </xsl:template>
435
436 <!-- = videodata = -->
437 <xsl:template match="mediaobject/videoobject/videodata |
438 db:mediaobject/db:videoobject/db:videodata">
439 <div>
440 <xsl:call-template name="html.class.attr">
441 <xsl:with-param name="class" select="'media media-video'"/>
442 </xsl:call-template>
443 <div class="inner">
444 <xsl:call-template name="db2html.videodata">
445 <xsl:with-param name="inline" select="false()"/>
446 </xsl:call-template>
447 </div>
448 </div>
449 </xsl:template>
450 <xsl:template match="inlinemediaobject/videoobject/videodata |
451 db:inlinemediaobject/db:videoobject/db:videodata">
452 <span>
453 <xsl:call-template name="html.class.attr">
454 <xsl:with-param name="class" select="'media media-video'"/>
455 </xsl:call-template>
456 <xsl:call-template name="db2html.videodata"/>
457 </span>
458 </xsl:template>
459
460 <!-- = videoobject = -->
461 <xsl:template match="videoobject | db:videoobject">
462 <xsl:apply-templates select="videodata | db:videodata"/>
463 </xsl:template>
464
465 </xsl:stylesheet>