Debian Codegraph @

docs/xsl-generic/html/graphics.xsl

raw
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:xlink="http://www.w3.org/1999/xlink"
4 xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
5 xmlns:simg="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.ImageIntrinsics"
6 xmlns:ximg="xalan://com.nwalsh.xalan.ImageIntrinsics"
7 xmlns:xtext="xalan://com.nwalsh.xalan.Text"
8 xmlns:lxslt="http://xml.apache.org/xslt"
9 exclude-result-prefixes="xlink stext xtext lxslt simg ximg"
10 extension-element-prefixes="stext xtext"
11 version='1.0'>
12
13 <!-- ********************************************************************
14 $Id: graphics.xsl 7241 2007-08-14 15:59:17Z mzjn $
15 ********************************************************************
16
17 This file is part of the XSL DocBook Stylesheet distribution.
18 See ../README or http://docbook.sf.net/release/xsl/current/ for
19 copyright and other information.
20
21 Contributors:
22 Colin Paul Adams, <[email protected]>
23
24 ******************************************************************** -->
25
26 <lxslt:component prefix="xtext" elements="insertfile"/>
27 <lxslt:component prefix="ximg" functions="new getWidth getDepth"/>
28
29 <!-- ==================================================================== -->
30 <!-- Graphic format tests for the HTML backend -->
31
32 <xsl:template name="is.graphic.format">
33 <xsl:param name="format"></xsl:param>
34 <xsl:if test="$format = 'SVG'
35 or $format = 'PNG'
36 or $format = 'JPG'
37 or $format = 'JPEG'
38 or $format = 'linespecific'
39 or $format = 'GIF'
40 or $format = 'GIF87a'
41 or $format = 'GIF89a'
42 or $format = 'BMP'">1</xsl:if>
43 </xsl:template>
44
45 <xsl:template name="is.graphic.extension">
46 <xsl:param name="ext"></xsl:param>
47 <xsl:variable name="lcext" select="translate($ext,
48 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
49 'abcdefghijklmnopqrstuvwxyz')"/>
50 <xsl:if test="$lcext = 'svg'
51 or $lcext = 'png'
52 or $lcext = 'jpeg'
53 or $lcext = 'jpg'
54 or $lcext = 'avi'
55 or $lcext = 'mpg'
56 or $lcext = 'mpeg'
57 or $lcext = 'qt'
58 or $lcext = 'gif'
59 or $lcext = 'bmp'">1</xsl:if>
60 </xsl:template>
61
62 <!-- ==================================================================== -->
63
64 <xsl:template match="screenshot">
65 <div>
66 <xsl:apply-templates select="." mode="class.attribute"/>
67 <xsl:apply-templates/>
68 </div>
69 </xsl:template>
70
71 <xsl:template match="screeninfo">
72 </xsl:template>
73
74 <!-- ==================================================================== -->
75
76 <xsl:template name="process.image">
77 <!-- When this template is called, the current node should be -->
78 <!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
79 <!-- those elements have the same set of attributes, so we can -->
80 <!-- handle them all in one place. -->
81 <xsl:param name="tag" select="'img'"/>
82 <xsl:param name="alt"/>
83 <xsl:param name="longdesc"/>
84
85 <!-- The HTML img element only supports the notion of content-area
86 scaling; it doesn't support the distinction between a
87 content-area and a viewport-area, so we have to make some
88 compromises.
89
90 1. If only the content-area is specified, everything is fine.
91 (If you ask for a three inch image, that's what you'll get.)
92
93 2. If only the viewport-area is provided:
94 - If scalefit=1, treat it as both the content-area and
95 the viewport-area. (If you ask for an image in a five inch
96 area, we'll make the image five inches to fill that area.)
97 - If scalefit=0, ignore the viewport-area specification.
98
99 Note: this is not quite the right semantic and has the additional
100 problem that it can result in anamorphic scaling, which scalefit
101 should never cause.
102
103 3. If both the content-area and the viewport-area is specified
104 on a graphic element, ignore the viewport-area.
105 (If you ask for a three inch image in a five inch area, we'll assume
106 it's better to give you a three inch image in an unspecified area
107 than a five inch image in a five inch area.
108
109 Relative units also cause problems. As a general rule, the stylesheets
110 are operating too early and too loosely coupled with the rendering engine
111 to know things like the current font size or the actual dimensions of
112 an image. Therefore:
113
114 1. We use a fixed size for pixels, $pixels.per.inch
115
116 2. We use a fixed size for "em"s, $points.per.em
117
118 Percentages are problematic. In the following discussion, we speak
119 of width and contentwidth, but the same issues apply to depth and
120 contentdepth
121
122 1. A width of 50% means "half of the available space for the image."
123 That's fine. But note that in HTML, this is a dynamic property and
124 the image size will vary if the browser window is resized.
125
126 2. A contentwidth of 50% means "half of the actual image width". But
127 the stylesheets have no way to assess the image's actual size. Treating
128 this as a width of 50% is one possibility, but it produces behavior
129 (dynamic scaling) that seems entirely out of character with the
130 meaning.
131
132 Instead, the stylesheets define a $nominal.image.width
133 and convert percentages to actual values based on that nominal size.
134
135 Scale can be problematic. Scale applies to the contentwidth, so
136 a scale of 50 when a contentwidth is not specified is analagous to a
137 width of 50%. (If a contentwidth is specified, the scaling factor can
138 be applied to that value and no problem exists.)
139
140 If scale is specified but contentwidth is not supplied, the
141 nominal.image.width is used to calculate a base size
142 for scaling.
143
144 Warning: as a consequence of these decisions, unless the aspect ratio
145 of your image happens to be exactly the same as (nominal width / nominal height),
146 specifying contentwidth="50%" and contentdepth="50%" is NOT going to
147 scale the way you expect (or really, the way it should).
148
149 Don't do that. In fact, a percentage value is not recommended for content
150 size at all. Use scale instead.
151
152 Finally, align and valign are troublesome. Horizontal alignment is now
153 supported by wrapping the image in a <div align="{@align}"> (in block
154 contexts!). I can't think of anything (practical) to do about vertical
155 alignment.
156 -->
157
158 <xsl:variable name="width-units">
159 <xsl:choose>
160 <xsl:when test="$ignore.image.scaling != 0"></xsl:when>
161 <xsl:when test="@width">
162 <xsl:call-template name="length-units">
163 <xsl:with-param name="length" select="@width"/>
164 </xsl:call-template>
165 </xsl:when>
166 <xsl:when test="not(@depth) and $default.image.width != ''">
167 <xsl:call-template name="length-units">
168 <xsl:with-param name="length" select="$default.image.width"/>
169 </xsl:call-template>
170 </xsl:when>
171 </xsl:choose>
172 </xsl:variable>
173
174 <xsl:variable name="width">
175 <xsl:choose>
176 <xsl:when test="$ignore.image.scaling != 0"></xsl:when>
177 <xsl:when test="@width">
178 <xsl:choose>
179 <xsl:when test="$width-units = '%'">
180 <xsl:value-of select="@width"/>
181 </xsl:when>
182 <xsl:otherwise>
183 <xsl:call-template name="length-spec">
184 <xsl:with-param name="length" select="@width"/>
185 </xsl:call-template>
186 </xsl:otherwise>
187 </xsl:choose>
188 </xsl:when>
189 <xsl:when test="not(@depth) and $default.image.width != ''">
190 <xsl:value-of select="$default.image.width"/>
191 </xsl:when>
192 </xsl:choose>
193 </xsl:variable>
194
195 <xsl:variable name="scalefit">
196 <xsl:choose>
197 <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
198 <xsl:when test="@contentwidth or @contentdepth">0</xsl:when>
199 <xsl:when test="@scale">0</xsl:when>
200 <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
201 <xsl:when test="$width != '' or @depth">1</xsl:when>
202 <xsl:otherwise>0</xsl:otherwise>
203 </xsl:choose>
204 </xsl:variable>
205
206 <xsl:variable name="scale">
207 <xsl:choose>
208 <xsl:when test="$ignore.image.scaling != 0">1.0</xsl:when>
209 <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
210 <xsl:when test="@scale">
211 <xsl:value-of select="@scale div 100.0"/>
212 </xsl:when>
213 <xsl:otherwise>1.0</xsl:otherwise>
214 </xsl:choose>
215 </xsl:variable>
216
217 <xsl:variable name="filename">
218 <xsl:choose>
219 <xsl:when test="local-name(.) = 'graphic'
220 or local-name(.) = 'inlinegraphic'">
221 <!-- handle legacy graphic and inlinegraphic by new template -->
222 <xsl:call-template name="mediaobject.filename">
223 <xsl:with-param name="object" select="."/>
224 </xsl:call-template>
225 </xsl:when>
226 <xsl:otherwise>
227 <!-- imagedata, videodata, audiodata -->
228 <xsl:call-template name="mediaobject.filename">
229 <xsl:with-param name="object" select=".."/>
230 </xsl:call-template>
231 </xsl:otherwise>
232 </xsl:choose>
233 </xsl:variable>
234
235 <xsl:variable name="output_filename">
236 <xsl:choose>
237 <xsl:when test="@entityref">
238 <xsl:value-of select="$filename"/>
239 </xsl:when>
240 <!--
241 Moved test for $keep.relative.image.uris to template below:
242 <xsl:template match="@fileref">
243 -->
244 <xsl:otherwise>
245 <xsl:value-of select="$filename"/>
246 </xsl:otherwise>
247 </xsl:choose>
248 </xsl:variable>
249
250 <xsl:variable name="img.src.path.pi">
251 <xsl:call-template name="pi.dbhtml_img.src.path">
252 <xsl:with-param name="node" select=".."/>
253 </xsl:call-template>
254 </xsl:variable>
255
256 <xsl:variable name="filename.for.graphicsize">
257 <xsl:choose>
258 <xsl:when test="$img.src.path.pi != ''">
259 <xsl:value-of select="concat($img.src.path.pi, $filename)"/>
260 </xsl:when>
261 <xsl:when test="$img.src.path != '' and
262 $graphicsize.use.img.src.path != 0 and
263 $tag = 'img' and
264 not(starts-with($filename, '/')) and
265 not(contains($filename, '://'))">
266 <xsl:value-of select="concat($img.src.path, $filename)"/>
267 </xsl:when>
268 <xsl:otherwise>
269 <xsl:value-of select="$filename"/>
270 </xsl:otherwise>
271 </xsl:choose>
272 </xsl:variable>
273
274 <xsl:variable name="realintrinsicwidth">
275 <!-- This funny compound test works around a bug in XSLTC -->
276 <xsl:choose>
277 <xsl:when test="$use.extensions != 0 and $graphicsize.extension != 0">
278 <xsl:choose>
279 <xsl:when test="function-available('simg:getWidth')">
280 <xsl:value-of select="simg:getWidth(simg:new($filename.for.graphicsize),
281 $nominal.image.width)"/>
282 </xsl:when>
283 <xsl:when test="function-available('ximg:getWidth')">
284 <xsl:value-of select="ximg:getWidth(ximg:new($filename.for.graphicsize),
285 $nominal.image.width)"/>
286 </xsl:when>
287 <xsl:otherwise>
288 <xsl:value-of select="0"/>
289 </xsl:otherwise>
290 </xsl:choose>
291 </xsl:when>
292 <xsl:otherwise>
293 <xsl:value-of select="0"/>
294 </xsl:otherwise>
295 </xsl:choose>
296 </xsl:variable>
297
298 <xsl:variable name="intrinsicwidth">
299 <xsl:choose>
300 <xsl:when test="$realintrinsicwidth = 0">
301 <xsl:value-of select="$nominal.image.width"/>
302 </xsl:when>
303 <xsl:otherwise>
304 <xsl:value-of select="$realintrinsicwidth"/>
305 </xsl:otherwise>
306 </xsl:choose>
307 </xsl:variable>
308
309 <xsl:variable name="intrinsicdepth">
310 <!-- This funny compound test works around a bug in XSLTC -->
311 <xsl:choose>
312 <xsl:when test="$use.extensions != 0 and $graphicsize.extension != 0">
313 <xsl:choose>
314 <xsl:when test="function-available('simg:getDepth')">
315 <xsl:value-of select="simg:getDepth(simg:new($filename.for.graphicsize),
316 $nominal.image.depth)"/>
317 </xsl:when>
318 <xsl:when test="function-available('ximg:getDepth')">
319 <xsl:value-of select="ximg:getDepth(ximg:new($filename.for.graphicsize),
320 $nominal.image.depth)"/>
321 </xsl:when>
322 <xsl:otherwise>
323 <xsl:value-of select="$nominal.image.depth"/>
324 </xsl:otherwise>
325 </xsl:choose>
326 </xsl:when>
327 <xsl:otherwise>
328 <xsl:value-of select="$nominal.image.depth"/>
329 </xsl:otherwise>
330 </xsl:choose>
331 </xsl:variable>
332
333 <xsl:variable name="contentwidth">
334 <xsl:choose>
335 <xsl:when test="$ignore.image.scaling != 0"></xsl:when>
336 <xsl:when test="@contentwidth">
337 <xsl:variable name="units">
338 <xsl:call-template name="length-units">
339 <xsl:with-param name="length" select="@contentwidth"/>
340 </xsl:call-template>
341 </xsl:variable>
342
343 <xsl:choose>
344 <xsl:when test="$units = '%'">
345 <xsl:variable name="cmagnitude">
346 <xsl:call-template name="length-magnitude">
347 <xsl:with-param name="length" select="@contentwidth"/>
348 </xsl:call-template>
349 </xsl:variable>
350 <xsl:value-of select="$intrinsicwidth * $cmagnitude div 100.0"/>
351 <xsl:text>px</xsl:text>
352 </xsl:when>
353 <xsl:otherwise>
354 <xsl:call-template name="length-spec">
355 <xsl:with-param name="length" select="@contentwidth"/>
356 </xsl:call-template>
357 </xsl:otherwise>
358 </xsl:choose>
359 </xsl:when>
360 <xsl:otherwise>
361 <xsl:value-of select="$intrinsicwidth"/>
362 <xsl:text>px</xsl:text>
363 </xsl:otherwise>
364 </xsl:choose>
365 </xsl:variable>
366
367 <xsl:variable name="scaled.contentwidth">
368 <xsl:if test="$contentwidth != ''">
369 <xsl:variable name="cwidth.in.points">
370 <xsl:call-template name="length-in-points">
371 <xsl:with-param name="length" select="$contentwidth"/>
372 <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
373 <xsl:with-param name="em.size" select="$points.per.em"/>
374 </xsl:call-template>
375 </xsl:variable>
376 <xsl:value-of select="$cwidth.in.points div 72.0 * $pixels.per.inch * $scale"/>
377 </xsl:if>
378 </xsl:variable>
379
380 <xsl:variable name="html.width">
381 <xsl:choose>
382 <xsl:when test="$ignore.image.scaling != 0"></xsl:when>
383 <xsl:when test="$width-units = '%'">
384 <xsl:value-of select="$width"/>
385 </xsl:when>
386 <xsl:when test="$width != ''">
387 <xsl:variable name="width.in.points">
388 <xsl:call-template name="length-in-points">
389 <xsl:with-param name="length" select="$width"/>
390 <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
391 <xsl:with-param name="em.size" select="$points.per.em"/>
392 </xsl:call-template>
393 </xsl:variable>
394 <xsl:value-of select="round($width.in.points div 72.0 * $pixels.per.inch)"/>
395 </xsl:when>
396 <xsl:otherwise></xsl:otherwise>
397 </xsl:choose>
398 </xsl:variable>
399
400 <xsl:variable name="contentdepth">
401 <xsl:choose>
402 <xsl:when test="$ignore.image.scaling != 0"></xsl:when>
403 <xsl:when test="@contentdepth">
404 <xsl:variable name="units">
405 <xsl:call-template name="length-units">
406 <xsl:with-param name="length" select="@contentdepth"/>
407 </xsl:call-template>
408 </xsl:variable>
409
410 <xsl:choose>
411 <xsl:when test="$units = '%'">
412 <xsl:variable name="cmagnitude">
413 <xsl:call-template name="length-magnitude">
414 <xsl:with-param name="length" select="@contentdepth"/>
415 </xsl:call-template>
416 </xsl:variable>
417 <xsl:value-of select="$intrinsicdepth * $cmagnitude div 100.0"/>
418 <xsl:text>px</xsl:text>
419 </xsl:when>
420 <xsl:otherwise>
421 <xsl:call-template name="length-spec">
422 <xsl:with-param name="length" select="@contentdepth"/>
423 </xsl:call-template>
424 </xsl:otherwise>
425 </xsl:choose>
426 </xsl:when>
427 <xsl:otherwise>
428 <xsl:value-of select="$intrinsicdepth"/>
429 <xsl:text>px</xsl:text>
430 </xsl:otherwise>
431 </xsl:choose>
432 </xsl:variable>
433
434 <xsl:variable name="scaled.contentdepth">
435 <xsl:if test="$contentdepth != ''">
436 <xsl:variable name="cdepth.in.points">
437 <xsl:call-template name="length-in-points">
438 <xsl:with-param name="length" select="$contentdepth"/>
439 <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
440 <xsl:with-param name="em.size" select="$points.per.em"/>
441 </xsl:call-template>
442 </xsl:variable>
443 <xsl:value-of select="$cdepth.in.points div 72.0 * $pixels.per.inch * $scale"/>
444 </xsl:if>
445 </xsl:variable>
446
447 <xsl:variable name="depth-units">
448 <xsl:if test="@depth">
449 <xsl:call-template name="length-units">
450 <xsl:with-param name="length" select="@depth"/>
451 </xsl:call-template>
452 </xsl:if>
453 </xsl:variable>
454
455 <xsl:variable name="depth">
456 <xsl:if test="@depth">
457 <xsl:choose>
458 <xsl:when test="$depth-units = '%'">
459 <xsl:value-of select="@depth"/>
460 </xsl:when>
461 <xsl:otherwise>
462 <xsl:call-template name="length-spec">
463 <xsl:with-param name="length" select="@depth"/>
464 </xsl:call-template>
465 </xsl:otherwise>
466 </xsl:choose>
467 </xsl:if>
468 </xsl:variable>
469
470 <xsl:variable name="html.depth">
471 <xsl:choose>
472 <xsl:when test="$ignore.image.scaling != 0"></xsl:when>
473 <xsl:when test="$depth-units = '%'">
474 <xsl:value-of select="$depth"/>
475 </xsl:when>
476 <xsl:when test="@depth and @depth != ''">
477 <xsl:variable name="depth.in.points">
478 <xsl:call-template name="length-in-points">
479 <xsl:with-param name="length" select="$depth"/>
480 <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
481 <xsl:with-param name="em.size" select="$points.per.em"/>
482 </xsl:call-template>
483 </xsl:variable>
484 <xsl:value-of select="round($depth.in.points div 72.0 * $pixels.per.inch)"/>
485 </xsl:when>
486 <xsl:otherwise></xsl:otherwise>
487 </xsl:choose>
488 </xsl:variable>
489
490 <xsl:variable name="viewport">
491 <xsl:choose>
492 <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
493 <xsl:when test="local-name(.) = 'inlinegraphic'
494 or ancestor::inlinemediaobject
495 or ancestor::inlineequation">0</xsl:when>
496 <xsl:otherwise>
497 <xsl:value-of select="$make.graphic.viewport"/>
498 </xsl:otherwise>
499 </xsl:choose>
500 </xsl:variable>
501
502 <!--
503 <xsl:message>=====================================
504 scale: <xsl:value-of select="$scale"/>, <xsl:value-of select="$scalefit"/>
505 @contentwidth <xsl:value-of select="@contentwidth"/>
506 $contentwidth <xsl:value-of select="$contentwidth"/>
507 scaled.contentwidth: <xsl:value-of select="$scaled.contentwidth"/>
508 @width: <xsl:value-of select="@width"/>
509 width: <xsl:value-of select="$width"/>
510 html.width: <xsl:value-of select="$html.width"/>
511 @contentdepth <xsl:value-of select="@contentdepth"/>
512 $contentdepth <xsl:value-of select="$contentdepth"/>
513 scaled.contentdepth: <xsl:value-of select="$scaled.contentdepth"/>
514 @depth: <xsl:value-of select="@depth"/>
515 depth: <xsl:value-of select="$depth"/>
516 html.depth: <xsl:value-of select="$html.depth"/>
517 align: <xsl:value-of select="@align"/>
518 valign: <xsl:value-of select="@valign"/></xsl:message>
519 -->
520
521 <xsl:variable name="scaled"
522 select="@width|@depth|@contentwidth|@contentdepth
523 |@scale|@scalefit"/>
524
525 <xsl:variable name="img">
526 <xsl:choose>
527 <xsl:when test="@format = 'SVG'">
528 <object data="{$output_filename}" type="image/svg+xml">
529 <xsl:call-template name="process.image.attributes">
530 <!--xsl:with-param name="alt" select="$alt"/ there's no alt here-->
531 <xsl:with-param name="html.depth" select="$html.depth"/>
532 <xsl:with-param name="html.width" select="$html.width"/>
533 <xsl:with-param name="longdesc" select="$longdesc"/>
534 <xsl:with-param name="scale" select="$scale"/>
535 <xsl:with-param name="scalefit" select="$scalefit"/>
536 <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
537 <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
538 <xsl:with-param name="viewport" select="$viewport"/>
539 </xsl:call-template>
540 <xsl:if test="@align">
541 <xsl:attribute name="align">
542 <xsl:choose>
543 <xsl:when test="@align = 'center'">middle</xsl:when>
544 <xsl:otherwise>
545 <xsl:value-of select="@align"/>
546 </xsl:otherwise>
547 </xsl:choose>
548 </xsl:attribute>
549 </xsl:if>
550 <xsl:if test="$use.embed.for.svg != 0">
551 <embed src="{$output_filename}" type="image/svg+xml">
552 <xsl:call-template name="process.image.attributes">
553 <!--xsl:with-param name="alt" select="$alt"/ there's no alt here -->
554 <xsl:with-param name="html.depth" select="$html.depth"/>
555 <xsl:with-param name="html.width" select="$html.width"/>
556 <xsl:with-param name="longdesc" select="$longdesc"/>
557 <xsl:with-param name="scale" select="$scale"/>
558 <xsl:with-param name="scalefit" select="$scalefit"/>
559 <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
560 <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
561 <xsl:with-param name="viewport" select="$viewport"/>
562 </xsl:call-template>
563 </embed>
564 </xsl:if>
565 </object>
566 </xsl:when>
567 <xsl:otherwise>
568 <xsl:element name="{$tag}">
569 <xsl:if test="$tag = 'img' and ../../self::imageobjectco">
570 <xsl:variable name="mapname">
571 <xsl:call-template name="object.id">
572 <xsl:with-param name="object" select="../../areaspec"/>
573 </xsl:call-template>
574 </xsl:variable>
575 <xsl:choose>
576 <xsl:when test="$scaled">
577 <!-- It might be possible to handle some scaling; needs -->
578 <!-- more investigation -->
579 <xsl:message>
580 <xsl:text>Warning: imagemaps not supported </xsl:text>
581 <xsl:text>on scaled images</xsl:text>
582 </xsl:message>
583 </xsl:when>
584 <xsl:otherwise>
585 <xsl:attribute name="border">0</xsl:attribute>
586 <xsl:attribute name="usemap">
587 <xsl:value-of select="concat('#', $mapname)"/>
588 </xsl:attribute>
589 </xsl:otherwise>
590 </xsl:choose>
591 </xsl:if>
592
593 <xsl:attribute name="src">
594 <xsl:choose>
595 <xsl:when test="$img.src.path != '' and
596 $tag = 'img' and
597 not(starts-with($output_filename, '/')) and
598 not(contains($output_filename, '://'))">
599 <xsl:value-of select="$img.src.path"/>
600 </xsl:when>
601 </xsl:choose>
602 <xsl:value-of select="$output_filename"/>
603 </xsl:attribute>
604
605 <xsl:if test="@align">
606 <xsl:attribute name="align">
607 <xsl:choose>
608 <xsl:when test="@align = 'center'">middle</xsl:when>
609 <xsl:otherwise>
610 <xsl:value-of select="@align"/>
611 </xsl:otherwise>
612 </xsl:choose>
613 </xsl:attribute>
614 </xsl:if>
615
616 <xsl:call-template name="process.image.attributes">
617 <xsl:with-param name="alt">
618 <xsl:choose>
619 <xsl:when test="$alt != ''">
620 <xsl:copy-of select="$alt"/>
621 </xsl:when>
622 <xsl:when test="ancestor::figure">
623 <xsl:value-of select="normalize-space(ancestor::figure/title)"/>
624 </xsl:when>
625 </xsl:choose>
626 </xsl:with-param>
627 <xsl:with-param name="html.depth" select="$html.depth"/>
628 <xsl:with-param name="html.width" select="$html.width"/>
629 <xsl:with-param name="longdesc" select="$longdesc"/>
630 <xsl:with-param name="scale" select="$scale"/>
631 <xsl:with-param name="scalefit" select="$scalefit"/>
632 <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
633 <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
634 <xsl:with-param name="viewport" select="$viewport"/>
635 </xsl:call-template>
636 </xsl:element>
637 </xsl:otherwise>
638 </xsl:choose>
639 </xsl:variable>
640
641 <xsl:variable name="bgcolor">
642 <xsl:call-template name="pi.dbhtml_background-color">
643 <xsl:with-param name="node" select=".."/>
644 </xsl:call-template>
645 </xsl:variable>
646
647 <xsl:variable name="use.viewport"
648 select="$viewport != 0
649 and ($html.width != ''
650 or ($html.depth != '' and $depth-units != '%')
651 or $bgcolor != ''
652 or @valign)"/>
653
654 <xsl:choose>
655 <xsl:when test="$use.viewport">
656 <table border="0" summary="manufactured viewport for HTML img"
657 cellspacing="0" cellpadding="0">
658 <xsl:if test="$html.width != ''">
659 <xsl:attribute name="width">
660 <xsl:value-of select="$html.width"/>
661 </xsl:attribute>
662 </xsl:if>
663 <tr>
664 <xsl:if test="$html.depth != '' and $depth-units != '%'">
665 <!-- don't do this for percentages because browsers get confused -->
666 <xsl:choose>
667 <xsl:when test="$css.decoration != 0">
668 <xsl:attribute name="style">
669 <xsl:text>height: </xsl:text>
670 <xsl:value-of select="$html.depth"/>
671 <xsl:text>px</xsl:text>
672 </xsl:attribute>
673 </xsl:when>
674 <xsl:otherwise>
675 <xsl:attribute name="height">
676 <xsl:value-of select="$html.depth"/>
677 </xsl:attribute>
678 </xsl:otherwise>
679 </xsl:choose>
680 </xsl:if>
681 <td>
682 <xsl:if test="$bgcolor != ''">
683 <xsl:choose>
684 <xsl:when test="$css.decoration != 0">
685 <xsl:attribute name="style">
686 <xsl:text>background-color: </xsl:text>
687 <xsl:value-of select="$bgcolor"/>
688 </xsl:attribute>
689 </xsl:when>
690 <xsl:otherwise>
691 <xsl:attribute name="bgcolor">
692 <xsl:value-of select="$bgcolor"/>
693 </xsl:attribute>
694 </xsl:otherwise>
695 </xsl:choose>
696 </xsl:if>
697 <xsl:if test="@align">
698 <xsl:attribute name="align">
699 <xsl:value-of select="@align"/>
700 </xsl:attribute>
701 </xsl:if>
702 <xsl:if test="@valign">
703 <xsl:attribute name="valign">
704 <xsl:value-of select="@valign"/>
705 </xsl:attribute>
706 </xsl:if>
707 <xsl:copy-of select="$img"/>
708 </td>
709 </tr>
710 </table>
711 </xsl:when>
712 <xsl:otherwise>
713 <xsl:copy-of select="$img"/>
714 </xsl:otherwise>
715 </xsl:choose>
716
717 <xsl:if test="$tag = 'img' and ../../self::imageobjectco and not($scaled)">
718 <xsl:variable name="mapname">
719 <xsl:call-template name="object.id">
720 <xsl:with-param name="object" select="../../areaspec"/>
721 </xsl:call-template>
722 </xsl:variable>
723
724 <map name="{$mapname}">
725 <xsl:for-each select="../../areaspec//area">
726 <xsl:variable name="units">
727 <xsl:choose>
728 <xsl:when test="@units = 'other' and @otherunits">
729 <xsl:value-of select="@otherunits"/>
730 </xsl:when>
731 <xsl:when test="@units">
732 <xsl:value-of select="@units"/>
733 </xsl:when>
734 <!-- areaspec|areaset/area -->
735 <xsl:when test="../@units = 'other' and ../@otherunits">
736 <xsl:value-of select="../@otherunits"/>
737 </xsl:when>
738 <xsl:when test="../@units">
739 <xsl:value-of select="../@units"/>
740 </xsl:when>
741 <!-- areaspec/areaset/area -->
742 <xsl:when test="../../@units = 'other' and ../../@otherunits">
743 <xsl:value-of select="../@otherunits"/>
744 </xsl:when>
745 <xsl:when test="../../@units">
746 <xsl:value-of select="../../@units"/>
747 </xsl:when>
748 <xsl:otherwise>calspair</xsl:otherwise>
749 </xsl:choose>
750 </xsl:variable>
751
752 <xsl:choose>
753 <xsl:when test="$units = 'calspair' or
754 $units = 'imagemap'">
755 <xsl:variable name="coords" select="normalize-space(@coords)"/>
756
757 <area shape="rect">
758 <xsl:variable name="linkends">
759 <xsl:choose>
760 <xsl:when test="@linkends">
761 <xsl:value-of select="normalize-space(@linkends)"/>
762 </xsl:when>
763 <xsl:otherwise>
764 <xsl:value-of select="normalize-space(../@linkends)"/>
765 </xsl:otherwise>
766 </xsl:choose>
767 </xsl:variable>
768
769 <xsl:variable name="href">
770 <xsl:choose>
771 <xsl:when test="@xlink:href">
772 <xsl:value-of select="@xlink:href"/>
773 </xsl:when>
774 <xsl:otherwise>
775 <xsl:value-of select="../@xlink:href"/>
776 </xsl:otherwise>
777 </xsl:choose>
778 </xsl:variable>
779
780 <xsl:choose>
781 <xsl:when test="$linkends != ''">
782 <xsl:variable name="linkend">
783 <xsl:choose>
784 <xsl:when test="contains($linkends, ' ')">
785 <xsl:value-of select="substring-before($linkends, ' ')"/>
786 </xsl:when>
787 <xsl:otherwise>
788 <xsl:value-of select="$linkends"/>
789 </xsl:otherwise>
790 </xsl:choose>
791 </xsl:variable>
792
793 <xsl:variable name="target" select="key('id', $linkend)[1]"/>
794
795 <xsl:if test="$target">
796 <xsl:attribute name="href">
797 <xsl:call-template name="href.target">
798 <xsl:with-param name="object" select="$target"/>
799 </xsl:call-template>
800 </xsl:attribute>
801 </xsl:if>
802 </xsl:when>
803 <xsl:when test="$href != ''">
804 <xsl:attribute name="href">
805 <xsl:value-of select="$href"/>
806 </xsl:attribute>
807 </xsl:when>
808 </xsl:choose>
809
810 <xsl:if test="alt">
811 <xsl:attribute name="alt">
812 <xsl:value-of select="alt[1]"/>
813 </xsl:attribute>
814 </xsl:if>
815
816 <xsl:attribute name="coords">
817 <xsl:choose>
818 <xsl:when test="$units = 'calspair'">
819
820 <xsl:variable name="p1"
821 select="substring-before($coords, ' ')"/>
822 <xsl:variable name="p2"
823 select="substring-after($coords, ' ')"/>
824
825 <xsl:variable name="x1" select="substring-before($p1,',')"/>
826 <xsl:variable name="y1" select="substring-after($p1,',')"/>
827 <xsl:variable name="x2" select="substring-before($p2,',')"/>
828 <xsl:variable name="y2" select="substring-after($p2,',')"/>
829
830 <xsl:variable name="x1p" select="$x1 div 100.0"/>
831 <xsl:variable name="y1p" select="$y1 div 100.0"/>
832 <xsl:variable name="x2p" select="$x2 div 100.0"/>
833 <xsl:variable name="y2p" select="$y2 div 100.0"/>
834
835 <!--
836 <xsl:message>
837 <xsl:text>units: </xsl:text>
838 <xsl:value-of select="$units"/>
839 <xsl:text> </xsl:text>
840 <xsl:value-of select="$x1p"/><xsl:text>, </xsl:text>
841 <xsl:value-of select="$y1p"/><xsl:text>, </xsl:text>
842 <xsl:value-of select="$x2p"/><xsl:text>, </xsl:text>
843 <xsl:value-of select="$y2p"/><xsl:text>, </xsl:text>
844 </xsl:message>
845
846 <xsl:message>
847 <xsl:text> </xsl:text>
848 <xsl:value-of select="$intrinsicwidth"/>
849 <xsl:text>, </xsl:text>
850 <xsl:value-of select="$intrinsicdepth"/>
851 </xsl:message>
852
853 <xsl:message>
854 <xsl:text> </xsl:text>
855 <xsl:value-of select="$units"/>
856 <xsl:text> </xsl:text>
857 <xsl:value-of
858 select="round($x1p * $intrinsicwidth div 100.0)"/>
859 <xsl:text>,</xsl:text>
860 <xsl:value-of select="round($intrinsicdepth
861 - ($y2p * $intrinsicdepth div 100.0))"/>
862 <xsl:text>,</xsl:text>
863 <xsl:value-of select="round($x2p *
864 $intrinsicwidth div 100.0)"/>
865 <xsl:text>,</xsl:text>
866 <xsl:value-of select="round($intrinsicdepth
867 - ($y1p * $intrinsicdepth div 100.0))"/>
868 </xsl:message>
869 -->
870 <xsl:value-of
871 select="round($x1p * $intrinsicwidth div 100.0)"/>
872 <xsl:text>,</xsl:text>
873 <xsl:value-of select="round($intrinsicdepth
874 - ($y2p * $intrinsicdepth div 100.0))"/>
875 <xsl:text>,</xsl:text>
876 <xsl:value-of
877 select="round($x2p * $intrinsicwidth div 100.0)"/>
878 <xsl:text>,</xsl:text>
879 <xsl:value-of select="round($intrinsicdepth
880 - ($y1p * $intrinsicdepth div 100.0))"/>
881 </xsl:when>
882 <xsl:otherwise>
883 <xsl:copy-of select="$coords"/>
884 </xsl:otherwise>
885 </xsl:choose>
886 </xsl:attribute>
887 </area>
888 </xsl:when>
889 <xsl:otherwise>
890 <xsl:message>
891 <xsl:text>Warning: only calspair or </xsl:text>
892 <xsl:text>otherunits='imagemap' supported </xsl:text>
893 <xsl:text>in imageobjectco</xsl:text>
894 </xsl:message>
895 </xsl:otherwise>
896 </xsl:choose>
897 </xsl:for-each>
898 </map>
899 </xsl:if>
900 </xsl:template>
901
902 <xsl:template name="process.image.attributes">
903 <xsl:param name="alt"/>
904 <xsl:param name="html.width"/>
905 <xsl:param name="html.depth"/>
906 <xsl:param name="longdesc"/>
907 <xsl:param name="scale"/>
908 <xsl:param name="scalefit"/>
909 <xsl:param name="scaled.contentdepth"/>
910 <xsl:param name="scaled.contentwidth"/>
911 <xsl:param name="viewport"/>
912
913 <xsl:choose>
914 <xsl:when test="@contentwidth or @contentdepth">
915 <!-- ignore @width/@depth, @scale, and @scalefit if specified -->
916 <xsl:if test="@contentwidth and $scaled.contentwidth != ''">
917 <xsl:attribute name="width">
918 <xsl:value-of select="$scaled.contentwidth"/>
919 </xsl:attribute>
920 </xsl:if>
921 <xsl:if test="@contentdepth and $scaled.contentdepth != ''">
922 <xsl:attribute name="height">
923 <xsl:value-of select="$scaled.contentdepth"/>
924 </xsl:attribute>
925 </xsl:if>
926 </xsl:when>
927
928 <xsl:when test="number($scale) != 1.0">
929 <!-- scaling is always uniform, so we only have to specify one dimension -->
930 <!-- ignore @scalefit if specified -->
931 <xsl:attribute name="width">
932 <xsl:value-of select="$scaled.contentwidth"/>
933 </xsl:attribute>
934 </xsl:when>
935
936 <xsl:when test="$scalefit != 0">
937 <xsl:choose>
938 <xsl:when test="contains($html.width, '%')">
939 <xsl:choose>
940 <xsl:when test="$viewport != 0">
941 <!-- The *viewport* will be scaled, so use 100% here! -->
942 <xsl:attribute name="width">
943 <xsl:value-of select="'100%'"/>
944 </xsl:attribute>
945 </xsl:when>
946 <xsl:otherwise>
947 <xsl:attribute name="width">
948 <xsl:value-of select="$html.width"/>
949 </xsl:attribute>
950 </xsl:otherwise>
951 </xsl:choose>
952 </xsl:when>
953
954 <xsl:when test="contains($html.depth, '%')">
955 <!-- HTML doesn't deal with this case very well...do nothing -->
956 </xsl:when>
957
958 <xsl:when test="$scaled.contentwidth != '' and $html.width != ''
959 and $scaled.contentdepth != '' and $html.depth != ''">
960 <!-- scalefit should not be anamorphic; figure out which direction -->
961 <!-- has the limiting scale factor and scale in that direction -->
962 <xsl:choose>
963 <xsl:when test="$html.width div $scaled.contentwidth &gt;
964 $html.depth div $scaled.contentdepth">
965 <xsl:attribute name="height">
966 <xsl:value-of select="$html.depth"/>
967 </xsl:attribute>
968 </xsl:when>
969 <xsl:otherwise>
970 <xsl:attribute name="width">
971 <xsl:value-of select="$html.width"/>
972 </xsl:attribute>
973 </xsl:otherwise>
974 </xsl:choose>
975 </xsl:when>
976
977 <xsl:when test="$scaled.contentwidth != '' and $html.width != ''">
978 <xsl:attribute name="width">
979 <xsl:value-of select="$html.width"/>
980 </xsl:attribute>
981 </xsl:when>
982
983 <xsl:when test="$scaled.contentdepth != '' and $html.depth != ''">
984 <xsl:attribute name="height">
985 <xsl:value-of select="$html.depth"/>
986 </xsl:attribute>
987 </xsl:when>
988 </xsl:choose>
989 </xsl:when>
990 </xsl:choose>
991
992 <xsl:if test="$alt != ''">
993 <xsl:attribute name="alt">
994 <xsl:value-of select="normalize-space($alt)"/>
995 </xsl:attribute>
996 </xsl:if>
997
998 <xsl:if test="$longdesc != ''">
999 <xsl:attribute name="longdesc">
1000 <xsl:value-of select="$longdesc"/>
1001 </xsl:attribute>
1002 </xsl:if>
1003
1004 <xsl:if test="@align and $viewport = 0">
1005 <xsl:attribute name="align">
1006 <xsl:choose>
1007 <xsl:when test="@align = 'center'">middle</xsl:when>
1008 <xsl:otherwise>
1009 <xsl:value-of select="@align"/>
1010 </xsl:otherwise>
1011 </xsl:choose>
1012 </xsl:attribute>
1013 </xsl:if>
1014 </xsl:template>
1015
1016 <!-- ==================================================================== -->
1017
1018 <xsl:template match="graphic">
1019 <xsl:choose>
1020 <xsl:when test="parent::inlineequation">
1021 <xsl:call-template name="anchor"/>
1022 <xsl:call-template name="process.image"/>
1023 </xsl:when>
1024 <xsl:otherwise>
1025 <div>
1026 <xsl:if test="@align">
1027 <xsl:attribute name="align">
1028 <xsl:value-of select="@align"/>
1029 </xsl:attribute>
1030 </xsl:if>
1031 <xsl:call-template name="anchor"/>
1032 <xsl:call-template name="process.image"/>
1033 </div>
1034 </xsl:otherwise>
1035 </xsl:choose>
1036 </xsl:template>
1037
1038 <xsl:template match="inlinegraphic">
1039 <xsl:variable name="filename">
1040 <xsl:choose>
1041 <xsl:when test="@entityref">
1042 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1043 </xsl:when>
1044 <xsl:otherwise>
1045 <xsl:apply-templates select="@fileref"/>
1046 </xsl:otherwise>
1047 </xsl:choose>
1048 </xsl:variable>
1049
1050 <xsl:call-template name="anchor"/>
1051
1052 <xsl:choose>
1053 <xsl:when test="@format='linespecific'">
1054 <xsl:choose>
1055 <xsl:when test="$use.extensions != '0'
1056 and $textinsert.extension != '0'">
1057 <xsl:choose>
1058 <xsl:when test="element-available('stext:insertfile')">
1059 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
1060 </xsl:when>
1061 <xsl:when test="element-available('xtext:insertfile')">
1062 <xtext:insertfile href="{$filename}"/>
1063 </xsl:when>
1064 <xsl:otherwise>
1065 <xsl:message terminate="yes">
1066 <xsl:text>No insertfile extension available.</xsl:text>
1067 </xsl:message>
1068 </xsl:otherwise>
1069 </xsl:choose>
1070 </xsl:when>
1071 <xsl:otherwise>
1072 <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
1073 href="{$filename}"/>
1074 </xsl:otherwise>
1075 </xsl:choose>
1076 </xsl:when>
1077 <xsl:otherwise>
1078 <xsl:call-template name="process.image"/>
1079 </xsl:otherwise>
1080 </xsl:choose>
1081 </xsl:template>
1082
1083 <!-- ==================================================================== -->
1084
1085 <xsl:template match="mediaobject|mediaobjectco">
1086
1087 <xsl:variable name="olist" select="imageobject|imageobjectco
1088 |videoobject|audioobject
1089 |textobject"/>
1090
1091 <xsl:variable name="object.index">
1092 <xsl:call-template name="select.mediaobject.index">
1093 <xsl:with-param name="olist" select="$olist"/>
1094 <xsl:with-param name="count" select="1"/>
1095 </xsl:call-template>
1096 </xsl:variable>
1097
1098 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
1099
1100 <xsl:variable name="align">
1101 <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
1102 </xsl:variable>
1103
1104 <div>
1105 <xsl:apply-templates select="." mode="class.attribute"/>
1106 <xsl:if test="$align != '' ">
1107 <xsl:attribute name="align">
1108 <xsl:value-of select="$align"/>
1109 </xsl:attribute>
1110 </xsl:if>
1111 <xsl:call-template name="anchor"/>
1112
1113 <xsl:apply-templates select="$object"/>
1114 <xsl:apply-templates select="caption"/>
1115 </div>
1116 </xsl:template>
1117
1118 <xsl:template match="inlinemediaobject">
1119 <span>
1120 <xsl:apply-templates select="." mode="class.attribute"/>
1121 <xsl:call-template name="anchor"/>
1122 <xsl:call-template name="select.mediaobject"/>
1123 </span>
1124 </xsl:template>
1125
1126 <xsl:template match="programlisting/inlinemediaobject
1127 |screen/inlinemediaobject" priority="2">
1128 <!-- the additional span causes problems in some cases -->
1129 <xsl:call-template name="select.mediaobject"/>
1130 </xsl:template>
1131
1132 <!-- ==================================================================== -->
1133
1134 <xsl:template match="imageobjectco">
1135 <xsl:call-template name="anchor"/>
1136 <xsl:apply-templates select="imageobject"/>
1137 <xsl:apply-templates select="calloutlist"/>
1138 </xsl:template>
1139
1140 <xsl:template match="imageobject">
1141 <xsl:apply-templates select="imagedata"/>
1142 </xsl:template>
1143
1144 <xsl:template match="imagedata">
1145 <xsl:variable name="filename">
1146 <xsl:call-template name="mediaobject.filename">
1147 <xsl:with-param name="object" select=".."/>
1148 </xsl:call-template>
1149 </xsl:variable>
1150
1151 <xsl:choose>
1152 <!-- Handle MathML and SVG markup in imagedata -->
1153 <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
1154 <xsl:apply-templates/>
1155 </xsl:when>
1156
1157 <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
1158 <xsl:apply-templates/>
1159 </xsl:when>
1160
1161 <xsl:when test="@format='linespecific'">
1162 <xsl:choose>
1163 <xsl:when test="$use.extensions != '0'
1164 and $textinsert.extension != '0'">
1165 <xsl:choose>
1166 <xsl:when test="element-available('stext:insertfile')">
1167 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
1168 </xsl:when>
1169 <xsl:when test="element-available('xtext:insertfile')">
1170 <xtext:insertfile href="{$filename}"/>
1171 </xsl:when>
1172 <xsl:otherwise>
1173 <xsl:message terminate="yes">
1174 <xsl:text>No insertfile extension available.</xsl:text>
1175 </xsl:message>
1176 </xsl:otherwise>
1177 </xsl:choose>
1178 </xsl:when>
1179 <xsl:otherwise>
1180 <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
1181 href="{$filename}"/>
1182 </xsl:otherwise>
1183 </xsl:choose>
1184 </xsl:when>
1185 <xsl:otherwise>
1186 <xsl:variable name="longdesc.uri">
1187 <xsl:call-template name="longdesc.uri">
1188 <xsl:with-param name="mediaobject"
1189 select="ancestor::imageobject/parent::*"/>
1190 </xsl:call-template>
1191 </xsl:variable>
1192
1193 <xsl:variable name="phrases"
1194 select="ancestor::mediaobject/textobject[phrase]
1195 |ancestor::inlinemediaobject/textobject[phrase]
1196 |ancestor::mediaobjectco/textobject[phrase]"/>
1197
1198 <xsl:call-template name="process.image">
1199 <xsl:with-param name="alt">
1200 <xsl:apply-templates select="$phrases[not(@role) or @role!='tex'][1]"/>
1201 </xsl:with-param>
1202 <xsl:with-param name="longdesc">
1203 <xsl:call-template name="write.longdesc">
1204 <xsl:with-param name="mediaobject"
1205 select="ancestor::imageobject/parent::*"/>
1206 </xsl:call-template>
1207 </xsl:with-param>
1208 </xsl:call-template>
1209
1210 <xsl:if test="$html.longdesc != 0 and $html.longdesc.link != 0
1211 and ancestor::imageobject/parent::*/textobject[not(phrase)]">
1212 <xsl:call-template name="longdesc.link">
1213 <xsl:with-param name="longdesc.uri" select="$longdesc.uri"/>
1214 </xsl:call-template>
1215 </xsl:if>
1216 </xsl:otherwise>
1217 </xsl:choose>
1218 </xsl:template>
1219
1220 <!-- ==================================================================== -->
1221
1222 <xsl:template name="longdesc.uri">
1223 <xsl:param name="mediaobject" select="."/>
1224 <xsl:if test="$html.longdesc">
1225 <xsl:if test="$mediaobject/textobject[not(phrase)]">
1226 <xsl:variable name="dbhtml.dir">
1227 <xsl:call-template name="dbhtml-dir"/>
1228 </xsl:variable>
1229 <xsl:variable name="filename">
1230 <xsl:call-template name="make-relative-filename">
1231 <xsl:with-param name="base.dir">
1232 <xsl:choose>
1233 <xsl:when test="$dbhtml.dir != ''">
1234 <xsl:value-of select="$dbhtml.dir"/>
1235 </xsl:when>
1236 <xsl:otherwise>
1237 <xsl:value-of select="$base.dir"/>
1238 </xsl:otherwise>
1239 </xsl:choose>
1240 </xsl:with-param>
1241 <xsl:with-param name="base.name">
1242 <xsl:choose>
1243 <xsl:when test="
1244 $mediaobject/@*[local-name() = 'id']
1245 and not($use.id.as.filename = 0)">
1246 <!-- * if this mediaobject has an ID, then we use the -->
1247 <!-- * value of that ID as basename for the "longdesc" -->
1248 <!-- * file (that is, without prepending an "ld-" too it) -->
1249 <xsl:value-of select="$mediaobject/@*[local-name() = 'id']"/>
1250 <xsl:value-of select="$html.ext"/>
1251 </xsl:when>
1252 <xsl:otherwise>
1253 <!-- * otherwise, if this mediaobject does not have an -->
1254 <!-- * ID, then we generate an ID... -->
1255 <xsl:variable name="image-id">
1256 <xsl:call-template name="object.id">
1257 <xsl:with-param name="object" select="$mediaobject"/>
1258 </xsl:call-template>
1259 </xsl:variable>
1260 <!-- * ...and then we take that generated ID, prepend an -->
1261 <!-- * "ld-" to it, and use that as the basename for the file -->
1262 <xsl:value-of select="concat('ld-',$image-id,$html.ext)"/>
1263 </xsl:otherwise>
1264 </xsl:choose>
1265 </xsl:with-param>
1266 </xsl:call-template>
1267 </xsl:variable>
1268
1269 <xsl:value-of select="$filename"/>
1270 </xsl:if>
1271 </xsl:if>
1272 </xsl:template>
1273
1274 <xsl:template name="write.longdesc">
1275 <xsl:param name="mediaobject" select="."/>
1276 <xsl:if test="$html.longdesc != 0 and $mediaobject/textobject[not(phrase)]">
1277 <xsl:variable name="filename">
1278 <xsl:call-template name="longdesc.uri">
1279 <xsl:with-param name="mediaobject" select="$mediaobject"/>
1280 </xsl:call-template>
1281 </xsl:variable>
1282
1283 <xsl:value-of select="$filename"/>
1284
1285 <xsl:call-template name="write.chunk">
1286 <xsl:with-param name="filename" select="$filename"/>
1287 <xsl:with-param name="quiet" select="$chunk.quietly"/>
1288 <xsl:with-param name="content">
1289 <xsl:call-template name="user.preroot"/>
1290 <html>
1291 <head>
1292 <xsl:call-template name="system.head.content"/>
1293 <xsl:call-template name="head.content">
1294 <xsl:with-param name="title" select="'Long Description'"/>
1295 </xsl:call-template>
1296 <xsl:call-template name="user.head.content"/>
1297 </head>
1298 <body>
1299 <xsl:call-template name="body.attributes"/>
1300 <xsl:for-each select="$mediaobject/textobject[not(phrase)]">
1301 <xsl:apply-templates select="./*"/>
1302 </xsl:for-each>
1303 </body>
1304 </html>
1305 <xsl:value-of select="$chunk.append"/>
1306 </xsl:with-param>
1307 </xsl:call-template>
1308 </xsl:if>
1309 </xsl:template>
1310
1311 <xsl:template name="longdesc.link">
1312 <xsl:param name="longdesc.uri" select="''"/>
1313
1314 <xsl:variable name="this.uri">
1315 <xsl:call-template name="make-relative-filename">
1316 <xsl:with-param name="base.dir" select="$base.dir"/>
1317 <xsl:with-param name="base.name">
1318 <xsl:call-template name="href.target.uri"/>
1319 </xsl:with-param>
1320 </xsl:call-template>
1321 </xsl:variable>
1322
1323 <xsl:variable name="href.to">
1324 <xsl:call-template name="trim.common.uri.paths">
1325 <xsl:with-param name="uriA" select="$longdesc.uri"/>
1326 <xsl:with-param name="uriB" select="$this.uri"/>
1327 <xsl:with-param name="return" select="'A'"/>
1328 </xsl:call-template>
1329 </xsl:variable>
1330
1331 <div class="longdesc-link" align="right">
1332 <br clear="all"/>
1333 <span class="longdesc-link">
1334 <xsl:text>[</xsl:text>
1335 <a href="{$href.to}" target="longdesc">D</a>
1336 <xsl:text>]</xsl:text>
1337 </span>
1338 </div>
1339 </xsl:template>
1340
1341 <!-- ==================================================================== -->
1342
1343 <xsl:template match="videoobject">
1344 <xsl:apply-templates select="videodata"/>
1345 </xsl:template>
1346
1347 <xsl:template match="videodata">
1348 <xsl:call-template name="process.image">
1349 <xsl:with-param name="tag" select="'embed'"/>
1350 <xsl:with-param name="alt">
1351 <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
1352 </xsl:with-param>
1353 </xsl:call-template>
1354 </xsl:template>
1355
1356 <!-- ==================================================================== -->
1357
1358 <xsl:template match="audioobject">
1359 <xsl:apply-templates select="audiodata"/>
1360 </xsl:template>
1361
1362 <xsl:template match="audiodata">
1363 <xsl:call-template name="process.image">
1364 <xsl:with-param name="tag" select="'embed'"/>
1365 <xsl:with-param name="alt">
1366 <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
1367 </xsl:with-param>
1368 </xsl:call-template>
1369 </xsl:template>
1370
1371 <!-- ==================================================================== -->
1372
1373 <xsl:template match="textobject">
1374 <xsl:apply-templates/>
1375 </xsl:template>
1376
1377 <xsl:template match="textdata">
1378 <xsl:variable name="filename">
1379 <xsl:choose>
1380 <xsl:when test="@entityref">
1381 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1382 </xsl:when>
1383 <xsl:otherwise>
1384 <xsl:apply-templates select="@fileref"/>
1385 </xsl:otherwise>
1386 </xsl:choose>
1387 </xsl:variable>
1388
1389 <xsl:variable name="encoding">
1390 <xsl:choose>
1391 <xsl:when test="@encoding">
1392 <xsl:value-of select="@encoding"/>
1393 </xsl:when>
1394 <xsl:otherwise>
1395 <xsl:value-of select="$textdata.default.encoding"/>
1396 </xsl:otherwise>
1397 </xsl:choose>
1398 </xsl:variable>
1399
1400 <xsl:choose>
1401 <xsl:when test="$use.extensions != '0'
1402 and $textinsert.extension != '0'">
1403 <xsl:choose>
1404 <xsl:when test="element-available('stext:insertfile')">
1405 <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
1406 </xsl:when>
1407 <xsl:when test="element-available('xtext:insertfile')">
1408 <xtext:insertfile href="{$filename}"/>
1409 </xsl:when>
1410 <xsl:otherwise>
1411 <xsl:message terminate="yes">
1412 <xsl:text>No insertfile extension available.</xsl:text>
1413 </xsl:message>
1414 </xsl:otherwise>
1415 </xsl:choose>
1416 </xsl:when>
1417 <xsl:otherwise>
1418 <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
1419 href="{$filename}"/>
1420 </xsl:otherwise>
1421 </xsl:choose>
1422 </xsl:template>
1423
1424 <!-- ==================================================================== -->
1425
1426 <xsl:template match="caption">
1427 <div>
1428 <xsl:apply-templates select="." mode="class.attribute"/>
1429 <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
1430 <xsl:attribute name="align"><xsl:value-of
1431 select="@align"/></xsl:attribute>
1432 </xsl:if>
1433 <xsl:apply-templates/>
1434 </div>
1435 </xsl:template>
1436
1437 <!-- ==================================================================== -->
1438 <!-- "Support" for SVG -->
1439
1440 <xsl:template match="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
1441 <xsl:copy>
1442 <xsl:copy-of select="@*"/>
1443 <xsl:apply-templates/>
1444 </xsl:copy>
1445 </xsl:template>
1446
1447
1448 <!-- The following works sometimes, but needs to take into account
1449 1. When there is no /*/@xml:base
1450 2. When the chunks are going somewhere else
1451 <xsl:variable name="relpath">
1452 <xsl:call-template name="relative-uri">
1453 <xsl:with-param name="filename" select="@fileref"/>
1454 </xsl:call-template>
1455 </xsl:variable>
1456
1457 <xsl:choose>
1458 <xsl:when test="/*/@xml:base
1459 and starts-with($relpath,/*/@xml:base)">
1460 <xsl:value-of select="substring-after($relpath,/*/@xml:base)"/>
1461 </xsl:when>
1462 <xsl:otherwise>
1463 <xsl:value-of select="@fileref"/>
1464 </xsl:otherwise>
1465 </xsl:choose>
1466 <xsl:value-of select="@fileref"/>
1467 </xsl:when>
1468 -->
1469 <!-- Resolve xml:base attributes -->
1470 <xsl:template match="@fileref">
1471 <!-- need a check for absolute urls -->
1472 <xsl:choose>
1473 <xsl:when test="contains(., ':')">
1474 <!-- it has a uri scheme so it is an absolute uri -->
1475 <xsl:value-of select="."/>
1476 </xsl:when>
1477 <xsl:when test="$keep.relative.image.uris != 0">
1478 <!-- leave it alone -->
1479 <xsl:value-of select="."/>
1480 </xsl:when>
1481 <xsl:otherwise>
1482 <!-- its a relative uri that needs xml:base processing -->
1483 <xsl:call-template name="relative-uri">
1484 </xsl:call-template>
1485 </xsl:otherwise>
1486 </xsl:choose>
1487 </xsl:template>
1488
1489 </xsl:stylesheet>