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 + ############################################################################## -->
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'>
14 <doc:reference id="mediaobject" xmlns="">
16 <releaseinfo role="meta">
17 $Id: mediaobject.mod.xsl,v 1.22 2004/01/12 13:52:30 j-devenish Exp $
24 <year>2000</year><year>2001</year><year>2002</year><year>2003</year><year>2004</year>
25 <holder>Ramon Casellas</holder>
28 <doc:revision rcasver="1.12">&rev_2003_05;</doc:revision>
31 <title>MediaObjects <filename>mediaobject.mod.xsl</filename></title>
40 <doc:template xmlns="">
41 <refpurpose>Process <doc:db>textobject</doc:db> elements</refpurpose>
51 <xsl:template match="textobject">
52 <!-- TODO if mixed in with imageobjects, use subfigure (if appropriate) -->
53 <xsl:apply-templates/>
56 <doc:template basename="mediaobject" xmlns="">
57 <refpurpose>Process <doc:db>mediaobject</doc:db> elements</refpurpose>
60 Calls <xref linkend="template.mediacontent"/>.
67 <simplelist type='inline'>
72 <xsl:template match="mediaobject">
73 <xsl:if test="local-name(preceding-sibling::*[1])!='mediaobject'">
74 <xsl:text> </xsl:text>
76 <xsl:call-template name="mediacontent"/>
77 <xsl:text> </xsl:text>
80 <doc:template basename="mediaobject" xmlns="">
81 <refpurpose>Process a <doc:db>para</doc:db>'s <doc:db>mediaobject</doc:db> elements</refpurpose>
84 Formats a <doc:db>mediaobject</doc:db> as a block surrounded by paragraph text.
92 Inserts newline characters around the output of <xref
93 linkend="template.mediacontent"/>.
97 <xsl:template match="para/mediaobject">
98 <xsl:text> </xsl:text>
99 <xsl:call-template name="mediacontent"/>
100 <xsl:text> </xsl:text>
103 <doc:template xmlns="">
104 <refpurpose>Process <doc:db>inlinemediaobject</doc:db> elements</refpurpose>
114 <xsl:template match="inlinemediaobject">
115 <xsl:call-template name="mediacontent"/>
118 <doc:template xmlns="">
119 <refpurpose>Process media and inline media </refpurpose>
123 Would be good to be able to include text media, too,
124 so that mixed-content figures look proper.
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>
138 Otherwise, the following algorithm will be used:
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>
148 <xsl:template name="mediacontent">
150 <xsl:variable name="actualmediacnt" select="count(../../..//mediaobject[imageobject or textobject])"/>
152 <xsl:variable name="actualmediacnt" select="count(../mediaobject)"/>
153 <xsl:if test="$actualmediacnt > 1 and $latex.use.subfigure='1' and count(ancestor::figure) > 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]"/>
159 <xsl:text>]</xsl:text>
161 <xsl:text>{</xsl:text>
163 <xsl:when test="count(imageobject)<1">
164 <xsl:apply-templates select="textobject[1]"/>
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]"/>
169 <xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='latex'])!=0">
170 <xsl:apply-templates select="imageobject[@role='latex']"/>
172 <xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='tex'])!=0">
173 <xsl:apply-templates select="imageobject[@role='tex']"/>
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,','))]"/>
181 <xsl:when test="count($candidates)!=0">
182 <xsl:apply-templates select="$candidates[1]"/>
185 <xsl:variable name="fallbacks" select="imageobject/imagedata[@format='']"/>
187 <xsl:when test="count($fallbacks)!=0">
188 <xsl:apply-templates select="$fallbacks[1]"/>
190 <xsl:when test="count(textobject)!=0">
191 <xsl:apply-templates select="textobject[1]"/>
194 <xsl:apply-templates select="imageobject[1]"/>
201 <xsl:apply-templates select="imageobject[1]"/>
204 <xsl:text>}</xsl:text>
207 <doc:template basename="imageobject" xmlns="">
208 <refpurpose>Process <doc:db>imageobject</doc:db> elements</refpurpose>
218 <xsl:template match="imageobject">
219 <xsl:apply-templates select="imagedata"/>
222 <doc:template xmlns="">
223 <refpurpose>Process <doc:db>imagedata</doc:db> elements</refpurpose>
226 Formats a picture using <function condition="latex">includegraphics</function>.
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>
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>
256 For widths, those containing a percent symbol (<quote>%</quote>) will be
257 taken relative to the <function condition="latex">textwidth</function>.
260 The <quote>PRN</quote> value of the <sgmltag class="attribute">format</sgmltag> attribute is honoured.
265 <listitem><simpara>&mapping;</simpara></listitem>
266 <listitem><simpara><xref linkend="template.content-templates"/></simpara></listitem>
270 <xsl:template match="imagedata" name="imagedata">
271 <xsl:param name="filename">
273 <xsl:when test="@entityref">
274 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
277 <xsl:value-of select="@fileref"/>
281 <xsl:param name="is.imageobjectco" select="false()"/>
282 <xsl:variable name="width">
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>
289 <xsl:value-of select="@width"/>
293 <xsl:if test="$width!='' and (@scalefit='0' or count(@scale)>0)">
294 <xsl:text>\makebox[</xsl:text><xsl:value-of select='$width' /><xsl:text>]</xsl:text>
296 <!-- TODO this logic actually needs to make decisions based on the ALLOWED imagedata,
297 not all the imagedata present in the source file. -->
299 <xsl:when test="$is.imageobjectco=1">
300 <xsl:text>{\begin{overpic}[</xsl:text>
303 <xsl:text>{\includegraphics[</xsl:text>
307 <xsl:when test="@scale">
308 <xsl:text>scale=</xsl:text>
309 <xsl:value-of select="number(@scale) div 100"/>
311 <xsl:when test="$width!='' and @scalefit='1'">
312 <xsl:text>width=</xsl:text><xsl:value-of select="normalize-space($width)"/>
314 <xsl:when test="@depth!='' and @scalefit='1'">
315 <xsl:text>height=</xsl:text><xsl:value-of select="normalize-space(@depth)"/>
319 <xsl:when test="@format = 'PRN'"><xsl:text>,angle=270</xsl:text></xsl:when>
321 <xsl:text>]{</xsl:text>
322 <xsl:value-of select="$filename"/>
324 <xsl:when test="$is.imageobjectco=1">
325 <xsl:text>} \calsscale </xsl:text>
326 <xsl:apply-templates select="ancestor::imageobjectco/areaspec//area"/>
327 <xsl:text>\end{overpic}}</xsl:text>
330 <xsl:text>}}</xsl:text>
335 <doc:template xmlns="">
336 <refpurpose>Process <doc:db>caption</doc:db> elements</refpurpose>
346 <xsl:template match="caption">
347 <xsl:apply-templates/>