source: clfs-embedded/BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/xhtml/graphics.xsl @ 00b1e11

Last change on this file since 00b1e11 was 00b1e11, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Merged r8226 from new-xsl branch.

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