1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns:xlink="http://www.w3.org/1999/xlink"
4                xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
5                xmlns:xtext="com.nwalsh.xalan.Text"
6                xmlns:lxslt="http://xml.apache.org/xslt"
7                exclude-result-prefixes="xlink stext xtext lxslt"
8                extension-element-prefixes="stext xtext"
9                version='1.0'>
10
11<!-- ********************************************************************
12     $Id$
13     ********************************************************************
14
15     This file is part of the XSL DocBook Stylesheet distribution.
16     See /README or http://nwalsh.com/docbook/xsl/ for copyright
17     and other information.
18
19     Contributors:
20     Colin Paul Adams, <colin@colina.demon.co.uk>
21
22     ******************************************************************** -->
23
24<lxslt:component prefix="xtext"
25                 elements="insertfile"/>
26
27<!-- ==================================================================== -->
28<!-- Graphic format tests for the HTML backend -->
29
30<xsl:template name="is.graphic.format">
31  <xsl:param name="format"></xsl:param>
32  <xsl:if test="$format = 'PNG'
33                or $format = 'JPG'
34                or $format = 'JPEG'
35                or $format = 'linespecific'
36                or $format = 'GIF'
37                or $format = 'GIF87a'
38                or $format = 'GIF89a'
39                or $format = 'BMP'">1</xsl:if>
40</xsl:template>
41
42<xsl:template name="is.graphic.extension">
43  <xsl:param name="ext"></xsl:param>
44  <xsl:if test="$ext = 'png'
45                or $ext = 'jpeg'
46                or $ext = 'jpg'
47                or $ext = 'avi'
48                or $ext = 'mpg'
49                or $ext = 'mpeg'
50                or $ext = 'qt'
51                or $ext = 'gif'
52                or $ext = 'bmp'">1</xsl:if>
53</xsl:template>
54
55<!-- ==================================================================== -->
56
57<xsl:template match="screenshot">
58  <div class="{name(.)}">
59    <xsl:apply-templates/>
60  </div>
61</xsl:template>
62
63<xsl:template match="screeninfo">
64</xsl:template>
65
66<!-- ==================================================================== -->
67
68<xsl:template name="process.image">
69  <!-- When this template is called, the current node should be  -->
70  <!-- a graphic, inlinegraphic, imagedata, or videodata. All    -->
71  <!-- those elements have the same set of attributes, so we can -->
72  <!-- handle them all in one place.                             -->
73  <xsl:param name="tag" select="'img'"/>
74  <xsl:param name="alt"/>
75
76  <xsl:variable name="filename">
77    <xsl:choose>
78      <xsl:when test="local-name(.) = 'graphic'
79                      or local-name(.) = 'inlinegraphic'">
80        <xsl:choose>
81          <xsl:when test="@fileref">
82            <xsl:value-of select="@fileref"/>
83          </xsl:when>
84          <xsl:when test="@entityref">
85            <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
86          </xsl:when>
87          <xsl:otherwise>
88            <xsl:message>
89              <xsl:text>A fileref or entityref is required on </xsl:text>
90              <xsl:value-of select="local-name(.)"/>
91            </xsl:message>
92          </xsl:otherwise>
93        </xsl:choose>
94      </xsl:when>
95      <xsl:otherwise>
96        <!-- imagedata, videodata, audiodata -->
97        <xsl:call-template name="mediaobject.filename">
98          <xsl:with-param name="object" select=".."/>
99        </xsl:call-template>
100      </xsl:otherwise>
101    </xsl:choose>
102  </xsl:variable>
103
104  <xsl:variable name="width">
105    <xsl:choose>
106      <xsl:when test="@scale"><xsl:value-of select="@scale"/>%</xsl:when>
107      <xsl:when test="@width"><xsl:value-of select="@width"/></xsl:when>
108      <xsl:otherwise></xsl:otherwise>
109    </xsl:choose>
110  </xsl:variable>
111
112  <xsl:variable name="height">
113    <xsl:choose>
114      <xsl:when test="@scale"></xsl:when>
115      <xsl:when test="@depth"><xsl:value-of select="@depth"/></xsl:when>
116      <xsl:otherwise></xsl:otherwise>
117    </xsl:choose>
118  </xsl:variable>
119
120  <xsl:variable name="align">
121    <xsl:value-of select="@align"/>
122  </xsl:variable>
123
124  <xsl:element name="{$tag}">
125    <xsl:attribute name="src">
126      <xsl:value-of select="$filename"/>
127    </xsl:attribute>
128
129    <xsl:if test="$align != ''">
130      <xsl:attribute name="align">
131        <xsl:value-of select="$align"/>
132      </xsl:attribute>
133    </xsl:if>
134    <xsl:if test="$height != ''">
135      <xsl:attribute name="height">
136        <xsl:value-of select="$height"/>
137      </xsl:attribute>
138    </xsl:if>
139    <xsl:if test="$width != ''">
140      <xsl:attribute name="width">
141        <xsl:value-of select="$width"/>
142      </xsl:attribute>
143    </xsl:if>
144    <xsl:if test="$alt != ''">
145      <xsl:attribute name="alt">
146        <xsl:value-of select="$alt"/>
147      </xsl:attribute>
148    </xsl:if>
149  </xsl:element>
150</xsl:template>
151
152<!-- ==================================================================== -->
153
154<xsl:template match="graphic">
155  <p>
156    <xsl:call-template name="process.image"/>
157  </p>
158</xsl:template>
159
160<xsl:template match="inlinegraphic">
161  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
162  <xsl:variable name="filename">
163    <xsl:choose>
164      <xsl:when test="@entityref">
165        <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
166      </xsl:when>
167      <xsl:otherwise>
168        <xsl:value-of select="@fileref"/>
169      </xsl:otherwise>
170    </xsl:choose>
171  </xsl:variable>
172
173  <xsl:choose>
174    <xsl:when test="@format='linespecific'">
175      <xsl:choose>
176        <xsl:when test="$use.extensions != '0'
177                        and $textinsert.extension != '0'">
178          <xsl:choose>
179            <xsl:when test="contains($vendor, 'SAXON')">
180              <stext:insertfile href="{$filename}"/>
181            </xsl:when>
182            <xsl:when test="contains($vendor, 'Apache Software Foundation')">
183              <xtext:insertfile href="{$filename}"/>
184            </xsl:when>
185            <xsl:otherwise>
186              <xsl:message terminate="yes">
187                <xsl:text>Don't know how to insert files with </xsl:text>
188                <xsl:value-of select="$vendor"/>
189              </xsl:message>
190            </xsl:otherwise>
191          </xsl:choose>
192        </xsl:when>
193        <xsl:otherwise>
194          <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
195             href="{$filename}"/>
196        </xsl:otherwise>
197      </xsl:choose>
198    </xsl:when>
199    <xsl:otherwise>
200      <xsl:call-template name="process.image"/>
201    </xsl:otherwise>
202  </xsl:choose>
203</xsl:template>
204
205<!-- ==================================================================== -->
206
207<xsl:template match="mediaobject|mediaobjectco">
208  <div class="{name(.)}">
209    <xsl:call-template name="select.mediaobject"/>
210    <xsl:apply-templates select="caption"/>
211  </div>
212</xsl:template>
213
214<xsl:template match="inlinemediaobject">
215  <span class="{name(.)}">
216    <xsl:call-template name="select.mediaobject"/>
217  </span>
218</xsl:template>
219
220<!-- ==================================================================== -->
221
222<xsl:template match="imageobjectco">
223  <xsl:apply-templates select="imageobject"/>
224  <xsl:apply-templates select="calloutlist"/>
225</xsl:template>
226
227<xsl:template match="imageobject">
228  <xsl:apply-templates select="imagedata"/>
229</xsl:template>
230
231<xsl:template match="imagedata">
232  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
233  <xsl:variable name="filename">
234    <xsl:call-template name="mediaobject.filename">
235      <xsl:with-param name="object" select=".."/>
236    </xsl:call-template>
237  </xsl:variable>
238
239  <xsl:choose>
240    <xsl:when test="@format='linespecific'">
241      <xsl:choose>
242        <xsl:when test="$use.extensions != '0'
243                        and $textinsert.extension != '0'">
244          <xsl:choose>
245            <xsl:when test="contains($vendor, 'SAXON')">
246              <stext:insertfile href="{$filename}"/>
247            </xsl:when>
248            <xsl:when test="contains($vendor, 'Apache Software Foundation')">
249              <xtext:insertfile href="{$filename}"/>
250            </xsl:when>
251            <xsl:otherwise>
252              <xsl:message terminate="yes">
253                <xsl:text>Don't know how to insert files with </xsl:text>
254                <xsl:value-of select="$vendor"/>
255              </xsl:message>
256            </xsl:otherwise>
257          </xsl:choose>
258        </xsl:when>
259        <xsl:otherwise>
260          <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
261             href="{$filename}"/>
262        </xsl:otherwise>
263      </xsl:choose>
264    </xsl:when>
265    <xsl:otherwise>
266      <xsl:call-template name="process.image">
267        <xsl:with-param name="alt">
268          <xsl:apply-templates select="(/textobject/phrase)[1]"/>
269        </xsl:with-param>
270      </xsl:call-template>
271    </xsl:otherwise>
272  </xsl:choose>
273</xsl:template>
274
275<!-- ==================================================================== -->
276
277<xsl:template match="videoobject">
278  <xsl:apply-templates select="videodata"/>
279</xsl:template>
280
281<xsl:template match="videodata">
282  <xsl:call-template name="process.image">
283    <xsl:with-param name="tag" select="'embed'"/>
284    <xsl:with-param name="alt">
285      <xsl:apply-templates select="(/textobject/phrase)[1]"/>
286    </xsl:with-param>
287  </xsl:call-template>
288</xsl:template>
289
290<!-- ==================================================================== -->
291
292<xsl:template match="audioobject">
293  <xsl:apply-templates select="audiodata"/>
294</xsl:template>
295
296<xsl:template match="audiodata">
297  <xsl:call-template name="process.image">
298    <xsl:with-param name="tag" select="'embed'"/>
299    <xsl:with-param name="alt">
300      <xsl:apply-templates select="(/textobject/phrase)[1]"/>
301    </xsl:with-param>
302  </xsl:call-template>
303</xsl:template>
304
305<!-- ==================================================================== -->
306
307<xsl:template match="textobject">
308  <xsl:apply-templates/>
309</xsl:template>
310
311<!-- ==================================================================== -->
312
313<xsl:template match="caption">
314  <div class="{name(.)}">
315    <xsl:apply-templates/>
316  </div>
317</xsl:template>
318
319</xsl:stylesheet>
320