Debian Codegraph @

xsl/xslodt/dita2odt-img.xsl

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- This file is part of the DITA Open Toolkit project hosted on
3 Sourceforge.net. See the accompanying license.txt file for
4 applicable licenses.-->
5 <!-- (c) Copyright IBM Corp. 2005, 2006 All Rights Reserved. -->
6 <!--
7 <draw:frame text:anchor-type="as-char"
8 svg:width="6in" svg:height="3.2736in" draw:z-index="0">
9 <draw:image xlink:href="Pictures/100000000000027A0000015A35A01F85.jpg"
10 xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
11 </draw:frame>
12
13 -->
14 <xsl:stylesheet
15 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
16 xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
17 xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
18 xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
19 xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
20 xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
21 xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
22 xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
23 xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
24 xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
25 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
26 xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
27 xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
28 xmlns:math="http://www.w3.org/1998/Math/MathML"
29 xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
30 xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
31 xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms"
32 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
33 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
34 xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0"
35 xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
36 xmlns:prodtools="http://www.ibm.com/xmlns/prodtools"
37 version="1.0"
38 xmlns:java="org.dita.dost.util.ImgUtils" exclude-result-prefixes="java">
39
40 <xsl:output method="xml"/>
41 <xsl:output indent="yes"/>
42 <xsl:strip-space elements="*"/>
43
44 <xsl:template match="*[contains(@class,' topic/image ')]">
45 <xsl:if test="@href and not(@href='')">
46
47 <!-- image meta data -->
48 <xsl:variable name="type">
49 <xsl:choose>
50 <xsl:when test="not(contains(@href,'://'))">
51 <xsl:value-of select="java:getType(string(@href))"/>
52 </xsl:when>
53 <xsl:otherwise/>
54 </xsl:choose>
55 </xsl:variable>
56 <xsl:variable name="scale">
57 <xsl:choose>
58 <xsl:when test="@scale">
59 <xsl:value-of select="@scale div 100"/>
60 </xsl:when>
61 <xsl:otherwise>1</xsl:otherwise>
62 </xsl:choose>
63 </xsl:variable>
64 <xsl:variable name="height">
65 <xsl:choose>
66 <xsl:when test="@height">
67 <xsl:choose>
68 <xsl:when test="contains(@height, 'in')">
69 <xsl:value-of select="substring-before(@height, 'in') * $scale"/>
70 </xsl:when>
71 <xsl:when test="contains(@height, 'cm')">
72 <xsl:value-of select="number(round(substring-before(@height, 'cm') div 2.54)) * $scale"/>
73 </xsl:when>
74 <xsl:when test="contains(@height, 'mm')">
75 <xsl:value-of select="number(round(substring-before(@height, 'mm') div 25.4)) * $scale"/>
76 </xsl:when>
77 <xsl:when test="contains(@height, 'pt')">
78 <xsl:value-of select="number(round(substring-before(@height, 'pt') div 72)) * $scale"/>
79 </xsl:when>
80 <xsl:when test="contains(@height, 'pc')">
81 <xsl:value-of select="number(round(substring-before(@height, 'pc') div 6)) * $scale"/>
82 </xsl:when>
83 <xsl:when test="contains(@height, 'px')">
84 <xsl:value-of select="number(round(substring-before(@height, 'px') div 96)) * $scale"/>
85 </xsl:when>
86 <xsl:when test="contains(@height, 'em')">
87 <xsl:value-of select="number(round(substring-before(@height, 'em') div 6)) * $scale"/>
88 </xsl:when>
89 <!-- default is px -->
90 <xsl:otherwise>
91 <xsl:value-of select="number(@height div 96) * $scale"/>
92 </xsl:otherwise>
93 </xsl:choose>
94 </xsl:when>
95 <xsl:when test="not(contains(@href,'://'))">
96 <xsl:value-of select="number(java:getHeightODT($OUTPUTDIR, string(@href)) div 96) * $scale"/>
97 </xsl:when>
98 <xsl:otherwise/>
99 </xsl:choose>
100 </xsl:variable>
101 <xsl:variable name="width">
102 <xsl:choose>
103 <xsl:when test="@width">
104 <xsl:choose>
105 <xsl:when test="contains(@width, 'in')">
106 <xsl:value-of select="substring-before(@width, 'in') * $scale"/>
107 </xsl:when>
108 <xsl:when test="contains(@width, 'cm')">
109 <xsl:value-of select="number(round(substring-before(@width, 'cm') div 2.54)) * $scale"/>
110 </xsl:when>
111 <xsl:when test="contains(@width, 'mm')">
112 <xsl:value-of select="number(round(substring-before(@width, 'mm') div 25.4)) * $scale"/>
113 </xsl:when>
114 <xsl:when test="contains(@width, 'pt')">
115 <xsl:value-of select="number(round(substring-before(@width, 'pt') div 72)) * $scale"/>
116 </xsl:when>
117 <xsl:when test="contains(@width, 'pc')">
118 <xsl:value-of select="number(round(substring-before(@width, 'pc') div 6)) * $scale"/>
119 </xsl:when>
120 <xsl:when test="contains(@width, 'px')">
121 <xsl:value-of select="number(round(substring-before(@width, 'px') div 96)) * $scale"/>
122 </xsl:when>
123 <xsl:when test="contains(@width, 'em')">
124 <xsl:value-of select="number(round(substring-before(@width, 'em') div 6)) * $scale"/>
125 </xsl:when>
126 <!-- default is px -->
127 <xsl:otherwise>
128 <xsl:value-of select="number(@width div 96) * $scale"/>
129 </xsl:otherwise>
130 </xsl:choose>
131 </xsl:when>
132 <xsl:when test="not(contains(@href,'://'))">
133 <xsl:value-of select="number(java:getWidthODT($OUTPUTDIR, string(@href)) div 96) * $scale"/>
134 </xsl:when>
135 <xsl:otherwise/>
136 </xsl:choose>
137 </xsl:variable>
138
139 <xsl:choose>
140 <!-- nested by body or list -->
141 <xsl:when test="parent::*[contains(@class, ' topic/body ')] or
142 parent::*[contains(@class, ' topic/li ')] or parent::*[contains(@class, ' topic/sli ')]">
143 <xsl:element name="text:p">
144 <xsl:element name="text:span">
145 <xsl:choose>
146 <xsl:when test="parent::fig[contains(@frame,'top ')]">
147 <!-- NOP if there is already a break implied by a parent property -->
148 </xsl:when>
149 <xsl:otherwise>
150 <xsl:choose>
151 <xsl:when test="(@placement='break')">
152 <!-- start add flagging styles -->
153 <xsl:apply-templates select="." mode="start-add-odt-flags"/>
154 </xsl:when>
155 <xsl:otherwise>
156 <xsl:call-template name="flagcheck"/>
157 </xsl:otherwise>
158 </xsl:choose>
159 </xsl:otherwise>
160 </xsl:choose>
161
162 <xsl:call-template name="draw_image">
163 <xsl:with-param name="height" select="$height"/>
164 <xsl:with-param name="type" select="$type"/>
165 <xsl:with-param name="width" select="$width"/>
166 </xsl:call-template>
167
168 <!-- end add flagging styles -->
169 <xsl:apply-templates select="." mode="end-add-odt-flags"/>
170 </xsl:element>
171 </xsl:element>
172 </xsl:when>
173 <!-- nested by entry -->
174 <xsl:when test="parent::*[contains(@class, ' topic/entry ')]">
175 <!-- create p tag -->
176 <xsl:element name="text:p">
177 <xsl:element name="text:span">
178 <xsl:choose>
179 <xsl:when test="parent::fig[contains(@frame,'top ')]">
180 <!-- NOP if there is already a break implied by a parent property -->
181 </xsl:when>
182 <xsl:otherwise>
183 <xsl:choose>
184 <xsl:when test="(@placement='break')">
185 <!-- start add flagging styles -->
186 <xsl:apply-templates select="." mode="start-add-odt-flags"/>
187 </xsl:when>
188 <xsl:otherwise>
189 <xsl:call-template name="flagcheck"/>
190 </xsl:otherwise>
191 </xsl:choose>
192 </xsl:otherwise>
193 </xsl:choose>
194
195 <xsl:call-template name="draw_image">
196 <xsl:with-param name="height" select="$height"/>
197 <xsl:with-param name="type" select="$type"/>
198 <xsl:with-param name="width" select="$width"/>
199 </xsl:call-template>
200
201 <!-- end add flagging styles -->
202 <xsl:apply-templates select="." mode="end-add-odt-flags"/>
203 </xsl:element>
204 </xsl:element>
205 </xsl:when>
206 <!-- nested by stentry -->
207 <xsl:when test="parent::*[contains(@class, ' topic/stentry ')]">
208 <xsl:element name="text:p">
209 <xsl:element name="text:span">
210 <xsl:choose>
211 <xsl:when test="parent::fig[contains(@frame,'top ')]">
212 <!-- NOP if there is already a break implied by a parent property -->
213 </xsl:when>
214 <xsl:otherwise>
215 <xsl:choose>
216 <xsl:when test="(@placement='break')">
217 <!-- start add flagging styles -->
218 <xsl:apply-templates select="." mode="start-add-odt-flags"/>
219 </xsl:when>
220 <xsl:otherwise>
221 <xsl:call-template name="flagcheck"/>
222 </xsl:otherwise>
223 </xsl:choose>
224 </xsl:otherwise>
225 </xsl:choose>
226
227 <xsl:call-template name="draw_image">
228 <xsl:with-param name="height" select="$height"/>
229 <xsl:with-param name="type" select="$type"/>
230 <xsl:with-param name="width" select="$width"/>
231 </xsl:call-template>
232
233 <!-- end add flagging styles -->
234 <xsl:apply-templates select="." mode="end-add-odt-flags"/>
235 </xsl:element>
236 </xsl:element>
237 </xsl:when>
238 <!-- nested by other tags -->
239 <xsl:otherwise>
240 <xsl:element name="text:span">
241 <xsl:choose>
242 <xsl:when test="parent::fig[contains(@frame,'top ')]">
243 <!-- NOP if there is already a break implied by a parent property -->
244 </xsl:when>
245 <xsl:otherwise>
246 <xsl:choose>
247 <xsl:when test="(@placement='break')">
248 <!-- start add flagging styles -->
249 <xsl:apply-templates select="." mode="start-add-odt-flags"/>
250 </xsl:when>
251 <xsl:otherwise>
252 <xsl:call-template name="flagcheck"/>
253 </xsl:otherwise>
254 </xsl:choose>
255 </xsl:otherwise>
256 </xsl:choose>
257
258 <xsl:call-template name="draw_image">
259 <xsl:with-param name="height" select="$height"/>
260 <xsl:with-param name="type" select="$type"/>
261 <xsl:with-param name="width" select="$width"/>
262 </xsl:call-template>
263
264 <!-- end add flagging styles -->
265 <xsl:apply-templates select="." mode="end-add-odt-flags"/>
266 </xsl:element>
267 </xsl:otherwise>
268 </xsl:choose>
269
270 </xsl:if>
271 </xsl:template>
272
273 <xsl:template name="draw_image">
274 <xsl:param name="type"/>
275 <xsl:param name="height"/>
276 <xsl:param name="width"/>
277
278 <xsl:choose>
279 <xsl:when test="not(contains(@href,'://')) and $type and not($type='other') and ($height &gt; 0) and ($width &gt; 0)">
280 <xsl:element name="draw:frame">
281 <xsl:attribute name="text:anchor-type">as-char</xsl:attribute>
282 <xsl:attribute name="svg:y">-0.1in</xsl:attribute>
283 <xsl:attribute name="svg:width">
284 <xsl:choose>
285 <xsl:when test="$width &gt; 6">6</xsl:when>
286 <xsl:otherwise>
287 <xsl:value-of select="$width"/>
288 </xsl:otherwise>
289 </xsl:choose>
290 <xsl:value-of select="'in'"/>
291 </xsl:attribute>
292 <xsl:attribute name="svg:height"><xsl:value-of select="$height"/>in</xsl:attribute>
293 <xsl:element name="draw:image">
294 <xsl:choose>
295 <xsl:when test="$ODTIMGEMBED = 'yes'">
296 <xsl:element name="office:binary-data">
297 <xsl:value-of select="java:getBASE64($OUTPUTDIR, string(@href))" disable-output-escaping="yes"/>
298 </xsl:element>
299 </xsl:when>
300 <xsl:otherwise>
301 <xsl:attribute name="xlink:href">
302 <xsl:value-of select="translate(@href, '\', '/')"/>
303 </xsl:attribute>
304 </xsl:otherwise>
305 </xsl:choose>
306 </xsl:element>
307 </xsl:element>
308 </xsl:when>
309 <xsl:otherwise>
310 <xsl:element name="text:a">
311 <xsl:attribute name="xlink:href">
312 <xsl:value-of select="translate(@href, '\', '/')"/>
313 </xsl:attribute>
314 <xsl:attribute name="xlink:type">simple</xsl:attribute>
315 <xsl:call-template name="gen-img-txt"/>
316 </xsl:element>
317 </xsl:otherwise>
318 </xsl:choose>
319 </xsl:template>
320
321
322 <xsl:template name="draw_image_odt">
323 <xsl:param name="type"/>
324 <xsl:param name="height"/>
325 <xsl:param name="width"/>
326 <xsl:param name="imgsrc"/>
327 <xsl:param name="alttext"/>
328 <xsl:choose>
329 <xsl:when test="not(contains($imgsrc,'://')) and $type and not($type='other') and ($height &gt; 0) and ($width &gt; 0)">
330 <xsl:element name="draw:frame">
331 <xsl:attribute name="text:anchor-type">as-char</xsl:attribute>
332 <xsl:attribute name="svg:y">-0.1in</xsl:attribute>
333 <xsl:attribute name="svg:width">
334 <xsl:choose>
335 <xsl:when test="$width &gt; 6">6</xsl:when>
336 <xsl:otherwise>
337 <xsl:value-of select="$width"/>
338 </xsl:otherwise>
339 </xsl:choose>
340 <xsl:value-of select="'in'"/>
341 </xsl:attribute>
342 <xsl:attribute name="svg:height"><xsl:value-of select="$height"/>in</xsl:attribute>
343 <xsl:element name="draw:image">
344 <xsl:choose>
345 <xsl:when test="$ODTIMGEMBED = 'yes'">
346 <xsl:element name="office:binary-data">
347 <xsl:value-of select="java:getBASE64($OUTPUTDIR, string($imgsrc))" disable-output-escaping="yes"/>
348 </xsl:element>
349 </xsl:when>
350 <xsl:otherwise>
351 <xsl:attribute name="xlink:href">
352 <xsl:value-of select="translate($imgsrc, '\', '/')"/>
353 </xsl:attribute>
354 </xsl:otherwise>
355 </xsl:choose>
356 </xsl:element>
357 </xsl:element>
358 </xsl:when>
359 <xsl:otherwise>
360 <xsl:element name="text:span">
361 <!--
362 <xsl:attribute name="xlink:href">
363 <xsl:value-of select="translate($imgsrc, '\', '/')"/>
364 </xsl:attribute>
365 <xsl:attribute name="xlink:type">simple</xsl:attribute>
366 -->
367 <xsl:call-template name="gen-img-txt">
368 <xsl:with-param name="alttext" select="$alttext"/>
369 </xsl:call-template>
370 </xsl:element>
371 </xsl:otherwise>
372 </xsl:choose>
373 </xsl:template>
374
375
376 <xsl:template name="gen-img-txt">
377 <xsl:param name="alttext"/>
378 <xsl:choose>
379 <xsl:when test="$alttext != ''">
380 <xsl:call-template name="getStringODT">
381 <xsl:with-param name="stringName" select="$alttext"/>
382 </xsl:call-template>
383 </xsl:when>
384 <xsl:when test="*[contains(@class,' topic/alt ')]">
385 <xsl:value-of select="*[contains(@class,' topic/alt ')]"/>
386 </xsl:when>
387
388 <xsl:when test="startflag/alt-text">
389 <xsl:value-of select="startflag/alt-text"/>
390 </xsl:when>
391
392 <xsl:when test="@alt and not(@alt='')">
393 <xsl:value-of select="@alt"/>
394 </xsl:when>
395 <xsl:when test="text() or *">
396 <xsl:apply-templates/>
397 </xsl:when>
398 <xsl:when test="@href">
399 <xsl:value-of select="@href"/>
400 </xsl:when>
401 <xsl:otherwise/>
402
403 </xsl:choose>
404
405 </xsl:template>
406
407 </xsl:stylesheet>