~ubuntu-branches/ubuntu/saucy/yelp-xsl/saucy

« back to all changes in this revision

Viewing changes to xslt/docbook/html/db2html-media.xsl

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2013-05-30 09:55:02 UTC
  • mfrom: (11.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130530095502-uqkc9bzuod7xqrmn
Tags: 3.8.1-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
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"
23
24
                version="1.0">
24
25
 
25
26
<!--!!==========================================================================
26
27
DocBook to HTML - Images and Media
27
 
:Requires: db2html-block db2html-xref
28
 
 
29
 
REMARK: Describe this module
30
 
-->
 
28
Handle DocBook media elements.
 
29
:Revision:version="3.8" date="2012-11-13" status="final"
 
30
 
 
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.
 
35
-->
 
36
 
 
37
 
 
38
<!--**==========================================================================
 
39
db2html.audiodata
 
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.
 
43
 
 
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.
 
46
-->
 
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]
 
53
                                     )[last()]"/>
 
54
  <audio preload="auto" controls="controls">
 
55
    <xsl:attribute name="src">
 
56
      <xsl:choose>
 
57
        <xsl:when test="$node/@fileref">
 
58
          <xsl:value-of select="$node/@fileref"/>
 
59
        </xsl:when>
 
60
        <xsl:when test="$node/@entityref">
 
61
          <xsl:value-of select="unparsed-entity-uri($node/@entityref)"/>
 
62
        </xsl:when>
 
63
      </xsl:choose>
 
64
    </xsl:attribute>
 
65
    <xsl:attribute name="data-play-label">
 
66
      <xsl:call-template name="l10n.gettext">
 
67
        <xsl:with-param name="msgid" select="'Play'"/>
 
68
      </xsl:call-template>
 
69
    </xsl:attribute>
 
70
    <xsl:attribute name="data-pause-label">
 
71
      <xsl:call-template name="l10n.gettext">
 
72
        <xsl:with-param name="msgid" select="'Pause'"/>
 
73
      </xsl:call-template>
 
74
    </xsl:attribute>
 
75
    <xsl:call-template name="db2html.mediaobject.fallback">
 
76
      <xsl:with-param name="node" select="$media"/>
 
77
    </xsl:call-template>
 
78
  </audio>
 
79
</xsl:template>
31
80
 
32
81
 
33
82
<!--**==========================================================================
34
83
db2html.imagedata
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.
37
87
 
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.
43
 
 
44
 
REMARK: calls db2html.imagedata.src, how other attrs are gotten
45
93
-->
46
94
<xsl:template name="db2html.imagedata">
47
95
  <xsl:param name="node" select="."/>
48
96
  <img>
49
97
    <xsl:attribute name="src">
50
 
      <xsl:call-template name="db2html.imagedata.src">
51
 
        <xsl:with-param name="node" select="$node"/>
52
 
      </xsl:call-template>
 
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>
53
106
    </xsl:attribute>
54
 
    <xsl:choose>
55
 
      <xsl:when test="$node/@scale">
56
 
        <xsl:attribute name="width">
57
 
          <xsl:value-of select="concat($node/@scale, '%')"/>
58
 
        </xsl:attribute>
59
 
      </xsl:when>
60
 
      <xsl:when test="$node/@width">
61
 
        <xsl:attribute name="width">
62
 
          <xsl:value-of select="$node/@width"/>
63
 
        </xsl:attribute>
64
 
        <xsl:if test="$node/@height">
65
 
          <xsl:attribute name="height">
66
 
            <xsl:value-of select="$node/@height"/>
67
 
          </xsl:attribute>
68
 
        </xsl:if>
69
 
      </xsl:when>
70
 
    </xsl:choose>
71
 
    <xsl:if test="$node/@align">
72
 
      <xsl:attribute name="align">
73
 
        <xsl:value-of select="$node/@align"/>
74
 
      </xsl:attribute>
75
 
    </xsl:if>
76
 
<!-- FIXME
77
 
    <xsl:if test="$textobject/phrase">
 
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:if test="$alt">
78
124
      <xsl:attribute name="alt">
79
 
        <xsl:value-of select="phrase[1]"/>
 
125
        <xsl:value-of select="$alt[1]"/>
80
126
      </xsl:attribute>
81
127
    </xsl:if>
82
 
-->
83
 
    <!-- FIXME: longdesc -->
84
128
  </img>
85
129
</xsl:template>
86
130
 
87
131
 
88
132
<!--**==========================================================================
89
 
