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