2 <!--#############################################################################
3 |- #############################################################################
5 | PURPOSE: Manage Imageobject related tags.
6 + ############################################################################## -->
9 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
11 exclude-result-prefixes="doc" version='1.0'>
15 <!--############################################################################# -->
16 <!-- DOCUMENTATION -->
17 <doc:reference id="mediaobject" xmlns="">
19 <releaseinfo role="meta">
22 <author> <firstname>Ramon</firstname> <surname>Casellas</surname> </author>
23 <author> <firstname>James</firstname> <surname>Devenish</surname> </author>
26 <year>2000</year> <year>2001</year> <year>2002</year> <year>2003</year>
27 <holder>Ramon Casellas</holder>
31 <title>MediaObjects <filename>mediaobject.mod.xsl</filename></title>
33 <section><title>Introduction</title>
41 <xsl:template match="videoobject">
42 <xsl:apply-templates select="videodata"/>
44 <xsl:template match="audioobject">
45 <xsl:apply-templates select="audiodata"/>
47 <xsl:template match="textobject">
48 <!-- TODO if mixed in with imageobjects, use subfigure (if appropriate) -->
49 <xsl:apply-templates/>
53 <xsl:template match="mediaobject">
54 <xsl:if test="local-name(preceding-sibling::*[1])!='mediaobject'">
55 <xsl:text> </xsl:text>
57 <xsl:call-template name="mediacontent"/>
58 <xsl:text> </xsl:text>
61 <xsl:template match="inlinemediaobject">
62 <xsl:call-template name="mediacontent"/>
65 <xsl:template name="mediacontent">
67 <xsl:when test="count(imageobject)<1">
68 <xsl:apply-templates select="textobject[1]"/>
70 <xsl:when test="$use.role.for.mediaobject='1' and $preferred.mediaobject.role!='' and count(imageobject[@role='$preferred.mediaobject.role'])!=0">
71 <xsl:apply-templates select="imageobject[@role=$preferred.mediaobject.role]"/>
73 <xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='latex'])!=0">
74 <xsl:apply-templates select="imageobject[@role='latex']"/>
76 <xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='tex'])!=0">
77 <xsl:apply-templates select="imageobject[@role='tex']"/>
79 <xsl:when test="$latex.graphics.formats!='' and count(imageobject/imagedata[@format!=''])!=0">
80 <!-- this is not really the right method: formats to the left of $latex.graphics.formats
81 should be given higher 'priority' than those to the right in a command-separated list -->
82 <xsl:variable name="formats" select="concat(',',$latex.graphics.formats,',')"/>
83 <xsl:variable name="candidates" select="imageobject/imagedata[contains($formats,concat(',',@format,','))]"/>
85 <xsl:when test="count($candidates)!=0">
86 <xsl:apply-templates select="$candidates[1]"/>
89 <xsl:variable name="fallbacks" select="imageobject/imagedata[@format='']"/>
91 <xsl:when test="count($fallbacks)!=0">
92 <xsl:apply-templates select="$fallbacks[1]"/>
94 <xsl:when test="count(textobject)!=0">
95 <xsl:apply-templates select="textobject[1]"/>
98 <xsl:apply-templates select="imageobject[1]"/>
105 <xsl:apply-templates select="imageobject[1]"/>
110 <xsl:template match="imageobject">
111 <xsl:apply-templates select="imagedata"/>
121 <!--############################################################################# -->
122 <!-- DOCUMENTATION -->
123 <doc:template match="imagedata" xmlns="">
124 <refpurpose>XSL template for images.</refpurpose>
127 <formalpara><title>Remarks and Bugs</title>
129 <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>
130 <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>
131 <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>
136 <!--############################################################################# -->
137 <xsl:template match="imagedata">
138 <xsl:variable name="filename" select="@fileref"/>
139 <xsl:variable name="ext">
140 <xsl:call-template name="filename-extension">
141 <xsl:with-param name="filename" select="$filename"/>
144 <xsl:variable name="imageobjectscnt" select="count(../../..//imageobject)"/>
145 <xsl:variable name="width">
147 <xsl:when test="contains(@width, '%') and substring-after(@width, '%')=''">
148 <xsl:value-of select="number(substring-before(@width, '%')) div 100"/>
149 <xsl:text>\textwidth</xsl:text>
152 <xsl:value-of select="@width"/>
156 <xsl:if test="$width!='' and (@scalefit='0' or count(@scale)>0)">
157 <xsl:text>\makebox[</xsl:text><xsl:value-of select='$width' /><xsl:text>]</xsl:text>
159 <xsl:text>{</xsl:text>
160 <!-- TODO this logic actually needs to make decisions based on the ALLOWED imagedata,
161 not all the imagedata present in the source file. -->
162 <xsl:if test="$imageobjectscnt > 1 and $latex.use.subfigure='1' and count(ancestor::figure) > 0">
163 <xsl:text>\subfigure[</xsl:text>
164 <xsl:if test="count(../../..//caption)>1">
165 <xsl:value-of select="../../caption"/>
167 <xsl:text>]</xsl:text>
169 <xsl:text>{\includegraphics[</xsl:text>
171 <xsl:when test="@scale">
172 <xsl:text>scale=</xsl:text>
173 <xsl:value-of select="number(@scale) div 100"/>
175 <xsl:when test="$width!='' and @scalefit='1'">
176 <xsl:text>width=</xsl:text><xsl:value-of select="normalize-space($width)"/>
178 <xsl:when test="@depth!='' and @scalefit='1'">
179 <xsl:text>height=</xsl:text><xsl:value-of select="normalize-space(@depth)"/>
183 <xsl:when test="@format = 'PRN'"><xsl:text>,angle=270</xsl:text></xsl:when>
185 <xsl:text>]{</xsl:text>
186 <xsl:choose><!-- package graphicx and DeclareGraphicExtensions will take care of this -->
187 <xsl:when test="$ext != ''">
188 <xsl:value-of select="$filename"/>
191 <xsl:value-of select="$filename"/>
194 <xsl:text>}}}</xsl:text>
199 <xsl:template match="videodata">
200 <xsl:variable name="filename">
201 <xsl:call-template name="mediaobject.filename"><xsl:with-param name="object" select=".."/>
204 <xsl:variable name="alt">
205 <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
209 <xsl:template match="audiodata">
210 <xsl:variable name="filename">
211 <xsl:call-template name="mediaobject.filename"><xsl:with-param name="object" select=".."/>
214 <xsl:variable name="alt">
215 <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
220 <xsl:template match="caption">
221 <xsl:apply-templates/>