source: branches/samba-3.2.x/docs-xml/xslt/db2latex-xsl/xsl/mediaobject.mod.xsl

Last change on this file was 203, checked in by Herwig Bauernfeind, 16 years ago

Missing 3.2.2 client and HOWTO files

File size: 13.0 KB
Line 
1<?xml version='1.0'?>
2<!DOCTYPE xsl:stylesheet [ <!ENTITY % xsldoc.ent SYSTEM "./xsldoc.ent"> %xsldoc.ent; ]>
3<!--#############################################################################
4| $Id: mediaobject.mod.xsl,v 1.22 2004/01/12 13:52:30 j-devenish Exp $
5|- #############################################################################
6| $Author: j-devenish $
7+ ############################################################################## -->
8
9<xsl:stylesheet
10 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
11 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
12 exclude-result-prefixes="doc" version='1.0'>
13
14 <doc:reference id="mediaobject" xmlns="">
15 <referenceinfo>
16 <releaseinfo role="meta">
17 $Id: mediaobject.mod.xsl,v 1.22 2004/01/12 13:52:30 j-devenish Exp $
18 </releaseinfo>
19 <authorgroup>
20 &ramon;
21 &james;
22 </authorgroup>
23 <copyright>
24 <year>2000</year><year>2001</year><year>2002</year><year>2003</year><year>2004</year>
25 <holder>Ramon Casellas</holder>
26 </copyright>
27 <revhistory>
28 <doc:revision rcasver="1.12">&rev_2003_05;</doc:revision>
29 </revhistory>
30 </referenceinfo>
31 <title>MediaObjects <filename>mediaobject.mod.xsl</filename></title>
32 <partintro>
33 <para>
34
35
36 </para>
37 </partintro>
38 </doc:reference>
39
40 <doc:template xmlns="">
41 <refpurpose>Process <doc:db>textobject</doc:db> elements</refpurpose>
42 <doc:description>
43 <para>
44 Applies templates.
45 </para>
46 </doc:description>
47 <doc:variables>
48 &no_var;
49 </doc:variables>
50 </doc:template>
51 <xsl:template match="textobject">
52 <!-- TODO if mixed in with imageobjects, use subfigure (if appropriate) -->
53 <xsl:apply-templates/>
54 </xsl:template>
55
56 <doc:template basename="mediaobject" xmlns="">
57 <refpurpose>Process <doc:db>mediaobject</doc:db> elements</refpurpose>
58 <doc:description>
59 <para>
60 Calls <xref linkend="template.mediacontent"/>.
61 </para>
62 </doc:description>
63 <doc:variables>
64 &no_var;
65 </doc:variables>
66 <doc:samples>
67 <simplelist type='inline'>
68 &test_subfig;
69 </simplelist>
70 </doc:samples>
71 </doc:template>
72 <xsl:template match="mediaobject">
73 <xsl:if test="local-name(preceding-sibling::*[1])!='mediaobject'">
74 <xsl:text>&#10;</xsl:text>
75 </xsl:if>
76 <xsl:call-template name="mediacontent"/>
77 <xsl:text>&#10;</xsl:text>
78 </xsl:template>
79
80 <doc:template basename="mediaobject" xmlns="">
81 <refpurpose>Process a <doc:db>para</doc:db>'s <doc:db>mediaobject</doc:db> elements</refpurpose>
82 <doc:description>
83 <para>
84 Formats a <doc:db>mediaobject</doc:db> as a block surrounded by paragraph text.
85 </para>
86 </doc:description>
87 <doc:variables>
88 &no_var;
89 </doc:variables>
90 <doc:notes>
91 <para>
92 Inserts newline characters around the output of <xref
93 linkend="template.mediacontent"/>.
94 </para>
95 </doc:notes>
96 </doc:template>
97 <xsl:template match="para/mediaobject">
98 <xsl:text>&#10;&#10;</xsl:text>
99 <xsl:call-template name="mediacontent"/>
100 <xsl:text>&#10;&#10;</xsl:text>
101 </xsl:template>
102
103 <doc:template xmlns="">
104 <refpurpose>Process <doc:db>inlinemediaobject</doc:db> elements</refpurpose>
105 <doc:description>
106 <para>
107 Applies templates.
108 </para>
109 </doc:description>
110 <doc:variables>
111 &no_var;
112 </doc:variables>
113 </doc:template>
114 <xsl:template match="inlinemediaobject">
115 <xsl:call-template name="mediacontent"/>
116 </xsl:template>
117
118 <doc:template xmlns="">
119 <refpurpose>Process media and inline media </refpurpose>
120 <doc:description>
121 <para>
122 Formats image media.
123 Would be good to be able to include text media, too,
124 so that mixed-content figures look proper.
125 </para>
126 </doc:description>
127 <doc:variables>
128 &no_var;
129 </doc:variables>
130 <doc:notes>
131 <para>
132 The template first attempts to obtain a count of the number
133 of media within this <doc:db>figure</doc:db>, if this is within a <sgmltag>figure</sgmltag>.
134 If the number of objects is greater than one, a <function condition="latex">subfigure</function>
135 command will be invoked with the contents of any <doc:db>caption</doc:db>.
136 If there are no <doc:db basename="imageobject">imageobjects</doc:db>, <doc:db basename="textobject">textobjects</doc:db>
137 will be selected.
138 Otherwise, the following algorithm will be used:
139 </para>
140 <procedure>
141 <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>
142 <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>
143 <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>
144 <step><simpara>Otherwise, the first <sgmltag>imageobject</sgmltag> is used regardless.</simpara></step>
145 </procedure>
146 </doc:notes>
147 </doc:template>
148 <xsl:template name="mediacontent">
149 <!--
150 <xsl:variable name="actualmediacnt" select="count(../../..//mediaobject[imageobject or textobject])"/>
151 -->
152 <xsl:variable name="actualmediacnt" select="count(../mediaobject)"/>
153 <xsl:if test="$actualmediacnt &gt; 1 and $latex.use.subfigure='1' and count(ancestor::figure) &gt; 0">
154 <xsl:text>\subfigure[</xsl:text>
155 <!-- TODO does subfigure stuff up with there are square brackets in here? -->
156 <xsl:if test="caption">
157 <xsl:apply-templates select="caption[1]"/>
158 </xsl:if>
159 <xsl:text>]</xsl:text>
160 </xsl:if>
161 <xsl:text>{</xsl:text>
162 <xsl:choose>
163 <xsl:when test="count(imageobject)&lt;1">
164 <xsl:apply-templates select="textobject[1]"/>
165 </xsl:when>
166 <xsl:when test="$use.role.for.mediaobject='1' and $preferred.mediaobject.role!='' and count(imageobject[@role=$preferred.mediaobject.role])!=0">
167 <xsl:apply-templates select="imageobject[@role=$preferred.mediaobject.role]"/>
168 </xsl:when>
169 <xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='latex'])!=0">
170 <xsl:apply-templates select="imageobject[@role='latex']"/>
171 </xsl:when>
172 <xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='tex'])!=0">
173 <xsl:apply-templates select="imageobject[@role='tex']"/>
174 </xsl:when>
175 <xsl:when test="$latex.graphics.formats!='' and count(imageobject/imagedata[@format!=''])!=0">
176 <!-- this is not really the right method: formats to the left of $latex.graphics.formats
177 should be given higher 'priority' than those to the right in a command-separated list -->
178 <xsl:variable name="formats" select="concat(',',$latex.graphics.formats,',')"/>
179 <xsl:variable name="candidates" select="imageobject/imagedata[contains($formats,concat(',',@format,','))]"/>
180 <xsl:choose>
181 <xsl:when test="count($candidates)!=0">
182 <xsl:apply-templates select="$candidates[1]"/>
183 </xsl:when>
184 <xsl:otherwise>
185 <xsl:variable name="fallbacks" select="imageobject/imagedata[@format='']"/>
186 <xsl:choose>
187 <xsl:when test="count($fallbacks)!=0">
188 <xsl:apply-templates select="$fallbacks[1]"/>
189 </xsl:when>
190 <xsl:when test="count(textobject)!=0">
191 <xsl:apply-templates select="textobject[1]"/>
192 </xsl:when>
193 <xsl:otherwise>
194 <xsl:apply-templates select="imageobject[1]"/>
195 </xsl:otherwise>
196 </xsl:choose>
197 </xsl:otherwise>
198 </xsl:choose>
199 </xsl:when>
200 <xsl:otherwise>
201 <xsl:apply-templates select="imageobject[1]"/>
202 </xsl:otherwise>
203 </xsl:choose>
204 <xsl:text>}</xsl:text>
205 </xsl:template>
206
207 <doc:template basename="imageobject" xmlns="">
208 <refpurpose>Process <doc:db>imageobject</doc:db> elements</refpurpose>
209 <doc:description>
210 <para>
211 Applies templates.
212 </para>
213 </doc:description>
214 <doc:variables>
215 &no_var;
216 </doc:variables>
217 </doc:template>
218 <xsl:template match="imageobject">
219 <xsl:apply-templates select="imagedata"/>
220 </xsl:template>
221
222 <doc:template xmlns="">
223 <refpurpose>Process <doc:db>imagedata</doc:db> elements</refpurpose>
224 <doc:description>
225 <para>
226 Formats a picture using <function condition="latex">includegraphics</function>.
227 </para>
228 </doc:description>
229 <doc:variables>
230 &no_var;
231 </doc:variables>
232 <doc:params>
233 <variablelist>
234 <varlistentry>
235 <term>filename</term>
236 <listitem><simpara>The file path to be passsed to <function
237 condition="latex">includegraphics</function>. By default,
238 the name of the graphics file is gathered from the <sgmltag
239 class="attribute">entityref</sgmltag> attribute, if it is
240 present, or otherwise from the <sgmltag
241 class="attribute">fileref</sgmltag> attribute.
242 Often with &LaTeX;, the <sgmltag class="attribute">fileref</sgmltag>
243 attribute need not end with any <quote>filename extension</quote>
244 (see <xref linkend="param.graphic.default.extension"/>).
245 </simpara></listitem>
246 </varlistentry>
247 </variablelist>
248 </doc:params>
249 <doc:notes>
250 <itemizedlist>
251 <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>
252 <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>
253 <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>
254 </itemizedlist>
255 <para>
256 For widths, those containing a percent symbol (<quote>%</quote>) will be
257 taken relative to the <function condition="latex">textwidth</function>.
258 </para>
259 <para>
260 The <quote>PRN</quote> value of the <sgmltag class="attribute">format</sgmltag> attribute is honoured.
261 </para>
262 </doc:notes>
263 <doc:seealso>
264 <itemizedlist>
265 <listitem><simpara>&mapping;</simpara></listitem>
266 <listitem><simpara><xref linkend="template.content-templates"/></simpara></listitem>
267 </itemizedlist>
268 </doc:seealso>
269 </doc:template>
270 <xsl:template match="imagedata" name="imagedata">
271 <xsl:param name="filename">
272 <xsl:choose>
273 <xsl:when test="@entityref">
274 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
275 </xsl:when>
276 <xsl:otherwise>
277 <xsl:value-of select="@fileref"/>
278 </xsl:otherwise>
279 </xsl:choose>
280 </xsl:param>
281 <xsl:param name="is.imageobjectco" select="false()"/>
282 <xsl:variable name="width">
283 <xsl:choose>
284 <xsl:when test="contains(@width, '%') and substring-after(@width, '%')=''">
285 <xsl:value-of select="number(substring-before(@width, '%')) div 100"/>
286 <xsl:text>\textwidth</xsl:text>
287 </xsl:when>
288 <xsl:otherwise>
289 <xsl:value-of select="@width"/>
290 </xsl:otherwise>
291 </xsl:choose>
292 </xsl:variable>
293 <xsl:if test="$width!='' and (@scalefit='0' or count(@scale)&gt;0)">
294 <xsl:text>\makebox[</xsl:text><xsl:value-of select='$width' /><xsl:text>]</xsl:text>
295 </xsl:if>
296 <!-- TODO this logic actually needs to make decisions based on the ALLOWED imagedata,
297 not all the imagedata present in the source file. -->
298 <xsl:choose>
299 <xsl:when test="$is.imageobjectco=1">
300 <xsl:text>{\begin{overpic}[</xsl:text>
301 </xsl:when>
302 <xsl:otherwise>
303 <xsl:text>{\includegraphics[</xsl:text>
304 </xsl:otherwise>
305 </xsl:choose>
306 <xsl:choose>
307 <xsl:when test="@scale">
308 <xsl:text>scale=</xsl:text>
309 <xsl:value-of select="number(@scale) div 100"/>
310 </xsl:when>
311 <xsl:when test="$width!='' and @scalefit='1'">
312 <xsl:text>width=</xsl:text><xsl:value-of select="normalize-space($width)"/>
313 </xsl:when>
314 <xsl:when test="@depth!='' and @scalefit='1'">
315 <xsl:text>height=</xsl:text><xsl:value-of select="normalize-space(@depth)"/>
316 </xsl:when>
317 </xsl:choose>
318 <xsl:choose>
319 <xsl:when test="@format = 'PRN'"><xsl:text>,angle=270</xsl:text></xsl:when>
320 </xsl:choose>
321 <xsl:text>]{</xsl:text>
322 <xsl:value-of select="$filename"/>
323 <xsl:choose>
324 <xsl:when test="$is.imageobjectco=1">
325 <xsl:text>}&#10;\calsscale&#10;</xsl:text>
326 <xsl:apply-templates select="ancestor::imageobjectco/areaspec//area"/>
327 <xsl:text>\end{overpic}}</xsl:text>
328 </xsl:when>
329 <xsl:otherwise>
330 <xsl:text>}}</xsl:text>
331 </xsl:otherwise>
332 </xsl:choose>
333 </xsl:template>
334
335 <doc:template xmlns="">
336 <refpurpose>Process <doc:db>caption</doc:db> elements</refpurpose>
337 <doc:description>
338 <para>
339 Applies templates.
340 </para>
341 </doc:description>
342 <doc:variables>
343 &no_var;
344 </doc:variables>
345 </doc:template>
346 <xsl:template match="caption">
347 <xsl:apply-templates/>
348 </xsl:template>
349
350</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.