19
19
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
20
20
xmlns:db="http://docbook.org/ns/docbook"
21
21
xmlns:mml="http://www.w3.org/1998/Math/MathML"
22
xmlns:str="http://exslt.org/strings"
22
23
xmlns="http://www.w3.org/1999/xhtml"
23
exclude-result-prefixes="db mml"
24
exclude-result-prefixes="db mml str"
26
27
<!--!!==========================================================================
82
83
<!--**==========================================================================
84
85
Output an HTML #{img} element for a #{imagedata} element.
85
:Revision:version="3.8" date="2012-11-12" status="final"
86
:Revision:version="3.10" date="2013-08-11" status="final"
86
87
$node: The #{imagedata} or other graphic element.
88
89
This template creates an #{img} element in the HTML output. This template
90
91
#{inlinegraphic} elements. Note that #{graphic} and #{inlinegraphic} are
91
92
deprecated and should not be used in any newly-written DocBook files. Use
92
93
#{mediaobject} instead.
95
This template looks for a #{textobject} with a #{phrase} child in an ancestor
96
#{mediaobject} or #{inlinemediaobject} element. It uses the first available,
97
taking conditional processing into consideration.
94
99
<xsl:template name="db2html.imagedata">
95
100
<xsl:param name="node" select="."/>
119
124
self::db:imagedata/ancestor::db:mediaobject[1] |
120
125
self::db:imagedata/ancestor::db:inlinemediaobject[1]
122
<xsl:variable name="alt" select="$media/textobject/phrase | $media/db:textobject/db:phrase"/>
127
<xsl:variable name="alt" select="$media/textobject[phrase] | $media/db:textobject[db:phrase]"/>
128
<xsl:variable name="altpos">
129
<xsl:for-each select="$alt">
130
<xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
131
<xsl:if test="$if != ''">
132
<xsl:value-of select="concat(',', position())"/>
136
<xsl:if test="$altpos != ''">
124
137
<xsl:attribute name="alt">
125
<xsl:value-of select="$alt[1]"/>
138
<xsl:variable name="obj" select="$alt[position() = number(str:split($altpos, ',')[1])]"/>
139
<xsl:value-of select="$obj/phrase | $obj/db:phrase"/>
204
218
<!--**==========================================================================
205
219
db2html.mediaobject
206
220
Outputs HTML for a #{mediaobject} element.
207
:Revision:version="3.8" date="2012-11-13" status="final"
221
:Revision:version="3.10" date="2013-08-11" status="final"
208
222
$node: The #{mediaobject} element.
210
224
This template processes a #{mediaobject} element and outputs the appropriate
211
225
HTML. DocBook allows multiple objects to be listed in a #{mediaobject} element.
212
226
Processing tools are expected to choose the earliest suitable object. This
213
227
template will select the first audio, image, or video object it can handle,
214
filtering out images in non-web formats. If no suitable non-text objects are
215
found, this template calls *{db2html.mediaobject.fallback}.
228
filtering out images in non-web formats, and taking conditional processing
229
into consideration. If no suitable non-text objects are found, this template
230
calls *{db2html.mediaobject.fallback}.
217
232
This template also detects MathML embedded in a DocBook 5 #{imagedata} element
218
233
with the #{format} attribute #{"mathml"}, and passes it to the templates in
240
255
@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or
241
256
@format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or
242
257
not(@format)]] "/>
258
<xsl:variable name="objspos">
259
<xsl:for-each select="$objs">
260
<xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
261
<xsl:if test="$if != ''">
262
<xsl:value-of select="concat(',', position())"/>
244
<xsl:when test="$objs">
245
<xsl:apply-templates select="$objs[1]"/>
267
<xsl:when test="$objspos != ''">
268
<xsl:apply-templates select="$objs[position() = number(str:split($objspos, ',')[1])]"/>
248
271
<xsl:call-template name="db2html.mediaobject.fallback">
256
279
<!--**==========================================================================
257
280
db2html.mediaobject.fallback
258
281
Outputs fallback HTML for a #{mediaobject} element.
259
:Revision:version="3.8" date="2012-11-13" status="final"
282
:Revision:version="3.10" date="2013-08-11" status="final"
260
283
$node: The #{mediaobject} element.
262
285
This template outputs HTML for the first suitable #{textobject} child element
263
286
of ${node}. If ${node} is an #{inlinemediaobject}, it looks for a #{textobject}
264
287
that contains a #{phrase} element. Otherwise, it looks for a #{textobject} with
265
normal block content.
288
normal block content. It also handles conditional processing on the #{textobject}
267
291
<xsl:template name="db2html.mediaobject.fallback">
268
292
<xsl:param name="node" select="."/>
270
294
<xsl:when test="local-name($node) = 'inlinemediaobject'">
271
<xsl:apply-templates select="($node/textobject/phrase | $node/db:textobject/db:phrase)[1]"/>
295
<xsl:variable name="alt" select="$node/textobject[phrase] | $node/db:textobject[db:phrase]"/>
296
<xsl:variable name="altpos">
297
<xsl:for-each select="$alt">
298
<xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
299
<xsl:if test="$if != ''">
300
<xsl:value-of select="concat(',', position())"/>
304
<xsl:if test="$altpos != ''">
305
<xsl:variable name="obj" select="$alt[position() = number(str:split($altpos, ',')[1])]"/>
306
<xsl:apply-templates select="$obj/phrase | $obj/db:phrase"/>
274
<xsl:apply-templates select="($node/textobject[not(phrase or textdata)] |
275
$node/db:textobject[not(db:phrase or db:textdata)]
310
<xsl:variable name="alt" select="$node/textobject[not(phrase or textdata)] |
311
$node/db:textobject[not(db:phrase or db:textdata)]"/>
312
<xsl:variable name="altpos">
313
<xsl:for-each select="$alt">
314
<xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
315
<xsl:if test="$if != ''">
316
<xsl:value-of select="concat(',', position())"/>
320
<xsl:if test="$altpos != ''">
321
<xsl:apply-templates select="$alt[position() = number(str:split($altpos, ',')[1])]/*"/>
284
330
<!-- = audiodata = -->
285
331
<xsl:template match="mediaobject/audioobject/audiodata |
286
332
db:mediaobject/db:audioobject/db:audiodata">
287
<div class="media media-audio">
334
<xsl:call-template name="html.class.attr">
335
<xsl:with-param name="class" select="'media media-audio'"/>
288
337
<div class="inner">
289
338
<xsl:call-template name="db2html.audiodata">
290
339
<xsl:with-param name="inline" select="false()"/>
295
344
<xsl:template match="inlinemediaobject/audioobject/audiodata |
296
345
db:inlinemediaobject/db:audioobject/db:audiodata">
297
<span class="media media-audio">
347
<xsl:call-template name="html.class.attr">
348
<xsl:with-param name="class" select="'media media-audio'"/>
298
350
<xsl:call-template name="db2html.audiodata"/>
307
359
<!-- = graphic = -->
308
360
<xsl:template match="graphic">
309
<div class="graphic">
362
<xsl:call-template name="html.class.attr">
363
<xsl:with-param name="class" select="'graphic'"/>
310
365
<xsl:call-template name="db2html.anchor"/>
311
366
<xsl:call-template name="db2html.imagedata"/>
332
387
<!-- = inlinegraphic = -->
333
388
<xsl:template match="inlinegraphic">
334
<span class="inlinegraphic">
390
<xsl:call-template name="html.class.attr">
391
<xsl:with-param name="class" select="'inlinegraphic'"/>
335
393
<xsl:call-template name="db2html.anchor"/>
336
394
<xsl:call-template name="db2html.imagedata"/>
340
398
<!-- = inlinemediaobject = -->
341
399
<xsl:template match="inlinemediaobject | db:inlinemediaobject">
342
<span class="inlinemediaobject">
400
<xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
401
<xsl:if test="$if != ''">
403
<xsl:call-template name="html.class.attr">
404
<xsl:with-param name="class" select="'inlinemediaobject'"/>
343
406
<xsl:call-template name="db2html.anchor"/>
344
407
<xsl:call-template name="db2html.mediaobject"/>
348
412
<!-- = mediaojbect = -->
349
413
<xsl:template match="mediaobject | db:mediaobject">
350
<div class="mediaobject">
414
<xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable>
415
<xsl:if test="$if != ''">
417
<xsl:call-template name="html.class.attr">
418
<xsl:with-param name="class" select="'mediaobject'"/>
351
420
<xsl:call-template name="db2html.anchor"/>
352
421
<xsl:call-template name="db2html.mediaobject"/>
353
422
<!-- When a figure contains only a single mediaobject, it eats the caption -->
360
429
<xsl:apply-templates select="caption | db:caption"/>
365
435
<!-- = videodata = -->
366
436
<xsl:template match="mediaobject/videoobject/videodata |
367
437
db:mediaobject/db:videoobject/db:videodata">
368
<div class="media media-video">
439
<xsl:call-template name="html.class.attr">
440
<xsl:with-param name="class" select="'media media-video'"/>
369
442
<div class="inner">
370
443
<xsl:call-template name="db2html.videodata">
371
444
<xsl:with-param name="inline" select="false()"/>
376
449
<xsl:template match="inlinemediaobject/videoobject/videodata |
377
450
db:inlinemediaobject/db:videoobject/db:videodata">
378
<span class="media media-video">
452
<xsl:call-template name="html.class.attr">
453
<xsl:with-param name="class" select="'media media-video'"/>
379
455
<xsl:call-template name="db2html.videodata"/>