Imported Upstream version 1.79.0
[platform/upstream/docbook-xsl-stylesheets.git] / fo / graphics.xsl
1 <?xml version='1.0'?>
2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
4 <!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
5  ]>
6 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
8                 xmlns:xlink="http://www.w3.org/1999/xlink"
9                 xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
10                 xmlns:xtext="com.nwalsh.xalan.Text"
11                 xmlns:lxslt="http://xml.apache.org/xslt"
12                 exclude-result-prefixes="xlink stext xtext lxslt"
13                 extension-element-prefixes="stext xtext"
14                 version='1.0'>
15
16 <!-- ********************************************************************
17      $Id: graphics.xsl 9941 2014-09-06 16:35:04Z bobstayton $
18      ********************************************************************
19
20      This file is part of the XSL DocBook Stylesheet distribution.
21      See ../README or http://docbook.sf.net/release/xsl/current/ for
22      copyright and other information.
23
24      Contributors:
25      Colin Paul Adams, <colin@colina.demon.co.uk>
26      Paul Grosso, <pgrosso@arbortext.com>
27
28      ******************************************************************** -->
29
30 <!-- ==================================================================== -->
31 <!-- Graphic format tests for the FO backend -->
32
33 <xsl:param name="graphic.notations">
34   <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
35   <xsl:choose>
36     <xsl:when test="$fop1.extensions != 0">
37       <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
38     </xsl:when>
39     <xsl:when test="$fop.extensions != 0">
40       <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
41     </xsl:when>
42     <xsl:when test="$arbortext.extensions != 0">
43       <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
44     </xsl:when>
45     <xsl:when test="$xep.extensions != 0">
46       <xsl:text> SVG PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
47     </xsl:when>
48     <xsl:otherwise>
49       <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
50     </xsl:otherwise>
51   </xsl:choose>
52 </xsl:param>
53
54 <xsl:template name="is.graphic.format">
55   <xsl:param name="format"/>
56   <xsl:if test="contains($graphic.notations, concat(' ',$format,' '))">1</xsl:if>
57 </xsl:template>
58
59 <xsl:param name="graphic.extensions">
60   <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
61   <xsl:choose>
62     <xsl:when test="$fop1.extensions != 0">
63       <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
64     </xsl:when>
65     <xsl:when test="$fop.extensions != 0">
66       <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
67     </xsl:when>
68     <xsl:when test="$arbortext.extensions != 0">
69       <xsl:text> png pdf jpg jpeg gif tif tiff bmp </xsl:text>
70     </xsl:when>
71     <xsl:when test="$xep.extensions != 0">
72       <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
73     </xsl:when>
74     <xsl:otherwise>
75       <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
76     </xsl:otherwise>
77   </xsl:choose>
78 </xsl:param>
79
80 <xsl:template name="is.graphic.extension">
81   <xsl:param name="ext"/>
82   <xsl:variable name="lcext" select="translate($ext,
83                                        'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
84                                        'abcdefghijklmnopqrstuvwxyz')"/>
85
86   <xsl:if test="contains($graphic.extensions,
87                          concat(' ', $lcext, ' '))">1</xsl:if>
88 </xsl:template>
89
90
91 <!-- ==================================================================== -->
92
93 <xsl:template match="screenshot">
94   <fo:block>
95     <xsl:call-template name="anchor"/>
96     <xsl:apply-templates/>
97   </fo:block>
98 </xsl:template>
99
100 <xsl:template match="screenshot/title">
101   <xsl:call-template name="formal.object.heading">
102     <xsl:with-param name="object" select=".."/>
103   </xsl:call-template>
104 </xsl:template>
105
106 <xsl:template match="screeninfo">
107 </xsl:template>
108
109 <!-- ==================================================================== -->
110 <!-- Override these templates for FO -->
111 <!-- ==================================================================== -->
112
113 <xsl:template name="image.scalefit">
114   <xsl:choose>
115     <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
116     <xsl:when test="@contentwidth">0</xsl:when>
117     <xsl:when test="@contentdepth and 
118                     @contentdepth != '100%'">0</xsl:when>
119     <xsl:when test="@scale">0</xsl:when>
120     <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
121     <xsl:when test="@width or @depth">1</xsl:when>
122     <xsl:when test="$default.image.width != ''">1</xsl:when>
123     <xsl:otherwise>0</xsl:otherwise>
124   </xsl:choose>
125 </xsl:template>
126
127 <xsl:template name="image.scale">
128   <xsl:choose>
129     <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
130     <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
131     <xsl:when test="@scale">
132       <xsl:value-of select="@scale div 100.0"/>
133     </xsl:when>
134     <xsl:otherwise>1.0</xsl:otherwise>
135   </xsl:choose>
136 </xsl:template>
137
138 <xsl:template name="image.filename">
139   <xsl:choose>
140     <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
141       <!-- no filename for inline SVG content -->
142     </xsl:when>
143     <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
144       <!-- no filename for inline MathML content -->
145     </xsl:when>
146     <xsl:when test="local-name(.) = 'graphic'
147                     or local-name(.) = 'inlinegraphic'">
148       <!-- handle legacy graphic and inlinegraphic by new template --> 
149       <xsl:call-template name="mediaobject.filename">
150         <xsl:with-param name="object" select="."/>
151       </xsl:call-template>
152     </xsl:when>
153     <xsl:otherwise>
154       <!-- imagedata, videodata, audiodata -->
155       <xsl:call-template name="mediaobject.filename">
156         <xsl:with-param name="object" select=".."/>
157       </xsl:call-template>
158     </xsl:otherwise>
159   </xsl:choose>
160 </xsl:template>
161
162 <xsl:template name="image.src">
163   <xsl:param name="filename"/>
164
165   <xsl:choose>
166     <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
167       <!-- no src attribute for inline SVG content -->
168     </xsl:when>
169     <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
170       <!-- no src attribute for inline MathML content -->
171     </xsl:when>
172     <xsl:otherwise>
173       <xsl:call-template name="fo-external-image">
174         <xsl:with-param name="filename">
175           <xsl:if test="$img.src.path != '' and
176                         not(starts-with($filename, '/')) and
177                         not(starts-with($filename, 'file:/')) and
178                         not(contains($filename, '://'))">
179             <xsl:value-of select="$img.src.path"/>
180           </xsl:if>
181           <xsl:value-of select="$filename"/>
182         </xsl:with-param>
183       </xsl:call-template>
184     </xsl:otherwise>
185   </xsl:choose>
186 </xsl:template>
187
188 <xsl:template name="image.content.type">
189   <xsl:if test="@format">
190     <xsl:call-template name="graphic.format.content-type">
191       <xsl:with-param name="format" select="@format"/>
192     </xsl:call-template>
193   </xsl:if>
194 </xsl:template>
195
196 <xsl:template name="image.bgcolor">
197   <xsl:call-template name="pi.dbfo_background-color">
198     <xsl:with-param name="node" select=".."/>
199   </xsl:call-template>
200 </xsl:template>
201
202 <xsl:template name="image.width">
203   <xsl:choose>
204     <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
205     <xsl:when test="contains(@width,'%')">
206       <xsl:value-of select="@width"/>
207     </xsl:when>
208     <xsl:when test="@width and not(@width = '')">
209       <xsl:call-template name="length-spec">
210         <xsl:with-param name="length" select="@width"/>
211         <xsl:with-param name="default.units" select="'px'"/>
212       </xsl:call-template>
213     </xsl:when>
214     <xsl:when test="not(@depth) and $default.image.width != ''">
215       <xsl:call-template name="length-spec">
216         <xsl:with-param name="length" select="$default.image.width"/>
217         <xsl:with-param name="default.units" select="'px'"/>
218       </xsl:call-template>
219     </xsl:when>
220     <xsl:otherwise>auto</xsl:otherwise>
221   </xsl:choose>
222 </xsl:template>
223
224 <xsl:template name="image.height">
225   <xsl:choose>
226     <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
227     <xsl:when test="contains(@depth,'%')">
228       <xsl:value-of select="@depth"/>
229     </xsl:when>
230     <xsl:when test="@depth">
231       <xsl:call-template name="length-spec">
232         <xsl:with-param name="length" select="@depth"/>
233         <xsl:with-param name="default.units" select="'px'"/>
234       </xsl:call-template>
235     </xsl:when>
236     <xsl:otherwise>auto</xsl:otherwise>
237   </xsl:choose>
238 </xsl:template>
239
240 <xsl:template name="image.content.width">
241   <xsl:param name="scalefit" select="0"/>
242   <xsl:param name="scale" select="'1.0'"/>
243
244   <xsl:choose>
245     <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
246     <xsl:when test="contains(@contentwidth,'%')">
247       <xsl:value-of select="@contentwidth"/>
248     </xsl:when>
249     <xsl:when test="@contentwidth">
250       <xsl:call-template name="length-spec">
251         <xsl:with-param name="length" select="@contentwidth"/>
252         <xsl:with-param name="default.units" select="'px'"/>
253       </xsl:call-template>
254     </xsl:when>
255     <xsl:when test="number($scale) != 1.0">
256       <xsl:value-of select="$scale * 100"/>
257       <xsl:text>%</xsl:text>
258     </xsl:when>
259     <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
260     <xsl:otherwise>auto</xsl:otherwise>
261   </xsl:choose>
262 </xsl:template>
263
264 <xsl:template name="image.content.height">
265   <xsl:param name="scalefit" select="0"/>
266   <xsl:param name="scale" select="0"/>
267
268   <xsl:choose>
269     <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
270     <xsl:when test="contains(@contentdepth,'%')">
271       <xsl:value-of select="@contentdepth"/>
272     </xsl:when>
273     <xsl:when test="@contentdepth">
274       <xsl:call-template name="length-spec">
275         <xsl:with-param name="length" select="@contentdepth"/>
276         <xsl:with-param name="default.units" select="'px'"/>
277       </xsl:call-template>
278     </xsl:when>
279     <xsl:when test="number($scale) != 1.0">
280       <xsl:value-of select="$scale * 100"/>
281       <xsl:text>%</xsl:text>
282     </xsl:when>
283     <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
284     <xsl:otherwise>auto</xsl:otherwise>
285   </xsl:choose>
286 </xsl:template>
287
288 <xsl:template name="image.align">
289   <xsl:value-of select="@align"/>
290 </xsl:template>
291
292 <xsl:template name="image.valign">
293   <xsl:if test="@valign">
294     <xsl:choose>
295       <xsl:when test="ancestor::inlinemediaobject or ancestor-or-self::inlinegraphic">
296         <xsl:choose>
297           <xsl:when test="@valign = 'top'">baseline</xsl:when>
298           <xsl:when test="@valign = 'middle'">central</xsl:when>
299           <xsl:when test="@valign = 'bottom'">text-before-edge</xsl:when>
300         </xsl:choose>
301       </xsl:when>
302       <xsl:otherwise>
303         <xsl:choose>
304           <xsl:when test="@valign = 'top'">before</xsl:when>
305           <xsl:when test="@valign = 'middle'">center</xsl:when>
306           <xsl:when test="@valign = 'bottom'">after</xsl:when>
307         </xsl:choose>
308       </xsl:otherwise>
309     </xsl:choose>
310   </xsl:if>
311 </xsl:template>
312
313   
314 <xsl:template name="process.image">
315   <!-- When this template is called, the current node should be  -->
316   <!-- a graphic, inlinegraphic, imagedata, or videodata. All    -->
317   <!-- those elements have the same set of attributes, so we can -->
318   <!-- handle them all in one place.                             -->
319
320   <!-- Compute each attribute value with its own customizable template call -->
321   <xsl:variable name="scalefit">
322     <xsl:call-template name="image.scalefit"/>
323   </xsl:variable>
324
325   <xsl:variable name="scale">
326     <xsl:call-template name="image.scale"/>
327   </xsl:variable>
328
329   <xsl:variable name="filename">
330     <xsl:call-template name="image.filename"/>
331   </xsl:variable>
332
333   <xsl:variable name="src">
334     <xsl:call-template name="image.src">
335       <xsl:with-param name="filename" select="$filename"/>
336     </xsl:call-template>
337   </xsl:variable>
338
339   <xsl:variable name="content.type">
340     <xsl:call-template name="image.content.type"/>
341   </xsl:variable>
342
343   <xsl:variable name="bgcolor">
344     <xsl:call-template name="image.bgcolor"/>
345   </xsl:variable>
346
347   <xsl:variable name="width">
348     <xsl:call-template name="image.width"/>
349   </xsl:variable>
350
351   <xsl:variable name="height">
352     <xsl:call-template name="image.height"/>
353   </xsl:variable>
354
355   <xsl:variable name="content.width">
356     <xsl:call-template name="image.content.width">
357       <xsl:with-param name="scalefit" select="$scalefit"/>
358       <xsl:with-param name="scale" select="$scale"/>
359     </xsl:call-template>
360   </xsl:variable>
361
362   <xsl:variable name="content.height">
363     <xsl:call-template name="image.content.height">
364       <xsl:with-param name="scalefit" select="$scalefit"/>
365       <xsl:with-param name="scale" select="$scale"/>
366     </xsl:call-template>
367   </xsl:variable>
368
369   <xsl:variable name="align">
370     <xsl:call-template name="image.align"/>
371   </xsl:variable>
372
373   <xsl:variable name="valign">
374     <xsl:call-template name="image.valign"/>
375   </xsl:variable>
376
377   <xsl:variable name="element.name">
378     <xsl:choose>
379       <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
380         <xsl:text>fo:instream-foreign-object</xsl:text>
381       </xsl:when>
382       <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
383         <xsl:text>fo:instream-foreign-object</xsl:text>
384       </xsl:when>
385       <xsl:otherwise>
386         <xsl:text>fo:external-graphic</xsl:text>
387       </xsl:otherwise>
388     </xsl:choose>
389   </xsl:variable>
390
391   <xsl:element name="{$element.name}">
392
393     <xsl:if test="$src != ''">
394       <xsl:attribute name="src">
395         <xsl:value-of select="$src"/>
396       </xsl:attribute>
397     </xsl:if>
398
399     <xsl:if test="$width != ''">
400       <xsl:attribute name="width">
401         <xsl:value-of select="$width"/>
402       </xsl:attribute>
403     </xsl:if>
404
405     <xsl:if test="$height != ''">
406       <xsl:attribute name="height">
407         <xsl:value-of select="$height"/>
408       </xsl:attribute>
409     </xsl:if>
410
411     <xsl:if test="$content.width != ''">
412       <xsl:attribute name="content-width">
413         <xsl:value-of select="$content.width"/>
414       </xsl:attribute>
415     </xsl:if>
416
417     <xsl:if test="$content.height != ''">
418       <xsl:attribute name="content-height">
419         <xsl:value-of select="$content.height"/>
420       </xsl:attribute>
421     </xsl:if>
422
423     <xsl:if test="$content.type != ''">
424       <xsl:attribute name="content-type">
425         <xsl:value-of select="concat('content-type:',$content.type)"/>
426       </xsl:attribute>
427     </xsl:if>
428
429     <xsl:if test="$bgcolor != ''">
430       <xsl:attribute name="background-color">
431         <xsl:value-of select="$bgcolor"/>
432       </xsl:attribute>
433     </xsl:if>
434
435     <xsl:if test="$align != ''">
436       <xsl:attribute name="text-align">
437         <xsl:value-of select="$align"/>
438       </xsl:attribute>
439     </xsl:if>
440
441     <xsl:if test="$valign != ''">
442       <xsl:variable name="att.name">
443         <xsl:choose>
444           <xsl:when test="ancestor::inlinemediaobject or ancestor-or-self::inlinegraphic">
445             <xsl:text>alignment-baseline</xsl:text>
446           </xsl:when>
447           <xsl:otherwise>
448             <xsl:text>display-align</xsl:text>
449           </xsl:otherwise>
450         </xsl:choose>
451       </xsl:variable>
452       <xsl:attribute name="{$att.name}">
453         <xsl:value-of select="$valign"/>
454       </xsl:attribute>
455     </xsl:if>
456
457     <!-- copy literal SVG elements to output -->
458     <xsl:if test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
459       <xsl:call-template name="process.svg"/>
460     </xsl:if>
461
462     <xsl:if test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
463       <xsl:call-template name="process.mml"/>
464     </xsl:if>
465
466   </xsl:element>
467 </xsl:template>
468
469 <!-- ==================================================================== -->
470
471 <xsl:template match="graphic">
472   <xsl:choose>
473     <xsl:when test="parent::inlineequation">
474       <xsl:call-template name="process.image"/>
475     </xsl:when>
476     <xsl:otherwise>
477       <fo:block>
478         <xsl:call-template name="anchor"/>
479         <xsl:if test="@align">
480           <xsl:attribute name="text-align">
481             <xsl:value-of select="@align"/>
482           </xsl:attribute>
483         </xsl:if>
484         <xsl:call-template name="process.image"/>
485       </fo:block>
486     </xsl:otherwise>
487   </xsl:choose>
488 </xsl:template>
489
490 <xsl:template match="inlinegraphic">
491   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
492   <xsl:variable name="filename">
493     <xsl:choose>
494       <xsl:when test="@entityref">
495         <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
496       </xsl:when>
497       <xsl:otherwise>
498         <xsl:apply-templates select="@fileref"/>
499       </xsl:otherwise>
500     </xsl:choose>
501   </xsl:variable>
502
503   <xsl:choose>
504     <xsl:when test="@format='linespecific'">
505       <xsl:choose>
506         <xsl:when test="$use.extensions != '0'
507                         and $textinsert.extension != '0'">
508           <xsl:choose>
509             <xsl:when test="contains($vendor, 'SAXON')">
510               <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
511             </xsl:when>
512             <xsl:when test="contains($vendor, 'Apache Software Foundation')">
513               <xtext:insertfile href="{$filename}"/>
514             </xsl:when>
515             <xsl:otherwise>
516               <xsl:message terminate="yes">
517                 <xsl:text>Don't know how to insert files with </xsl:text>
518                 <xsl:value-of select="$vendor"/>
519               </xsl:message>
520             </xsl:otherwise>
521           </xsl:choose>
522         </xsl:when>
523         <xsl:otherwise>
524           <xsl:message terminate="yes">
525             <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
526             <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text> 
527           </xsl:message>
528         </xsl:otherwise>
529       </xsl:choose>
530     </xsl:when>
531     <xsl:otherwise>
532       <xsl:call-template name="process.image"/>
533     </xsl:otherwise>
534   </xsl:choose>
535 </xsl:template>
536
537 <!-- ==================================================================== -->
538
539 <xsl:template match="mediaobject|mediaobjectco">
540
541   <xsl:variable name="olist" select="imageobject|imageobjectco
542                      |videoobject|audioobject
543                      |textobject"/>
544
545   <xsl:variable name="object.index">
546     <xsl:call-template name="select.mediaobject.index">
547       <xsl:with-param name="olist" select="$olist"/>
548       <xsl:with-param name="count" select="1"/>
549     </xsl:call-template>
550   </xsl:variable>
551
552   <xsl:variable name="object" select="$olist[position() = $object.index]"/>
553
554   <xsl:variable name="align">
555     <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
556   </xsl:variable>
557
558   <xsl:variable name="id">
559     <xsl:call-template name="object.id"/>
560   </xsl:variable>
561
562   <fo:block id="{$id}">
563     <xsl:if test="$align != '' ">
564       <xsl:attribute name="text-align">
565         <xsl:value-of select="$align"/>
566       </xsl:attribute>
567     </xsl:if>
568
569     <xsl:apply-templates select="$object"/>
570     <xsl:apply-templates select="caption"/>
571   </fo:block>
572 </xsl:template>
573
574 <xsl:template match="inlinemediaobject">
575   <xsl:call-template name="select.mediaobject"/>
576 </xsl:template>
577
578 <!-- ==================================================================== -->
579
580 <xsl:template match="imageobjectco">
581   <xsl:choose>
582     <!-- select one imageobject? -->
583     <xsl:when test="$use.role.for.mediaobject != 0 and
584                     count(imageobject) &gt; 1 and
585                     imageobject[@role]">
586       <xsl:variable name="olist" select="imageobject"/>
587     
588       <xsl:variable name="object.index">
589         <xsl:call-template name="select.mediaobject.index">
590           <xsl:with-param name="olist" select="$olist"/>
591           <xsl:with-param name="count" select="1"/>
592         </xsl:call-template>
593       </xsl:variable>
594     
595       <xsl:variable name="object" select="$olist[position() = $object.index]"/>
596     
597       <xsl:apply-templates select="$object"/>
598     </xsl:when>
599     <xsl:otherwise>
600       <!-- otherwise process them all -->
601       <xsl:apply-templates select="imageobject"/>
602     </xsl:otherwise>
603   </xsl:choose>
604
605   <xsl:apply-templates select="calloutlist"/>
606
607 </xsl:template>
608
609 <xsl:template match="imageobject">
610   <xsl:choose>
611     <xsl:when test="imagedata">
612       <xsl:apply-templates select="imagedata"/>
613     </xsl:when>
614     <xsl:otherwise>
615       <fo:instream-foreign-object>
616         <xsl:apply-templates mode="copy-all"/>
617       </fo:instream-foreign-object>
618     </xsl:otherwise>
619   </xsl:choose>
620 </xsl:template>
621
622 <!-- ==================================================================== -->
623
624 <xsl:template match="*" mode="copy-all">
625   <xsl:copy>
626     <xsl:for-each select="@*">
627       <xsl:copy/>
628     </xsl:for-each>
629     <xsl:apply-templates mode="copy-all"/>
630   </xsl:copy>
631 </xsl:template>
632
633 <xsl:template match="text()|comment()|processing-instruction()" mode="copy-all">
634   <xsl:copy/>
635 </xsl:template>
636
637 <xsl:template name="process.mml">
638   <xsl:apply-templates mode="copy-all" select="*"/>
639 </xsl:template>
640
641 <xsl:template name="process.svg">
642   <xsl:apply-templates mode="copy-all" select="*"/>
643 </xsl:template>
644
645 <!-- ==================================================================== -->
646
647 <xsl:template match="imagedata">
648   <xsl:choose>
649     <xsl:when test="@format='linespecific'">
650       <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
651     
652       <xsl:variable name="filename">
653         <xsl:call-template name="mediaobject.filename">
654           <xsl:with-param name="object" select=".."/>
655         </xsl:call-template>
656       </xsl:variable>
657
658       <xsl:choose>
659         <xsl:when test="$use.extensions != '0'
660                         and $textinsert.extension != '0'">
661           <xsl:choose>
662             <xsl:when test="contains($vendor, 'SAXON')">
663               <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
664             </xsl:when>
665             <xsl:when test="contains($vendor, 'Apache Software Foundation')">
666               <xtext:insertfile href="{$filename}"/>
667             </xsl:when>
668             <xsl:otherwise>
669               <xsl:message terminate="yes">
670                 <xsl:text>Don't know how to insert files with </xsl:text>
671                 <xsl:value-of select="$vendor"/>
672               </xsl:message>
673             </xsl:otherwise>
674           </xsl:choose>
675         </xsl:when>
676         <xsl:otherwise>
677           <xsl:message terminate="yes">
678             <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
679             <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text> 
680           </xsl:message>
681         </xsl:otherwise>
682       </xsl:choose>
683     </xsl:when>
684     <xsl:otherwise>
685       <xsl:call-template name="process.image"/>
686     </xsl:otherwise>
687   </xsl:choose>
688 </xsl:template>
689
690 <!-- ==================================================================== -->
691
692 <xsl:template match="videoobject">
693   <xsl:apply-templates select="videodata"/>
694 </xsl:template>
695
696 <xsl:template match="videodata">
697   <xsl:call-template name="process.image"/>
698 </xsl:template>
699
700 <!-- ==================================================================== -->
701
702 <xsl:template match="audioobject">
703   <xsl:apply-templates select="audiodata"/>
704 </xsl:template>
705
706 <xsl:template match="audiodata">
707   <xsl:call-template name="process.image"/>
708 </xsl:template>
709
710 <!-- ==================================================================== -->
711
712 <xsl:template match="textobject">
713   <xsl:apply-templates/>
714 </xsl:template>
715
716 <xsl:template match="textdata">
717   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
718   <xsl:variable name="filename">
719     <xsl:choose>
720       <xsl:when test="@entityref">
721         <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
722       </xsl:when>
723       <xsl:otherwise>
724         <xsl:apply-templates select="@fileref"/>
725       </xsl:otherwise>
726     </xsl:choose>
727   </xsl:variable>
728
729   <xsl:variable name="encoding">
730     <xsl:choose>
731       <xsl:when test="@encoding">
732         <xsl:value-of select="@encoding"/>
733       </xsl:when>
734       <xsl:otherwise>
735         <xsl:value-of select="$textdata.default.encoding"/>
736       </xsl:otherwise>
737     </xsl:choose>
738   </xsl:variable>
739
740   <xsl:choose>
741     <xsl:when test="$use.extensions != '0'
742                     and $textinsert.extension != '0'">
743       <xsl:choose>
744         <xsl:when test="element-available('stext:insertfile')">
745           <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
746         </xsl:when>
747         <xsl:when test="element-available('xtext:insertfile')">
748           <xtext:insertfile href="{$filename}"/>
749         </xsl:when>
750         <xsl:otherwise>
751           <xsl:message terminate="yes">
752             <xsl:text>Don't know how to insert files with </xsl:text>
753             <xsl:value-of select="$vendor"/>
754           </xsl:message>
755         </xsl:otherwise>
756       </xsl:choose>
757     </xsl:when>
758     <xsl:otherwise>
759       <xsl:message terminate="yes">
760         <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
761         <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text> 
762       </xsl:message>
763     </xsl:otherwise>
764   </xsl:choose>
765 </xsl:template>
766
767 <!-- ==================================================================== -->
768
769 <xsl:template match="mediaobject/caption|figure/caption">
770   <fo:block>
771     <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
772       <xsl:attribute name="text-align"><xsl:value-of
773                          select="@align"/></xsl:attribute>
774     </xsl:if>
775     <xsl:apply-templates/>
776   </fo:block>
777 </xsl:template>
778
779 <!-- ==================================================================== -->
780
781 <xsl:template name="fo-external-image">
782   <xsl:param name="filename"/>
783
784   <xsl:choose>
785     <xsl:when test="$fop.extensions != 0">
786       <xsl:value-of select="$filename"/>
787     </xsl:when>
788     <xsl:otherwise>
789       <xsl:value-of select="concat('url(', $filename, ')')"/>
790     </xsl:otherwise>
791   </xsl:choose>
792 </xsl:template>
793
794 <!-- Resolve xml:base attributes -->
795 <xsl:template match="@fileref">
796   <!-- need a check for absolute urls -->
797   <xsl:choose>
798     <xsl:when test="contains(., ':') or starts-with(.,'/')">
799       <!-- it has a uri scheme or starts with '/', so it is an absolute uri -->
800       <xsl:value-of select="."/>
801     </xsl:when>
802     <xsl:when test="$keep.relative.image.uris != 0">
803       <!-- leave it alone -->
804       <xsl:value-of select="."/>
805     </xsl:when>
806     <xsl:otherwise>
807       <!-- its a relative uri -->
808       <xsl:call-template name="relative-uri">
809       </xsl:call-template>
810     </xsl:otherwise>
811   </xsl:choose>
812 </xsl:template>
813
814 </xsl:stylesheet>