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