2 <!--#############################################################################
3 | $Id: mediaobject.mod.xsl,v 1.1.2.1 2003/05/01 14:06:15 jelmer Exp $
4 |- #############################################################################
7 | PURPOSE: Manage Imageobject related tags.
8 + ############################################################################## -->
11 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
12 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
13 exclude-result-prefixes="doc" version='1.0'>
17 <!--############################################################################# -->
18 <!-- DOCUMENTATION -->
19 <doc:reference id="mediaobject" xmlns="">
21 <releaseinfo role="meta">
22 $Id: mediaobject.mod.xsl,v 1.1.2.1 2003/05/01 14:06:15 jelmer Exp $
25 <author> <firstname>Ramon</firstname> <surname>Casellas</surname> </author>
26 <author> <firstname>James</firstname> <surname>Devenish</surname> </author>
29 <year>2000</year> <year>2001</year> <year>2002</year> <year>2003</year>
30 <holder>Ramon Casellas</holder>
34 <title>MediaObjects <filename>mediaobject.mod.xsl</filename></title>
36 <section><title>Introduction</title>
44 <xsl:template match="videoobject">
45 <xsl:apply-templates select="videodata"/>
47 <xsl:template match="audioobject">
48 <xsl:apply-templates select="audiodata"/>
50 <xsl:template match="textobject">
51 <!-- TODO if mixed in with imageobjects, use subfigure (if appropriate) -->
52 <xsl:apply-templates/>
56 <xsl:template match="mediaobject">
57 <xsl:if test="local-name(preceding-sibling::*[1])!='mediaobject'">
58 <xsl:text> </xsl:text>
60 <xsl:call-template name="mediacontent"/>
61 <xsl:text> </xsl:text>
64 <xsl:template match="inlinemediaobject">
65 <xsl:call-template name="mediacontent"/>
68 <xsl:template name="mediacontent">
70 <xsl:when test="count(imageobject)<1">
71 <xsl:apply-templates select="textobject[1]"/>
73 <xsl:when test="$use.role.for.mediaobject='1' and $preferred.mediaobject.role!='' and count(imageobject[@role='$preferred.mediaobject.role'])!=0">
74 <xsl:apply-templates select="imageobject[@role=$preferred.mediaobject.role]"/>
76 <xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='latex'])!=0">
77 <xsl:apply-templates select="imageobject[@role='latex']"/>
79 <xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='tex'])!=0">
80 <xsl:apply-templates select="imageobject[@role='tex']"/>
82 <xsl:when test="$latex.graphics.formats!='' and count(imageobject/imagedata[@format!=''])!=0">
83 <!-- this is not really the right method: formats to the left of $latex.graphics.formats
84 should be given higher 'priority' than those to the right in a command-separated list -->
85 <xsl:variable name="formats" select="concat(',',$latex.graphics.formats,',')"/>
86 <xsl:variable name="candidates" select="imageobject/imagedata[contains($formats,concat(',',@format,','))]"/>
88 <xsl:when test="count($candidates)!=0">
89 <xsl:apply-templates select="$candidates[1]"/>
92 <xsl:variable name="fallbacks" select="imageobject/imagedata[@format='']"/>
94 <xsl:when test="count($fallbacks)!=0">
95 <xsl:apply-templates select="$fallbacks[1]"/>
97 <xsl:when test="count(textobject)!=0">
98 <xsl:apply-templates select="textobject[1]"/>
101 <xsl:apply-templates select="imageobject[1]"/>
108 <xsl:apply-templates select="imageobject[1]"/>
113 <xsl:template match="imageobject">
114 <xsl:apply-templates select="imagedata"/>
124 <!--############################################################################# -->
125 <!-- DOCUMENTATION -->
126 <doc:template match="imagedata" xmlns="">
127 <refpurpose>XSL template for images.</refpurpose>
130 <formalpara><title>Remarks and Bugs</title>
132 <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>
133 <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>
134 <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>
139 <!--############################################################################# -->
140 <xsl:template match="imagedata">
141 <xsl:variable name="filename" select="@fileref"/>
142 <xsl:variable name="ext">
143 <xsl:call-template name="filename-extension">
144 <xsl:with-param name="filename" select="$filename"/>
147 <xsl:variable name="imageobjectscnt" select="count(../../..//imageobject)"/>
148 <xsl:variable name="width">
150 <xsl:when test="contains(@width, '%') and substring-after(@width, '%')=''">
151 <xsl:value-of select="number(substring-before(@width, '%')) div 100"/>
152 <xsl:text>\textwidth</xsl:text>
155 <xsl:value-of select="@width"/>
159 <xsl:if test="$width!='' and (@scalefit='0' or count(@scale)>0)">
160 <xsl:text>\makebox[</xsl:text><xsl:value-of select='$width' /><xsl:text>]</xsl:text>
162 <xsl:text>{</xsl:text>
163 <!-- TODO this logic actually needs to make decisions based on the ALLOWED imagedata,
164 not all the imagedata present in the source file. -->
165 <xsl:if test="$imageobjectscnt > 1 and $latex.use.subfigure='1' and count(ancestor::figure) > 0">
166 <xsl:text>\subfigure[</xsl:text>
167 <xsl:if test="count(../../..//caption)>1">
168 <xsl:value-of select="../../caption"/>
170 <xsl:text>]</xsl:text>
172 <xsl:text>{\includegraphics[</xsl:text>
174 <xsl:when test="@scale">
175 <xsl:text>scale=</xsl:text>
176 <xsl:value-of select="number(@scale) div 100"/>
178 <xsl:when test="$width!='' and @scalefit='1'">
179 <xsl:text>width=</xsl:text><xsl:value-of select="normalize-space($width)"/>
181 <xsl:when test="@depth!='' and @scalefit='1'">
182 <xsl:text>height=</xsl:text><xsl:value-of select="normalize-space(@depth)"/>
186 <xsl:when test="@format = 'PRN'"><xsl:text>,angle=270</xsl:text></xsl:when>
188 <xsl:text>]{</xsl:text>
189 <xsl:choose><!-- package graphicx and DeclareGraphicExtensions will take care of this -->
190 <xsl:when test="$ext != ''">
191 <xsl:value-of select="$filename"/>
194 <xsl:value-of select="$filename"/>
197 <xsl:text>}}}</xsl:text>
202 <xsl:template match="videodata">
203 <xsl:variable name="filename">
204 <xsl:call-template name="mediaobject.filename"><xsl:with-param name="object" select=".."/>
207 <xsl:variable name="alt">
208 <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
212 <xsl:template match="audiodata">
213 <xsl:variable name="filename">
214 <xsl:call-template name="mediaobject.filename"><xsl:with-param name="object" select=".."/>
217 <xsl:variable name="alt">
218 <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
223 <xsl:template match="caption">
224 <xsl:apply-templates/>