19
19
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
20
20
xmlns:db="http://docbook.org/ns/docbook"
21
xmlns:mml="http://www.w3.org/1998/Math/MathML"
21
22
xmlns="http://www.w3.org/1999/xhtml"
22
exclude-result-prefixes="db"
23
exclude-result-prefixes="db mml"
25
26
<!--!!==========================================================================
26
27
DocBook to HTML - Images and Media
27
:Requires: db2html-block db2html-xref
29
REMARK: Describe this module
28
Handle DocBook media elements.
29
:Revision:version="3.8" date="2012-11-13" status="final"
31
This stylesheet contains templates for handling DocBook #{mediaobject} and
32
#{inlinemediaobject} elements, as well as the various #{object} and #{data}
33
elements found in these elements. This stylesheet also handles the deprecated
34
DocBook 4 #{graphic} and #{inlinegraphic} elements.
38
<!--**==========================================================================
40
Output an HTML #{audio} element for a #{audiodata} element.
41
:Revision:version="3.8" date="2012-11-12" status="final"
42
$node: The #{audiodata} element.
44
This template creates an #{audio} element in the HTML output. This template
45
calls *{db2html.mediaobject.fallback} for the contents of the #{audio} element.
47
<xsl:template name="db2html.audiodata">
48
<xsl:param name="node" select="."/>
49
<xsl:variable name="media" select="($node/ancestor::mediaobject[1] |
50
$node/ancestor::inlinemediaobject[1] |
51
$node/ancestor::db:mediaobject[1] |
52
$node/ancestor::db:inlinemediaobject[1]
54
<audio preload="auto" controls="controls">
55
<xsl:attribute name="src">
57
<xsl:when test="$node/@fileref">
58
<xsl:value-of select="$node/@fileref"/>
60
<xsl:when test="$node/@entityref">
61
<xsl:value-of select="unparsed-entity-uri($node/@entityref)"/>
65
<xsl:attribute name="data-play-label">
66
<xsl:call-template name="l10n.gettext">
67
<xsl:with-param name="msgid" select="'Play'"/>
70
<xsl:attribute name="data-pause-label">
71
<xsl:call-template name="l10n.gettext">
72
<xsl:with-param name="msgid" select="'Pause'"/>
75
<xsl:call-template name="db2html.mediaobject.fallback">
76
<xsl:with-param name="node" select="$media"/>
33
82
<!--**==========================================================================
35
Renders an #{imagedata} element into an #{img} element
36
$node: The element to render
84
Output an HTML #{img} element for a #{imagedata} element.
85
:Revision:version="3.8" date="2012-11-12" status="final"
86
$node: The #{imagedata} or other graphic element.
38
This template creates an #{img} element in the HTML output. This named template
88
This template creates an #{img} element in the HTML output. This template
39
89
is called not only for #{imagedata} elements, but also for #{graphic} and
40
90
#{inlinegraphic} elements. Note that #{graphic} and #{inlinegraphic} are
41
91
deprecated and should not be used in any newly-written DocBook files. Use
42
92
#{mediaobject} instead.
44
REMARK: calls db2html.imagedata.src, how other attrs are gotten
46
94
<xsl:template name="db2html.imagedata">
47
95
<xsl:param name="node" select="."/>
49
97
<xsl:attribute name="src">
50
<xsl:call-template name="db2html.imagedata.src">
51
<xsl:with-param name="node" select="$node"/>
99
<xsl:when test="$node/@fileref">
100
<xsl:value-of select="$node/@fileref"/>
102
<xsl:when test="$node/@entityref">
103
<xsl:value-of select="unparsed-entity-uri($node/@entityref)"/>
55
<xsl:when test="$node/@scale">
56
<xsl:attribute name="width">
57
<xsl:value-of select="concat($node/@scale, '%')"/>
60
<xsl:when test="$node/@width">
61
<xsl:attribute name="width">
62
<xsl:value-of select="$node/@width"/>
64
<xsl:if test="$node/@height">
65
<xsl:attribute name="height">
66
<xsl:value-of select="$node/@height"/>
71
<xsl:if test="$node/@align">
72
<xsl:attribute name="align">
73
<xsl:value-of select="$node/@align"/>
77
<xsl:if test="$textobject/phrase">
107
<xsl:if test="$node/@contentwidth">
108
<xsl:attribute name="width">
109
<xsl:value-of select="$node/@contentwidth"/>
112
<xsl:if test="$node/@contentdepth">
113
<xsl:attribute name="height">
114
<xsl:value-of select="$node/@contentdepth"/>
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]
122
<xsl:variable name="alt" select="$media/textobject/phrase | $media/db:textobject/db:phrase"/>
78
124
<xsl:attribute name="alt">
79
<xsl:value-of select="phrase[1]"/>
125
<xsl:value-of select="$alt[1]"/>
83
<!-- FIXME: longdesc -->
88
132
<!--**==========================================================================
90
Outputs the content of the #{src} attribute for an #{img} element
91
$node: The element to render
134
Output an HTML #{video} element for a #{videodata} element.
135
:Revision:version="3.8" date="2012-11-12" status="final"
136
$node: The #{videodata} element.
93
This template is called by *{db2html.imagedata.src} for the content of the
94
#{src} attribute of an #{img} element.
138
This template creates a #{video} element in the HTML output. If the containing
139
#{mediaobject} or #{inlinemediaobject} element has an #{imageobject} with the
140
#{role} attribute set to #{"poster"}, that image will be used for the #{poster}
141
attribute on the HTML #{video} element. This template calls
142
*{db2html.mediaobject.fallback} for the contents of the #{video} element.
96
<xsl:template name="db2html.imagedata.src">
144
<xsl:template name="db2html.videodata">
97
145
<xsl:param name="node" select="."/>
99
<xsl:when test="$node/@fileref">
100
<!-- FIXME: do this less stupidly, or not at all -->
146
<xsl:variable name="media" select="($node/ancestor::mediaobject[1] |
147
$node/ancestor::inlinemediaobject[1] |
148
$node/ancestor::db:mediaobject[1] |
149
$node/ancestor::db:inlinemediaobject[1]
151
<video preload="auto" controls="controls">
152
<xsl:attribute name="src">
102
<xsl:when test="$node/@format = 'PNG' and
103
(substring($node/@fileref, string-length($node/@fileref) - 3)
105
<xsl:value-of select="concat($node/@fileref, '.png')"/>
154
<xsl:when test="$node/@fileref">
108
155
<xsl:value-of select="$node/@fileref"/>
157
<xsl:when test="$node/@entityref">
158
<xsl:value-of select="unparsed-entity-uri($node/@entityref)"/>
112
<xsl:when test="$node/@entityref">
113
<xsl:value-of select="unparsed-entity-uri($node/@entityref)"/>
162
<xsl:if test="$node/@contentwidth">
163
<xsl:attribute name="width">
164
<xsl:value-of select="$node/@contentwidth"/>
167
<xsl:if test="$node/@contentdepth">
168
<xsl:attribute name="height">
169
<xsl:value-of select="$node/@contentdepth"/>
172
<xsl:variable name="poster"
173
select="$media/imageobject[@role = 'poster']/imagedata |
174
$media/db:imageobject[@role = 'poster']/db:imagedata"/>
175
<xsl:if test="$poster">
176
<xsl:attribute name="poster">
178
<xsl:when test="$poster/@fileref">
179
<xsl:value-of select="$poster/@fileref"/>
181
<xsl:when test="$poster/@entityref">
182
<xsl:value-of select="unparsed-entity-uri($poster/@entityref)"/>
187
<xsl:attribute name="data-play-label">
188
<xsl:call-template name="l10n.gettext">
189
<xsl:with-param name="msgid" select="'Play'"/>
192
<xsl:attribute name="data-pause-label">
193
<xsl:call-template name="l10n.gettext">
194
<xsl:with-param name="msgid" select="'Pause'"/>
197
<xsl:call-template name="db2html.mediaobject.fallback">
198
<xsl:with-param name="node" select="$media"/>
119
204
<!--**==========================================================================
120
205
db2html.mediaobject
121
Outputs HTML for a #{mediaobject} element
122
$node: The element to render
206
Outputs HTML for a #{mediaobject} element.
207
:Revision:version="3.8" date="2012-11-13" status="final"
208
$node: The #{mediaobject} element.
124
210
This template processes a #{mediaobject} element and outputs the appropriate
125
HTML. DocBook allows multiple objects to be listed in a #{mediaobject} element.
126
Processing tools are expected to choose the earliest suitable object. Currently,
127
this template only chooses the first suitable #{imageobject} element. Support
128
for #{videobject} and #{audioobject} should be added in future versions, as well
211
HTML. DocBook allows multiple objects to be listed in a #{mediaobject} element.
212
Processing tools are expected to choose the earliest suitable object. This
213
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}.
217
This template also detects MathML embedded in a DocBook 5 #{imagedata} element
218
with the #{format} attribute #{"mathml"}, and passes it to the templates in
131
221
<xsl:template name="db2html.mediaobject">
132
222
<xsl:param name="node" select="."/>
223
<xsl:variable name="objs" select="
224
$node/audioobject | $node/db:audioobject |
225
$node/videoobject | $node/db:videoobject |
226
$node/imageobject[imagedata[
227
@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or
228
@format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or
230
$node/imageobjectco[imageobject/imagedata[
231
@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or
232
@format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or
234
$node/db:imageobject[db:imagedata[
235
@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or
236
@format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or
238
$node/db:imageobject[db:imagedata[@format = 'mathml'][mml:math]] |
239
$node/db:imageobjectco[db:imageobject/db:imagedata[
240
@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or
241
@format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or
135
<xsl:when test="$text_only">
136
<xsl:apply-templates select="textobject[1]"/>
244
<xsl:when test="$objs">
245
<xsl:apply-templates select="$objs[1]"/>
248
<xsl:call-template name="db2html.mediaobject.fallback">
249
<xsl:with-param name="node" select="$node"/>
256
<!--**==========================================================================
257
db2html.mediaobject.fallback
258
Outputs fallback HTML for a #{mediaobject} element.
259
:Revision:version="3.8" date="2012-11-13" status="final"
260
$node: The #{mediaobject} element.
262
This template outputs HTML for the first suitable #{textobject} child element
263
of ${node}. If ${node} is an #{inlinemediaobject}, it looks for a #{textobject}
264
that contains a #{phrase} element. Otherwise, it looks for a #{textobject} with
265
normal block content.
139
<xsl:when test="$node/imageobject[imagedata/@format = 'PNG']">
141
select="$node/imageobject[imagedata/@format = 'PNG'][1]">
142
<xsl:with-param name="textobject" select="$node/textobject[1]"/>
143
</xsl:apply-templates>
145
<xsl:when test="$node/db:imageobject[db:imagedata/@format = 'PNG']">
147
select="$node/db:imageobject[db:imagedata/@format = 'PNG'][1]">
148
<xsl:with-param name="textobject" select="$node/db:textobject[1]"/>
149
</xsl:apply-templates>
151
<xsl:when test="$node/imageobjectco[imageobject/imagedata/@format = 'PNG']">
153
select="$node/imageobjectco[imageobject/imagedata/@format = 'PNG'][1]">
154
<xsl:with-param name="textobject" select="$node/textobject[1]"/>
155
</xsl:apply-templates>
157
<xsl:when test="$node/db:imageobjectco[db:imageobject/db:imagedata/@format = 'PNG']">
159
select="$node/db:imageobjectco[db:imageobject/db:imagedata/@format = 'PNG'][1]">
160
<xsl:with-param name="textobject" select="$node/db:textobject[1]"/>
161
</xsl:apply-templates>
267
<xsl:template name="db2html.mediaobject.fallback">
268
<xsl:param name="node" select="."/>
270
<xsl:when test="local-name($node) = 'inlinemediaobject'">
271
<xsl:apply-templates select="($node/textobject/phrase | $node/db:textobject/db:phrase)[1]"/>
164
<xsl:apply-templates select="($node/imageobject | $node/imageobjectco |
165
$node/db:imageobject |
166
$node/db:imageobjectco)[1]">
167
<xsl:with-param name="textobject" select="$node/db:textobject[1]"/>
168
</xsl:apply-templates>
274
<xsl:apply-templates select="($node/textobject[not(phrase or textdata)] |
275
$node/db:textobject[not(db:phrase or db:textdata)]