db2html.imagedata.src
90
 
Outputs the content of the #{src} attribute for an #{img} element
91
 
$node: The element to render
 
133
db2html.videodata
 
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.
92
137
 
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.
95
143
-->
96
 
<xsl:template name="db2html.imagedata.src">
 
144
<xsl:template name="db2html.videodata">
97
145
  <xsl:param name="node" select="."/>
98
 
  <xsl:choose>
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]
 
150
                                     )[last()]"/>
 
151
  <video preload="auto" controls="controls">
 
152
    <xsl:attribute name="src">
101
153
      <xsl:choose>
102
 
        <xsl:when test="$node/@format = 'PNG' and
103
 
                        (substring($node/@fileref, string-length($node/@fileref) - 3)
104
 
                          != '.png')">
105
 
          <xsl:value-of select="concat($node/@fileref, '.png')"/>
106
 
        </xsl:when>
107
 
        <xsl:otherwise>
 
154
        <xsl:when test="$node/@fileref">
108
155
          <xsl:value-of select="$node/@fileref"/>
109
 
        </xsl:otherwise>
 
156
        </xsl:when>
 
157
        <xsl:when test="$node/@entityref">
 
158
          <xsl:value-of select="unparsed-entity-uri($node/@entityref)"/>
 
159
        </xsl:when>
110
160
      </xsl:choose>
111
 
    </xsl:when>
112
 
    <xsl:when test="$node/@entityref">
113
 
      <xsl:value-of select="unparsed-entity-uri($node/@entityref)"/>
114
 
    </xsl:when>
115
 
  </xsl:choose>
 
161
    </xsl:attribute>
 
162
    <xsl:if test="$node/@contentwidth">
 
163
      <xsl:attribute name="width">
 
164
        <xsl:value-of select="$node/@contentwidth"/>
 
165
      </xsl:attribute>
 
166
    </xsl:if>
 
167
    <xsl:if test="$node/@contentdepth">
 
168
      <xsl:attribute name="height">
 
169
        <xsl:value-of select="$node/@contentdepth"/>
 
170
      </xsl:attribute>
 
171
    </xsl:if>
 
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">
 
177
        <xsl:choose>
 
178
          <xsl:when test="$poster/@fileref">
 
179
            <xsl:value-of select="$poster/@fileref"/>
 
180
          </xsl:when>
 
181
          <xsl:when test="$poster/@entityref">
 
182
            <xsl:value-of select="unparsed-entity-uri($poster/@entityref)"/>
 
183
          </xsl:when>
 
184
        </xsl:choose>
 
185
      </xsl:attribute>
 
186
    </xsl:if>
 
187
    <xsl:attribute name="data-play-label">
 
188
      <xsl:call-template name="l10n.gettext">
 
189
        <xsl:with-param name="msgid" select="'Play'"/>
 
190
      </xsl:call-template>
 
191
    </xsl:attribute>
 
192
    <xsl:attribute name="data-pause-label">
 
193
      <xsl:call-template name="l10n.gettext">
 
194
        <xsl:with-param name="msgid" select="'Pause'"/>
 
195
      </xsl:call-template>
 
196
    </xsl:attribute>
 
197
    <xsl:call-template name="db2html.mediaobject.fallback">
 
198
      <xsl:with-param name="node" select="$media"/>
 
199
    </xsl:call-template>
 
200
  </video>
116
201
</xsl:template>
117
202
 
118
203
 
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.
123
209
 
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
129
 
as a text-only mode.
 
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}.
 
216
 
 
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
 
219
!{db2html-math}.
130
220
-->
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
 
229
      not(@format)]] |
 
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
 
233
      not(@format)]] |
 
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
 
237
      not(@format)]] |
 
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
 
242
      not(@format)]] "/>
133
243
  <xsl:choose>
134
 
<!-- FIXME
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]"/>
137
246
    </xsl:when>
 
247
    <xsl:otherwise>
 
248
      <xsl:call-template name="db2html.mediaobject.fallback">
 
249
        <xsl:with-param name="node" select="$node"/>
 
250
      </xsl:call-template>
 
251
    </xsl:otherwise>
 
252
  </xsl:choose>
 
253
</xsl:template>
 
254
 
 
255
 
 
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.
 
261
 
 
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.
138
266
-->
139
 
    <xsl:when test="$node/imageobject[imagedata/@format = 'PNG']">
140
 
      <xsl:apply-templates
141
 
       select="$node/imageobject[imagedata/@format = 'PNG'][1]">
