summaryrefslogtreecommitdiff
path: root/docs-xml/xslt/db2latex-xsl/xsl/mediaobject.mod.xsl
blob: b0a0bc5bd41f2611a2ff43eeca386e4bd88b789b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?xml version='1.0'?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY % xsldoc.ent SYSTEM "./xsldoc.ent"> %xsldoc.ent; ]>
<!--############################################################################# 
|	$Id: mediaobject.mod.xsl,v 1.22 2004/01/12 13:52:30 j-devenish Exp $
|- #############################################################################
|	$Author: j-devenish $
+ ############################################################################## -->

<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
	exclude-result-prefixes="doc" version='1.0'>

	<doc:reference id="mediaobject" xmlns="">
		<referenceinfo>
			<releaseinfo role="meta">
				$Id: mediaobject.mod.xsl,v 1.22 2004/01/12 13:52:30 j-devenish Exp $
			</releaseinfo>
			<authorgroup>
				&ramon;
				&james;
			</authorgroup>
			<copyright>
				<year>2000</year><year>2001</year><year>2002</year><year>2003</year><year>2004</year>
				<holder>Ramon Casellas</holder>
			</copyright>
			<revhistory>
				<doc:revision rcasver="1.12">&rev_2003_05;</doc:revision>
			</revhistory>
		</referenceinfo>
		<title>MediaObjects <filename>mediaobject.mod.xsl</filename></title>
		<partintro>
			<para>
			
			
			</para>
		</partintro>
	</doc:reference>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>textobject</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="textobject">
		<!-- TODO if mixed in with imageobjects, use subfigure (if appropriate) -->
		<xsl:apply-templates/>
	</xsl:template>

	<doc:template basename="mediaobject" xmlns="">
		<refpurpose>Process <doc:db>mediaobject</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Calls <xref linkend="template.mediacontent"/>.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:samples>
			<simplelist type='inline'>
				&test_subfig;
			</simplelist>
		</doc:samples>
	</doc:template>
	<xsl:template match="mediaobject">
		<xsl:if test="local-name(preceding-sibling::*[1])!='mediaobject'">
			<xsl:text>&#10;</xsl:text>
		</xsl:if>
		<xsl:call-template name="mediacontent"/>
		<xsl:text>&#10;</xsl:text>
	</xsl:template>

	<doc:template basename="mediaobject" xmlns="">
		<refpurpose>Process a <doc:db>para</doc:db>'s <doc:db>mediaobject</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Formats a <doc:db>mediaobject</doc:db> as a block surrounded by paragraph text.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				Inserts newline characters around the output of <xref
				linkend="template.mediacontent"/>.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="para/mediaobject">
		<xsl:text>&#10;&#10;</xsl:text>
		<xsl:call-template name="mediacontent"/>
		<xsl:text>&#10;&#10;</xsl:text>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>inlinemediaobject</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="inlinemediaobject">
		<xsl:call-template name="mediacontent"/>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process media and inline media </refpurpose>
		<doc:description>
			<para>
				Formats image media.
				Would be good to be able to include text media, too,
				so that mixed-content figures look proper.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				The template first attempts to obtain a count of the number
				of media within this <doc:db>figure</doc:db>, if this is within a <sgmltag>figure</sgmltag>.
				If the number of objects is greater than one, a <function condition="latex">subfigure</function>
				command will be invoked with the contents of any <doc:db>caption</doc:db>.
				If there are no <doc:db basename="imageobject">imageobjects</doc:db>, <doc:db basename="textobject">textobjects</doc:db>
				will be selected.
				Otherwise, the following algorithm will be used:
			</para>
			<procedure>
				<step><simpara>If <xref linkend="param.use.role.for.mediaobject"/> is set and there is an <doc:db>imageobject</doc:db> with a <sgmltag class="attribute">role</sgmltag> equal to the current <xref linkend="param.preferred.mediaobject.role"/> then that object will be used.</simpara></step>
				<step><simpara>Otherwise, if <xref linkend="param.use.role.for.mediaobject"/> is set and there is an <sgmltag>imageobject</sgmltag> with a role of <quote>latex</quote> or <quote>tex</quote>, that object will be used.</simpara></step>
				<step><simpara>Otherwise, if <xref linkend="param.latex.graphics.formats"/> is set and there are <sgmltag>imagedata</sgmltag> with non-empty <sgmltag class="attribute">format</sgmltag> attributes, and at least one of them has a matching format, then the first one of those objects is used. If none match, then the first <sgmltag>imagedata</sgmltag> with an <emphasis>empty</emphasis> format is used. Otherwise, the first <doc:db>textobject</doc:db> is used.</simpara></step>
				<step><simpara>Otherwise, the first <sgmltag>imageobject</sgmltag> is used regardless.</simpara></step>
			</procedure>
		</doc:notes>
	</doc:template>
	<xsl:template name="mediacontent">
		<!--
		<xsl:variable name="actualmediacnt" select="count(../../..//mediaobject[imageobject or textobject])"/>
		-->
		<xsl:variable name="actualmediacnt" select="count(../mediaobject)"/>
		<xsl:if test="$actualmediacnt &gt; 1 and $latex.use.subfigure='1' and count(ancestor::figure) &gt; 0">
			<xsl:text>\subfigure[</xsl:text>
			<!-- TODO does subfigure stuff up with there are square brackets in here? -->
			<xsl:if test="caption">
				<xsl:apply-templates select="caption[1]"/>
			</xsl:if>
			<xsl:text>]</xsl:text>
		</xsl:if>
		<xsl:text>{</xsl:text>
		<xsl:choose>
			<xsl:when test="count(imageobject)&lt;1">
				<xsl:apply-templates select="textobject[1]"/>
			</xsl:when>
			<xsl:when test="$use.role.for.mediaobject='1' and $preferred.mediaobject.role!='' and count(imageobject[@role=$preferred.mediaobject.role])!=0">
				<xsl:apply-templates select="imageobject[@role=$preferred.mediaobject.role]"/>
			</xsl:when>
			<xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='latex'])!=0">
				<xsl:apply-templates select="imageobject[@role='latex']"/>
			</xsl:when>
			<xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='tex'])!=0">
				<xsl:apply-templates select="imageobject[@role='tex']"/>
			</xsl:when>
			<xsl:when test="$latex.graphics.formats!='' and count(imageobject/imagedata[@format!=''])!=0">
				<!-- this is not really the right method: formats to the left of $latex.graphics.formats
				should be given higher 'priority' than those to the right in a command-separated list -->
				<xsl:variable name="formats" select="concat(',',$latex.graphics.formats,',')"/>
				<xsl:variable name="candidates" select="imageobject/imagedata[contains($formats,concat(',',@format,','))]"/>
				<xsl:choose>
					<xsl:when test="count($candidates)!=0">
						<xsl:apply-templates select="$candidates[1]"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:variable name="fallbacks" select="imageobject/imagedata[@format='']"/>
						<xsl:choose>
							<xsl:when test="count($fallbacks)!=0">
								<xsl:apply-templates select="$fallbacks[1]"/>
							</xsl:when>
							<xsl:when test="count(textobject)!=0">
								<xsl:apply-templates select="textobject[1]"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:apply-templates select="imageobject[1]"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates select="imageobject[1]"/>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:text>}</xsl:text>
	</xsl:template>

	<doc:template basename="imageobject" xmlns="">
		<refpurpose>Process <doc:db>imageobject</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="imageobject">
		<xsl:apply-templates select="imagedata"/>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>imagedata</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Formats a picture using <function condition="latex">includegraphics</function>.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:params>
			<variablelist>
				<varlistentry>
					<term>filename</term>
					<listitem><simpara>The file path to be passsed to <function
					condition="latex">includegraphics</function>. By default,
					the name of the graphics file is gathered from the <sgmltag
					class="attribute">entityref</sgmltag> attribute, if it is
					present, or otherwise from the <sgmltag
					class="attribute">fileref</sgmltag> attribute.
					Often with &LaTeX;, the <sgmltag class="attribute">fileref</sgmltag>
					attribute need not end with any <quote>filename extension</quote>
					(see <xref linkend="param.graphic.default.extension"/>).
					</simpara></listitem>
				</varlistentry>
			</variablelist>
		</doc:params>
		<doc:notes>
			<itemizedlist>
				<listitem><para>If both <literal>@width</literal> and <literal>@scale</literal> are given but <literal>@scalefit='0'</literal>, whitespace is added to the left and right in order to match the specified width.</para></listitem>
				<listitem><para>If <literal>@width</literal> is given and either <literal>@scalefit=1</literal> or no <literal>@scale</literal> is given, then the image is scale to <literal>@width</literal>. Otherwise, <literal>@scale</literal> is used, if it is present.</para></listitem>
				<listitem><para>If this is not the only <literal>imagedata</literal> within the figure, this will be rendered as a 'subfigure', including the <literal>caption</literal> of its enclosing <literal>mediaobject</literal>.</para></listitem>
			</itemizedlist>
			<para>
				For widths, those containing a percent symbol (<quote>%</quote>) will be
				taken relative to the <function condition="latex">textwidth</function>.
			</para>
			<para>
				The <quote>PRN</quote> value of the <sgmltag class="attribute">format</sgmltag> attribute is honoured.
			</para>
		</doc:notes>
		<doc:seealso>
			<itemizedlist>
				<listitem><simpara>&mapping;</simpara></listitem>
				<listitem><simpara><xref linkend="template.content-templates"/></simpara></listitem>
			</itemizedlist>
		</doc:seealso>
	</doc:template>
	<xsl:template match="imagedata" name="imagedata">
		<xsl:param name="filename">
			<xsl:choose>
				<xsl:when test="@entityref">
					<xsl:value-of select="unparsed-entity-uri(@entityref)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="@fileref"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:param>
		<xsl:param name="is.imageobjectco" select="false()"/>
		<xsl:variable name="width">
			<xsl:choose>
				<xsl:when test="contains(@width, '%') and substring-after(@width, '%')=''">
					<xsl:value-of select="number(substring-before(@width, '%')) div 100"/>
					<xsl:text>\textwidth</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="@width"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:if test="$width!='' and (@scalefit='0' or count(@scale)&gt;0)">
			<xsl:text>\makebox[</xsl:text><xsl:value-of select='$width' /><xsl:text>]</xsl:text>
		</xsl:if>
		<!-- TODO this logic actually needs to make decisions based on the ALLOWED imagedata,
		not all the imagedata present in the source file. -->
		<xsl:choose>
			<xsl:when test="$is.imageobjectco=1">
				<xsl:text>{\begin{overpic}[</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>{\includegraphics[</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="@scale"> 
			<xsl:text>scale=</xsl:text>
			<xsl:value-of select="number(@scale) div 100"/>
			</xsl:when>
			<xsl:when test="$width!='' and @scalefit='1'">
			<xsl:text>width=</xsl:text><xsl:value-of select="normalize-space($width)"/>
			</xsl:when>
			<xsl:when test="@depth!='' and @scalefit='1'">
			<xsl:text>height=</xsl:text><xsl:value-of select="normalize-space(@depth)"/>
			</xsl:when>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="@format = 'PRN'"><xsl:text>,angle=270</xsl:text></xsl:when>
		</xsl:choose>
		<xsl:text>]{</xsl:text>
		<xsl:value-of select="$filename"/>
		<xsl:choose>
			<xsl:when test="$is.imageobjectco=1">
				<xsl:text>}&#10;\calsscale&#10;</xsl:text>
				<xsl:apply-templates select="ancestor::imageobjectco/areaspec//area"/>
				<xsl:text>\end{overpic}}</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>}}</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>caption</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="caption">
		<xsl:apply-templates/>
	</xsl:template>

</xsl:stylesheet>