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