142
 
        <xsl:with-param name="textobject" select="$node/textobject[1]"/>
143
 
      </xsl:apply-templates>
144
 
    </xsl:when>
145
 
    <xsl:when test="$node/db:imageobject[db:imagedata/@format = 'PNG']">
146
 
      <xsl:apply-templates
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>
150
 
    </xsl:when>
151
 
    <xsl:when test="$node/imageobjectco[imageobject/imagedata/@format = 'PNG']">
152
 
      <xsl:apply-templates
153
 
       select="$node/imageobjectco[imageobject/imagedata/@format = 'PNG'][1]">
154
 
        <xsl:with-param name="textobject" select="$node/textobject[1]"/>
155
 
      </xsl:apply-templates>
156
 
    </xsl:when>
157
 
    <xsl:when test="$node/db:imageobjectco[db:imageobject/db:imagedata/@format = 'PNG']">
158
 
      <xsl:apply-templates
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="."/>
 
269
  <xsl:choose>
 
270
    <xsl:when test="local-name($node) = 'inlinemediaobject'">
 
271
      <xsl:apply-templates select="($node/textobject/phrase | $node/db:textobject/db:phrase)[1]"/>
162
272
    </xsl:when>
163
273
    <xsl:otherwise>
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)]
 
276
                                   )[1]/*"/>
169
277
    </xsl:otherwise>
170
278
  </xsl:choose>
171
279
</xsl:template>
173
281
 
174
282
<!-- == Matched Templates == -->
175
283
 
 
284
<!-- = audiodata = -->
 
285
<xsl:template match="mediaobject/audioobject/audiodata |
 
286
                     db:mediaobject/db:audioobject/db:audiodata">
 
287
  <div class="media media-audio">
 
288
    <div class="inner">
 
289
      <xsl:call-template name="db2html.audiodata">
 
290
        <xsl:with-param name="inline" select="false()"/>
 
291
      </xsl:call-template>
 
292
    </div>
 
293
  </div>
 
294
</xsl:template>
 
295
<xsl:template match="inlinemediaobject/audioobject/audiodata |
 
296
                     db:inlinemediaobject/db:audioobject/db:audiodata">
 
297
  <span class="media media-audio">
 
298
    <xsl:call-template name="db2html.audiodata"/>
 
299
  </span>
 
300
</xsl:template>
 
301
 
 
302
<!-- = audioobject = -->
 
303
<xsl:template match="audioobject | db:audioobject">
 
304
  <xsl:apply-templates select="audiodata | db:audiodata"/>
 
305
</xsl:template>
 
306
 
176
307
<!-- = graphic = -->
177
308
<xsl:template match="graphic">
178
309
  <div class="graphic">
183
314
 
184
315
<!-- = imagedata = -->
185
316
<xsl:template match="imagedata | db:imagedata">
186
 
  <xsl:call-template name="db2html.imagedata"/>
 
317
  <xsl:choose>
 
318
    <xsl:when test="@format = 'mathml' and mml:math">
 
319
      <xsl:apply-templates select="mml:math"/>
 
320
    </xsl:when>
 
321
    <xsl:otherwise>
 
322
      <xsl:call-template name="db2html.imagedata"/>
 
323
    </xsl:otherwise>
 
324
  </xsl:choose>
187
325
</xsl:template>
188
326
 
189
327
<!-- = imageobject = -->
224
362
  </div>
225
363
</xsl:template>
226
364
 
 
365
<!-- = videodata = -->
 
366
<xsl:template match="mediaobject/videoobject/videodata |
 
367
                     db:mediaobject/db:videoobject/db:videodata">
 
368
  <div class="media media-video">
 
369
    <div class="inner">
 
370
      <xsl:call-template name="db2html.videodata">
 
371
        <xsl:with-param name="inline" select="false()"/>
 
372
      </xsl:call-template>
 
373
    </div>
 
374
  </div>
 
375
</xsl:template>
 
376
<xsl:template match="inlinemediaobject/videoobject/videodata |
 
377
                     db:inlinemediaobject/db:videoobject/db:videodata">
 
378
  <span class="media media-video">
 
379
    <xsl:call-template name="db2html.videodata"/>
 
380
  </span>
 
381
</xsl:template>
 
382
 
 
383
<!-- = videoobject = -->
 
384
<xsl:template match="videoobject | db:videoobject">
 
385
  <xsl:apply-templates select="videodata | db:videodata"/>
 
386
</xsl:template>
 
387
 
227
388
</xsl:stylesheet>