2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
4 <!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
6 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7 xmlns:d="http://docbook.org/ns/docbook"
8 xmlns:fo="http://www.w3.org/1999/XSL/Format"
9 xmlns:xlink="http://www.w3.org/1999/xlink"
10 xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
11 xmlns:xtext="com.nwalsh.xalan.Text"
12 xmlns:lxslt="http://xml.apache.org/xslt"
13 exclude-result-prefixes="xlink stext xtext lxslt d"
14 extension-element-prefixes="stext xtext"
17 <!-- ********************************************************************
19 This file is part of the XSL DocBook Stylesheet distribution.
20 See ../README or http://cdn.docbook.org/release/xsl/current/ for
21 copyright and other information.
24 Colin Paul Adams, <colin@colina.demon.co.uk>
25 Paul Grosso, <pgrosso@arbortext.com>
27 ******************************************************************** -->
29 <!-- ==================================================================== -->
30 <!-- Graphic format tests for the FO backend -->
32 <xsl:param name="graphic.notations">
33 <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
35 <xsl:when test="$fop1.extensions != 0">
36 <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
38 <xsl:when test="$fop.extensions != 0">
39 <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
41 <xsl:when test="$arbortext.extensions != 0">
42 <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
44 <xsl:when test="$xep.extensions != 0">
45 <xsl:text> SVG PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
48 <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
53 <xsl:template name="is.graphic.format">
54 <xsl:param name="format"/>
55 <xsl:if test="contains($graphic.notations, concat(' ',$format,' '))">1</xsl:if>
58 <xsl:param name="graphic.extensions">
59 <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
61 <xsl:when test="$fop1.extensions != 0">
62 <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
64 <xsl:when test="$fop.extensions != 0">
65 <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
67 <xsl:when test="$arbortext.extensions != 0">
68 <xsl:text> png pdf jpg jpeg gif tif tiff bmp </xsl:text>
70 <xsl:when test="$xep.extensions != 0">
71 <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
74 <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
79 <xsl:template name="is.graphic.extension">
80 <xsl:param name="ext"/>
81 <xsl:variable name="lcext" select="translate($ext,
82 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
83 'abcdefghijklmnopqrstuvwxyz')"/>
85 <xsl:if test="contains($graphic.extensions,
86 concat(' ', $lcext, ' '))">1</xsl:if>
90 <!-- ==================================================================== -->
92 <xsl:template match="d:screenshot">
94 <xsl:call-template name="anchor"/>
95 <xsl:apply-templates/>
99 <xsl:template match="d:screenshot/d:title">
100 <xsl:call-template name="formal.object.heading">
101 <xsl:with-param name="object" select=".."/>
105 <xsl:template match="d:screeninfo">
108 <!-- ==================================================================== -->
109 <!-- Override these templates for FO -->
110 <!-- ==================================================================== -->
112 <xsl:template name="image.scalefit">
114 <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
115 <xsl:when test="@contentwidth">0</xsl:when>
116 <xsl:when test="@contentdepth and
117 @contentdepth != '100%'">0</xsl:when>
118 <xsl:when test="@scale">0</xsl:when>
119 <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
120 <xsl:when test="@width or @depth">1</xsl:when>
121 <xsl:when test="$default.image.width != ''">1</xsl:when>
122 <xsl:otherwise>0</xsl:otherwise>
126 <xsl:template name="image.scale">
128 <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
129 <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
130 <xsl:when test="@scale">
131 <xsl:value-of select="@scale div 100.0"/>
133 <xsl:otherwise>1.0</xsl:otherwise>
137 <xsl:template name="image.filename">
139 <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
140 <!-- no filename for inline SVG content -->
142 <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
143 <!-- no filename for inline MathML content -->
145 <xsl:when test="local-name(.) = 'graphic'
146 or local-name(.) = 'inlinegraphic'">
147 <!-- handle legacy graphic and inlinegraphic by new template -->
148 <xsl:call-template name="mediaobject.filename">
149 <xsl:with-param name="object" select="."/>
153 <!-- imagedata, videodata, audiodata -->
154 <xsl:call-template name="mediaobject.filename">
155 <xsl:with-param name="object" select=".."/>
161 <xsl:template name="image.src">
162 <xsl:param name="filename"/>
165 <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
166 <!-- no src attribute for inline SVG content -->
168 <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
169 <!-- no src attribute for inline MathML content -->
172 <xsl:call-template name="fo-external-image">
173 <xsl:with-param name="filename">
174 <xsl:if test="$img.src.path != '' and
175 not(starts-with($filename, '/')) and
176 not(starts-with($filename, 'file:/')) and
177 not(contains($filename, '://'))">
178 <xsl:value-of select="$img.src.path"/>
180 <xsl:value-of select="$filename"/>
187 <xsl:template name="image.content.type">
188 <xsl:if test="@format">
189 <xsl:call-template name="graphic.format.content-type">
190 <xsl:with-param name="format" select="@format"/>
195 <xsl:template name="image.bgcolor">
196 <xsl:call-template name="pi.dbfo_background-color">
197 <xsl:with-param name="node" select=".."/>
201 <xsl:template name="image.width">
203 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
204 <xsl:when test="contains(@width,'%')">
205 <xsl:value-of select="@width"/>
207 <xsl:when test="@width and not(@width = '')">
208 <xsl:call-template name="length-spec">
209 <xsl:with-param name="length" select="@width"/>
210 <xsl:with-param name="default.units" select="'px'"/>
213 <xsl:when test="not(@depth) and $default.image.width != ''">
214 <xsl:call-template name="length-spec">
215 <xsl:with-param name="length" select="$default.image.width"/>
216 <xsl:with-param name="default.units" select="'px'"/>
219 <xsl:otherwise>auto</xsl:otherwise>
223 <xsl:template name="image.height">
225 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
226 <xsl:when test="contains(@depth,'%')">
227 <xsl:value-of select="@depth"/>
229 <xsl:when test="@depth">
230 <xsl:call-template name="length-spec">
231 <xsl:with-param name="length" select="@depth"/>
232 <xsl:with-param name="default.units" select="'px'"/>
235 <xsl:otherwise>auto</xsl:otherwise>
239 <xsl:template name="image.content.width">
240 <xsl:param name="scalefit" select="0"/>
241 <xsl:param name="scale" select="'1.0'"/>
244 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
245 <xsl:when test="contains(@contentwidth,'%')">
246 <xsl:value-of select="@contentwidth"/>
248 <xsl:when test="@contentwidth">
249 <xsl:call-template name="length-spec">
250 <xsl:with-param name="length" select="@contentwidth"/>
251 <xsl:with-param name="default.units" select="'px'"/>
254 <xsl:when test="number($scale) != 1.0">
255 <xsl:value-of select="$scale * 100"/>
256 <xsl:text>%</xsl:text>
258 <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
259 <xsl:otherwise>auto</xsl:otherwise>
263 <xsl:template name="image.content.height">
264 <xsl:param name="scalefit" select="0"/>
265 <xsl:param name="scale" select="0"/>
268 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
269 <xsl:when test="contains(@contentdepth,'%')">
270 <xsl:value-of select="@contentdepth"/>
272 <xsl:when test="@contentdepth">
273 <xsl:call-template name="length-spec">
274 <xsl:with-param name="length" select="@contentdepth"/>
275 <xsl:with-param name="default.units" select="'px'"/>
278 <xsl:when test="number($scale) != 1.0">
279 <xsl:value-of select="$scale * 100"/>
280 <xsl:text>%</xsl:text>
282 <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
283 <xsl:otherwise>auto</xsl:otherwise>
287 <xsl:template name="image.align">
288 <xsl:value-of select="@align"/>
291 <xsl:template name="image.valign">
292 <xsl:if test="@valign">
294 <xsl:when test="ancestor::d:inlinemediaobject or ancestor-or-self::d:inlinegraphic">
296 <xsl:when test="@valign = 'top'">baseline</xsl:when>
297 <xsl:when test="@valign = 'middle'">central</xsl:when>
298 <xsl:when test="@valign = 'bottom'">text-before-edge</xsl:when>
303 <xsl:when test="@valign = 'top'">before</xsl:when>
304 <xsl:when test="@valign = 'middle'">center</xsl:when>
305 <xsl:when test="@valign = 'bottom'">after</xsl:when>
313 <xsl:template name="process.image">
314 <!-- When this template is called, the current node should be -->
315 <!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
316 <!-- those elements have the same set of attributes, so we can -->
317 <!-- handle them all in one place. -->
319 <!-- Compute each attribute value with its own customizable template call -->
320 <xsl:variable name="scalefit">
321 <xsl:call-template name="image.scalefit"/>
324 <xsl:variable name="scale">
325 <xsl:call-template name="image.scale"/>
328 <xsl:variable name="filename">
329 <xsl:call-template name="image.filename"/>
332 <xsl:variable name="src">
333 <xsl:call-template name="image.src">
334 <xsl:with-param name="filename" select="$filename"/>
338 <xsl:variable name="content.type">
339 <xsl:call-template name="image.content.type"/>
342 <xsl:variable name="bgcolor">
343 <xsl:call-template name="image.bgcolor"/>
346 <xsl:variable name="width">
347 <xsl:call-template name="image.width"/>
350 <xsl:variable name="height">
351 <xsl:call-template name="image.height"/>
354 <xsl:variable name="content.width">
355 <xsl:call-template name="image.content.width">
356 <xsl:with-param name="scalefit" select="$scalefit"/>
357 <xsl:with-param name="scale" select="$scale"/>
361 <xsl:variable name="content.height">
362 <xsl:call-template name="image.content.height">
363 <xsl:with-param name="scalefit" select="$scalefit"/>
364 <xsl:with-param name="scale" select="$scale"/>
368 <xsl:variable name="align">
369 <xsl:call-template name="image.align"/>
372 <xsl:variable name="valign">
373 <xsl:call-template name="image.valign"/>
376 <xsl:variable name="element.name">
378 <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
379 <xsl:text>fo:instream-foreign-object</xsl:text>
381 <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
382 <xsl:text>fo:instream-foreign-object</xsl:text>
385 <xsl:text>fo:external-graphic</xsl:text>
390 <xsl:element name="{$element.name}">
392 <xsl:if test="$src != ''">
393 <xsl:attribute name="src">
394 <xsl:value-of select="$src"/>
398 <xsl:if test="$width != ''">
399 <xsl:attribute name="width">
400 <xsl:value-of select="$width"/>
404 <xsl:if test="$height != ''">
405 <xsl:attribute name="height">
406 <xsl:value-of select="$height"/>
410 <xsl:if test="$content.width != ''">
411 <xsl:attribute name="content-width">
412 <xsl:value-of select="$content.width"/>
416 <xsl:if test="$content.height != ''">
417 <xsl:attribute name="content-height">
418 <xsl:value-of select="$content.height"/>
422 <xsl:if test="$content.type != ''">
423 <xsl:attribute name="content-type">
424 <xsl:value-of select="concat('content-type:',$content.type)"/>
428 <xsl:if test="$bgcolor != ''">
429 <xsl:attribute name="background-color">
430 <xsl:value-of select="$bgcolor"/>
434 <xsl:if test="$align != ''">
435 <xsl:attribute name="text-align">
436 <xsl:value-of select="$align"/>
440 <xsl:if test="$valign != ''">
441 <xsl:variable name="att.name">
443 <xsl:when test="ancestor::d:inlinemediaobject or ancestor-or-self::d:inlinegraphic">
444 <xsl:text>alignment-baseline</xsl:text>
447 <xsl:text>display-align</xsl:text>
451 <xsl:attribute name="{$att.name}">
452 <xsl:value-of select="$valign"/>
456 <!-- copy literal SVG elements to output -->
457 <xsl:if test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
458 <xsl:call-template name="process.svg"/>
461 <xsl:if test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
462 <xsl:call-template name="process.mml"/>
468 <!-- ==================================================================== -->
470 <xsl:template match="d:graphic">
472 <xsl:when test="parent::d:inlineequation">
473 <xsl:call-template name="process.image"/>
477 <xsl:call-template name="anchor"/>
478 <xsl:if test="@align">
479 <xsl:attribute name="text-align">
480 <xsl:value-of select="@align"/>
483 <xsl:call-template name="process.image"/>
489 <xsl:template match="d:inlinegraphic">
490 <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
491 <xsl:variable name="filename">
493 <xsl:when test="@entityref">
494 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
497 <xsl:apply-templates select="@fileref"/>
503 <xsl:when test="@format='linespecific'">
505 <xsl:when test="$use.extensions != '0'
506 and $textinsert.extension != '0'">
508 <xsl:when test="contains($vendor, 'SAXON')">
509 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
511 <xsl:when test="contains($vendor, 'Apache Software Foundation')">
512 <xtext:insertfile href="{$filename}"/>
515 <xsl:message terminate="yes">
516 <xsl:text>Don't know how to insert files with </xsl:text>
517 <xsl:value-of select="$vendor"/>
523 <xsl:message terminate="yes">
524 <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
525 <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
531 <xsl:call-template name="process.image"/>
536 <!-- ==================================================================== -->
538 <xsl:template match="d:mediaobject|d:mediaobjectco">
540 <xsl:variable name="olist" select="d:imageobject|d:imageobjectco
541 |d:videoobject|d:audioobject
544 <xsl:variable name="object.index">
545 <xsl:call-template name="select.mediaobject.index">
546 <xsl:with-param name="olist" select="$olist"/>
547 <xsl:with-param name="count" select="1"/>
551 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
553 <xsl:variable name="align">
554 <xsl:value-of select="$object/descendant::d:imagedata[@align][1]/@align"/>
557 <xsl:variable name="id">
558 <xsl:call-template name="object.id"/>
561 <fo:block id="{$id}">
562 <xsl:if test="$align != '' ">
563 <xsl:attribute name="text-align">
564 <xsl:value-of select="$align"/>
568 <xsl:apply-templates select="$object"/>
569 <xsl:apply-templates select="d:caption"/>
573 <xsl:template match="d:inlinemediaobject">
574 <xsl:call-template name="select.mediaobject"/>
577 <!-- ==================================================================== -->
579 <xsl:template match="d:imageobjectco">
581 <!-- select one imageobject? -->
582 <xsl:when test="$use.role.for.mediaobject != 0 and
583 count(d:imageobject) > 1 and
584 d:imageobject[@role]">
585 <xsl:variable name="olist" select="d:imageobject"/>
587 <xsl:variable name="object.index">
588 <xsl:call-template name="select.mediaobject.index">
589 <xsl:with-param name="olist" select="$olist"/>
590 <xsl:with-param name="count" select="1"/>
594 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
596 <xsl:apply-templates select="$object"/>
599 <!-- otherwise process them all -->
600 <xsl:apply-templates select="d:imageobject"/>
604 <xsl:apply-templates select="d:calloutlist"/>
608 <xsl:template match="d:imageobject">
610 <xsl:when test="d:imagedata">
611 <xsl:apply-templates select="d:imagedata"/>
614 <fo:instream-foreign-object>
615 <xsl:apply-templates mode="copy-all"/>
616 </fo:instream-foreign-object>
621 <!-- ==================================================================== -->
623 <xsl:template match="*" mode="copy-all">
625 <xsl:for-each select="@*">
628 <xsl:apply-templates mode="copy-all"/>
632 <xsl:template match="text()|comment()|processing-instruction()" mode="copy-all">
636 <xsl:template name="process.mml">
637 <xsl:apply-templates mode="copy-all" select="*"/>
640 <xsl:template name="process.svg">
641 <xsl:apply-templates mode="copy-all" select="*"/>
644 <!-- ==================================================================== -->
646 <xsl:template match="d:imagedata">
648 <xsl:when test="@format='linespecific'">
649 <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
651 <xsl:variable name="filename">
652 <xsl:call-template name="mediaobject.filename">
653 <xsl:with-param name="object" select=".."/>
658 <xsl:when test="$use.extensions != '0'
659 and $textinsert.extension != '0'">
661 <xsl:when test="contains($vendor, 'SAXON')">
662 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
664 <xsl:when test="contains($vendor, 'Apache Software Foundation')">
665 <xtext:insertfile href="{$filename}"/>
668 <xsl:message terminate="yes">
669 <xsl:text>Don't know how to insert files with </xsl:text>
670 <xsl:value-of select="$vendor"/>
676 <xsl:message terminate="yes">
677 <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
678 <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
684 <xsl:call-template name="process.image"/>
689 <!-- ==================================================================== -->
691 <xsl:template match="d:videoobject">
692 <xsl:apply-templates select="d:videodata"/>
695 <xsl:template match="d:videodata">
696 <xsl:call-template name="process.image"/>
699 <!-- ==================================================================== -->
701 <xsl:template match="d:audioobject">
702 <xsl:apply-templates select="d:audiodata"/>
705 <xsl:template match="d:audiodata">
706 <xsl:call-template name="process.image"/>
709 <!-- ==================================================================== -->
711 <xsl:template match="d:textobject">
712 <xsl:apply-templates/>
715 <xsl:template match="d:textdata">
716 <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
717 <xsl:variable name="filename">
719 <xsl:when test="@entityref">
720 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
723 <xsl:apply-templates select="@fileref"/>
728 <xsl:variable name="encoding">
730 <xsl:when test="@encoding">
731 <xsl:value-of select="@encoding"/>
734 <xsl:value-of select="$textdata.default.encoding"/>
740 <xsl:when test="$use.extensions != '0'
741 and $textinsert.extension != '0'">
743 <xsl:when test="element-available('stext:insertfile')">
744 <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
746 <xsl:when test="element-available('xtext:insertfile')">
747 <xtext:insertfile href="{$filename}"/>
750 <xsl:message terminate="yes">
751 <xsl:text>Don't know how to insert files with </xsl:text>
752 <xsl:value-of select="$vendor"/>
758 <xsl:message terminate="yes">
759 <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
760 <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
766 <!-- ==================================================================== -->
768 <xsl:template match="d:mediaobject/d:caption|d:figure/d:caption">
770 <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
771 <xsl:attribute name="text-align"><xsl:value-of
772 select="@align"/></xsl:attribute>
774 <xsl:apply-templates/>
778 <!-- ==================================================================== -->
780 <xsl:template name="fo-external-image">
781 <xsl:param name="filename"/>
784 <xsl:when test="$fop.extensions != 0">
785 <xsl:value-of select="$filename"/>
788 <xsl:value-of select="concat('url(', $filename, ')')"/>
793 <!-- Resolve xml:base attributes -->
794 <xsl:template match="@fileref">
795 <!-- need a check for absolute urls -->
797 <xsl:when test="contains(., ':') or starts-with(.,'/')">
798 <!-- it has a uri scheme or starts with '/', so it is an absolute uri -->
799 <xsl:value-of select="."/>
801 <xsl:when test="$keep.relative.image.uris != 0">
802 <!-- leave it alone -->
803 <xsl:value-of select="."/>
806 <!-- its a relative uri -->
807 <xsl:call-template name="relative-uri">