source: trunk/Distribution/XSL/fo/graphics.xsl

Last change on this file was 2, checked in by jkacer, 18 years ago

Added all DocBook Framework stuff:

  • DocBook DTD
  • Transformation software FOP 0.20.5 and Saxon 6
  • XSL styles
  • Rexx scripts

Also added some WarpIN-related stuff for creation of WarpIN installation packages.
This state corresponds to version 1.0.0 from November 2005, just slightly modified to carry versioning information (Rexx scripts).

File size: 20.8 KB
RevLine 
[2]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,v 1.42 2005/07/09 07:57:54 bobstayton Exp $
18 ********************************************************************
19
20 This file is part of the XSL DocBook Stylesheet distribution.
21 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
22 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="$passivetex.extensions != 0">
37 <xsl:text> PNG PDF 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="$passivetex.extensions != 0">
63 <xsl:text> png pdf jpg jpeg </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<xsl:template name="graphic.format.content-type">
91 <xsl:param name="format"/>
92 <xsl:variable name="is.graphic.format">
93 <xsl:call-template name="is.graphic.format">
94 <xsl:with-param name="format" select="$format"/>
95 </xsl:call-template>
96 </xsl:variable>
97 <xsl:if test="$is.graphic.format">
98 <xsl:choose>
99 <xsl:when test="$format = ''"></xsl:when>
100 <xsl:when test="$format = 'linespecific'"></xsl:when>
101 <xsl:when test="$format = 'PS'">application/postscript</xsl:when>
102 <xsl:when test="$format = 'PDF'">application/pdf</xsl:when>
103 <xsl:when test="$format = 'PNG'">image/png</xsl:when>
104 <xsl:when test="$format = 'SVG'">image/svg+xml</xsl:when>
105 <xsl:when test="$format = 'JPG'">image/jpeg</xsl:when>
106 <xsl:when test="$format = 'GIF87a'">image/gif</xsl:when>
107 <xsl:when test="$format = 'GIF89a'">image/gif</xsl:when>
108 <xsl:otherwise>
109 <xsl:value-of select="concat('image/',
110 translate($format, &uppercase;, &lowercase;))"/>
111 </xsl:otherwise>
112 </xsl:choose>
113 </xsl:if>
114</xsl:template>
115
116
117<!-- ==================================================================== -->
118
119<xsl:template match="screenshot">
120 <fo:block>
121 <xsl:apply-templates/>
122 </fo:block>
123</xsl:template>
124
125<xsl:template match="screeninfo">
126</xsl:template>
127
128<!-- ==================================================================== -->
129<!-- Override these templates for FO -->
130<!-- ==================================================================== -->
131
132<xsl:template name="process.image">
133 <!-- When this template is called, the current node should be -->
134 <!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
135 <!-- those elements have the same set of attributes, so we can -->
136 <!-- handle them all in one place. -->
137
138 <xsl:variable name="scalefit">
139 <xsl:choose>
140 <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
141 <xsl:when test="@contentwidth">0</xsl:when>
142 <xsl:when test="@contentdepth and
143 @contentdepth != '100%'">0</xsl:when>
144 <xsl:when test="@scale">0</xsl:when>
145 <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
146 <xsl:when test="@width or @depth">1</xsl:when>
147 <xsl:otherwise>0</xsl:otherwise>
148 </xsl:choose>
149 </xsl:variable>
150
151 <xsl:variable name="scale">
152 <xsl:choose>
153 <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
154 <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
155 <xsl:when test="@scale">
156 <xsl:value-of select="@scale div 100.0"/>
157 </xsl:when>
158 <xsl:otherwise>1.0</xsl:otherwise>
159 </xsl:choose>
160 </xsl:variable>
161
162 <xsl:variable name="filename">
163 <xsl:choose>
164 <xsl:when test="local-name(.) = 'graphic'
165 or local-name(.) = 'inlinegraphic'">
166 <!-- handle legacy graphic and inlinegraphic by new template -->
167 <xsl:call-template name="mediaobject.filename">
168 <xsl:with-param name="object" select="."/>
169 </xsl:call-template>
170 </xsl:when>
171 <xsl:otherwise>
172 <!-- imagedata, videodata, audiodata -->
173 <xsl:call-template name="mediaobject.filename">
174 <xsl:with-param name="object" select=".."/>
175 </xsl:call-template>
176 </xsl:otherwise>
177 </xsl:choose>
178 </xsl:variable>
179
180 <xsl:variable name="content-type">
181 <xsl:if test="@format">
182 <xsl:call-template name="graphic.format.content-type">
183 <xsl:with-param name="format" select="@format"/>
184 </xsl:call-template>
185 </xsl:if>
186 </xsl:variable>
187
188 <xsl:variable name="bgcolor">
189 <xsl:call-template name="dbfo-attribute">
190 <xsl:with-param name="pis"
191 select="../processing-instruction('dbfo')"/>
192 <xsl:with-param name="attribute" select="'background-color'"/>
193 </xsl:call-template>
194 </xsl:variable>
195
196 <fo:external-graphic>
197 <xsl:attribute name="src">
198 <xsl:call-template name="fo-external-image">
199 <xsl:with-param name="filename">
200 <xsl:if test="$img.src.path != '' and
201 not(starts-with($filename, '/')) and
202 not(contains($filename, '://'))">
203 <xsl:value-of select="$img.src.path"/>
204 </xsl:if>
205 <xsl:value-of select="$filename"/>
206 </xsl:with-param>
207 </xsl:call-template>
208 </xsl:attribute>
209
210 <xsl:attribute name="width">
211 <xsl:choose>
212 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
213 <xsl:when test="contains(@width,'%')">
214 <xsl:value-of select="@width"/>
215 </xsl:when>
216 <xsl:when test="@width">
217 <xsl:call-template name="length-spec">
218 <xsl:with-param name="length" select="@width"/>
219 <xsl:with-param name="default.units" select="'px'"/>
220 </xsl:call-template>
221 </xsl:when>
222 <xsl:when test="not(@depth) and $default.image.width != ''">
223 <xsl:call-template name="length-spec">
224 <xsl:with-param name="length" select="$default.image.width"/>
225 <xsl:with-param name="default.units" select="'px'"/>
226 </xsl:call-template>
227 </xsl:when>
228 <xsl:otherwise>auto</xsl:otherwise>
229 </xsl:choose>
230 </xsl:attribute>
231
232 <xsl:attribute name="height">
233 <xsl:choose>
234 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
235 <xsl:when test="contains(@depth,'%')">
236 <xsl:value-of select="@depth"/>
237 </xsl:when>
238 <xsl:when test="@depth">
239 <xsl:call-template name="length-spec">
240 <xsl:with-param name="length" select="@depth"/>
241 <xsl:with-param name="default.units" select="'px'"/>
242 </xsl:call-template>
243 </xsl:when>
244 <xsl:otherwise>auto</xsl:otherwise>
245 </xsl:choose>
246 </xsl:attribute>
247
248 <xsl:attribute name="content-width">
249 <xsl:choose>
250 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
251 <xsl:when test="contains(@contentwidth,'%')">
252 <xsl:value-of select="@contentwidth"/>
253 </xsl:when>
254 <xsl:when test="@contentwidth">
255 <xsl:call-template name="length-spec">
256 <xsl:with-param name="length" select="@contentwidth"/>
257 <xsl:with-param name="default.units" select="'px'"/>
258 </xsl:call-template>
259 </xsl:when>
260 <xsl:when test="number($scale) != 1.0">
261 <xsl:value-of select="$scale * 100"/>
262 <xsl:text>%</xsl:text>
263 </xsl:when>
264 <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
265 <xsl:otherwise>auto</xsl:otherwise>
266 </xsl:choose>
267 </xsl:attribute>
268
269 <xsl:attribute name="content-height">
270 <xsl:choose>
271 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
272 <xsl:when test="contains(@contentdepth,'%')">
273 <xsl:value-of select="@contentdepth"/>
274 </xsl:when>
275 <xsl:when test="@contentdepth">
276 <xsl:call-template name="length-spec">
277 <xsl:with-param name="length" select="@contentdepth"/>
278 <xsl:with-param name="default.units" select="'px'"/>
279 </xsl:call-template>
280 </xsl:when>
281 <xsl:when test="number($scale) != 1.0">
282 <xsl:value-of select="$scale * 100"/>
283 <xsl:text>%</xsl:text>
284 </xsl:when>
285 <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
286 <xsl:otherwise>auto</xsl:otherwise>
287 </xsl:choose>
288 </xsl:attribute>
289
290 <xsl:if test="$content-type != ''">
291 <xsl:attribute name="content-type">
292 <xsl:value-of select="concat('content-type:',$content-type)"/>
293 </xsl:attribute>
294 </xsl:if>
295
296 <xsl:if test="$bgcolor != ''">
297 <xsl:attribute name="background-color">
298 <xsl:value-of select="$bgcolor"/>
299 </xsl:attribute>
300 </xsl:if>
301
302 <xsl:if test="@align">
303 <xsl:attribute name="text-align">
304 <xsl:value-of select="@align"/>
305 </xsl:attribute>
306 </xsl:if>
307
308 <xsl:if test="@valign">
309 <xsl:attribute name="display-align">
310 <xsl:choose>
311 <xsl:when test="@valign = 'top'">before</xsl:when>
312 <xsl:when test="@valign = 'middle'">center</xsl:when>
313 <xsl:when test="@valign = 'bottom'">after</xsl:when>
314 <xsl:otherwise>auto</xsl:otherwise>
315 </xsl:choose>
316 </xsl:attribute>
317 </xsl:if>
318 </fo:external-graphic>
319</xsl:template>
320
321<!-- ==================================================================== -->
322
323<xsl:template match="graphic">
324 <xsl:choose>
325 <xsl:when test="parent::inlineequation">
326 <xsl:call-template name="process.image"/>
327 </xsl:when>
328 <xsl:otherwise>
329 <fo:block>
330 <xsl:if test="@align">
331 <xsl:attribute name="text-align">
332 <xsl:value-of select="@align"/>
333 </xsl:attribute>
334 </xsl:if>
335 <xsl:call-template name="process.image"/>
336 </fo:block>
337 </xsl:otherwise>
338 </xsl:choose>
339</xsl:template>
340
341<xsl:template match="inlinegraphic">
342 <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
343 <xsl:variable name="filename">
344 <xsl:choose>
345 <xsl:when test="@entityref">
346 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
347 </xsl:when>
348 <xsl:otherwise>
349 <xsl:apply-templates select="@fileref"/>
350 </xsl:otherwise>
351 </xsl:choose>
352 </xsl:variable>
353
354 <xsl:choose>
355 <xsl:when test="@format='linespecific'">
356 <xsl:choose>
357 <xsl:when test="$use.extensions != '0'
358 and $textinsert.extension != '0'">
359 <xsl:choose>
360 <xsl:when test="contains($vendor, 'SAXON')">
361 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
362 </xsl:when>
363 <xsl:when test="contains($vendor, 'Apache Software Foundation')">
364 <xtext:insertfile href="{$filename}"/>
365 </xsl:when>
366 <xsl:otherwise>
367 <xsl:message terminate="yes">
368 <xsl:text>Don't know how to insert files with </xsl:text>
369 <xsl:value-of select="$vendor"/>
370 </xsl:message>
371 </xsl:otherwise>
372 </xsl:choose>
373 </xsl:when>
374 <xsl:otherwise>
375 <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
376 href="{$filename}"/>
377 </xsl:otherwise>
378 </xsl:choose>
379 </xsl:when>
380 <xsl:otherwise>
381 <xsl:call-template name="process.image"/>
382 </xsl:otherwise>
383 </xsl:choose>
384</xsl:template>
385
386<!-- ==================================================================== -->
387
388<xsl:template match="mediaobject|mediaobjectco">
389
390 <xsl:variable name="olist" select="imageobject|imageobjectco
391 |videoobject|audioobject
392 |textobject"/>
393
394 <xsl:variable name="object.index">
395 <xsl:call-template name="select.mediaobject.index">
396 <xsl:with-param name="olist" select="$olist"/>
397 <xsl:with-param name="count" select="1"/>
398 </xsl:call-template>
399 </xsl:variable>
400
401 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
402
403 <xsl:variable name="align">
404 <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
405 </xsl:variable>
406
407 <xsl:variable name="id">
408 <xsl:call-template name="object.id"/>
409 </xsl:variable>
410
411 <fo:block id="{$id}">
412 <xsl:if test="$align != '' ">
413 <xsl:attribute name="text-align">
414 <xsl:value-of select="$align"/>
415 </xsl:attribute>
416 </xsl:if>
417
418 <xsl:apply-templates select="$object"/>
419 <xsl:apply-templates select="caption"/>
420 </fo:block>
421</xsl:template>
422
423<xsl:template match="inlinemediaobject">
424 <xsl:call-template name="select.mediaobject"/>
425</xsl:template>
426
427<!-- ==================================================================== -->
428
429<xsl:template match="imageobjectco">
430 <xsl:apply-templates select="imageobject"/>
431 <xsl:apply-templates select="calloutlist"/>
432</xsl:template>
433
434<xsl:template match="imageobject">
435 <xsl:choose>
436 <xsl:when test="imagedata">
437 <xsl:apply-templates select="imagedata"/>
438 </xsl:when>
439 <xsl:otherwise>
440 <fo:instream-foreign-object>
441 <xsl:apply-templates mode="copy-all"/>
442 </fo:instream-foreign-object>
443 </xsl:otherwise>
444 </xsl:choose>
445</xsl:template>
446
447<!-- ==================================================================== -->
448
449<xsl:template match="*" mode="copy-all">
450 <xsl:copy>
451 <xsl:for-each select="@*">
452 <xsl:copy/>
453 </xsl:for-each>
454 <xsl:apply-templates mode="copy-all"/>
455 </xsl:copy>
456</xsl:template>
457
458<xsl:template match="text()|comment()|processing-instruction()" mode="copy-all">
459 <xsl:copy/>
460</xsl:template>
461
462<!-- ==================================================================== -->
463
464<xsl:template match="imagedata">
465 <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
466 <xsl:variable name="filename">
467 <xsl:call-template name="mediaobject.filename">
468 <xsl:with-param name="object" select=".."/>
469 </xsl:call-template>
470 </xsl:variable>
471
472 <xsl:choose>
473 <xsl:when test="@format='linespecific'">
474 <xsl:choose>
475 <xsl:when test="$use.extensions != '0'
476 and $textinsert.extension != '0'">
477 <xsl:choose>
478 <xsl:when test="contains($vendor, 'SAXON')">
479 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
480 </xsl:when>
481 <xsl:when test="contains($vendor, 'Apache Software Foundation')">
482 <xtext:insertfile href="{$filename}"/>
483 </xsl:when>
484 <xsl:otherwise>
485 <xsl:message terminate="yes">
486 <xsl:text>Don't know how to insert files with </xsl:text>
487 <xsl:value-of select="$vendor"/>
488 </xsl:message>
489 </xsl:otherwise>
490 </xsl:choose>
491 </xsl:when>
492 <xsl:otherwise>
493 <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
494 href="{$filename}"/>
495 </xsl:otherwise>
496 </xsl:choose>
497 </xsl:when>
498 <xsl:otherwise>
499 <xsl:call-template name="process.image"/>
500 </xsl:otherwise>
501 </xsl:choose>
502</xsl:template>
503
504<!-- ==================================================================== -->
505
506<xsl:template match="videoobject">
507 <xsl:apply-templates select="videodata"/>
508</xsl:template>
509
510<xsl:template match="videodata">
511 <xsl:call-template name="process.image"/>
512</xsl:template>
513
514<!-- ==================================================================== -->
515
516<xsl:template match="audioobject">
517 <xsl:apply-templates select="audiodata"/>
518</xsl:template>
519
520<xsl:template match="audiodata">
521 <xsl:call-template name="process.image"/>
522</xsl:template>
523
524<!-- ==================================================================== -->
525
526<xsl:template match="textobject">
527 <xsl:apply-templates/>
528</xsl:template>
529
530<xsl:template match="textdata">
531 <xsl:variable name="filename">
532 <xsl:choose>
533 <xsl:when test="@entityref">
534 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
535 </xsl:when>
536 <xsl:otherwise>
537 <xsl:apply-templates select="@fileref"/>
538 </xsl:otherwise>
539 </xsl:choose>
540 </xsl:variable>
541
542 <xsl:variable name="encoding">
543 <xsl:choose>
544 <xsl:when test="@encoding">
545 <xsl:value-of select="@encoding"/>
546 </xsl:when>
547 <xsl:otherwise>
548 <xsl:value-of select="$textdata.default.encoding"/>
549 </xsl:otherwise>
550 </xsl:choose>
551 </xsl:variable>
552
553 <xsl:choose>
554 <xsl:when test="$use.extensions != '0'
555 and $textinsert.extension != '0'">
556 <xsl:choose>
557 <xsl:when test="element-available('stext:insertfile')">
558 <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
559 </xsl:when>
560 <xsl:when test="element-available('xtext:insertfile')">
561 <xtext:insertfile href="{$filename}"/>
562 </xsl:when>
563 <xsl:otherwise>
564 <xsl:message terminate="yes">
565 <xsl:text>No insertfile extension available.</xsl:text>
566 </xsl:message>
567 </xsl:otherwise>
568 </xsl:choose>
569 </xsl:when>
570 <xsl:otherwise>
571 <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
572 href="{$filename}"/>
573 </xsl:otherwise>
574 </xsl:choose>
575</xsl:template>
576
577<!-- ==================================================================== -->
578
579<xsl:template match="caption">
580 <fo:block>
581 <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
582 <xsl:attribute name="text-align"><xsl:value-of
583 select="@align"/></xsl:attribute>
584 </xsl:if>
585 <xsl:apply-templates/>
586 </fo:block>
587</xsl:template>
588
589<!-- ==================================================================== -->
590
591<xsl:template name="fo-external-image">
592 <xsl:param name="filename"/>
593
594 <xsl:choose>
595 <xsl:when test="$passivetex.extensions != 0
596 or $fop.extensions != 0
597 or $arbortext.extensions != 0">
598 <xsl:value-of select="$filename"/>
599 </xsl:when>
600 <xsl:otherwise>
601 <xsl:value-of select="concat('url(', $filename, ')')"/>
602 </xsl:otherwise>
603 </xsl:choose>
604</xsl:template>
605
606<!-- Resolve xml:base attributes -->
607<xsl:template match="@fileref">
608 <!-- need a check for absolute urls -->
609 <xsl:choose>
610 <xsl:when test="contains(., ':')">
611 <!-- it has a uri scheme so it is an absolute uri -->
612 <xsl:value-of select="."/>
613 </xsl:when>
614 <xsl:otherwise>
615 <!-- its a relative uri -->
616 <xsl:call-template name="relative-uri">
617 </xsl:call-template>
618 </xsl:otherwise>
619 </xsl:choose>
620</xsl:template>
621
622</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.