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
|
<?xml version='1.0'?>
<!--#############################################################################
| $Id: mediaobject.mod.xsl,v 1.1.2.3 2003/08/12 18:22:39 jelmer Exp $
|- #############################################################################
| $Author: jelmer $
|
| PURPOSE: Manage Imageobject related tags.
+ ############################################################################## -->
<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'>
<!--############################################################################# -->
<!-- DOCUMENTATION -->
<doc:reference id="mediaobject" xmlns="">
<referenceinfo>
<releaseinfo role="meta">
$Id: mediaobject.mod.xsl,v 1.1.2.3 2003/08/12 18:22:39 jelmer Exp $
</releaseinfo>
<authorgroup>
<author> <firstname>Ramon</firstname> <surname>Casellas</surname> </author>
<author> <firstname>James</firstname> <surname>Devenish</surname> </author>
</authorgroup>
<copyright>
<year>2000</year> <year>2001</year> <year>2002</year> <year>2003</year>
<holder>Ramon Casellas</holder>
</copyright>
</referenceinfo>
<title>MediaObjects <filename>mediaobject.mod.xsl</filename></title>
<partintro>
<section><title>Introduction</title>
<para></para>
</section>
</partintro>
</doc:reference>
<xsl:template match="videoobject">
<xsl:apply-templates select="videodata"/>
</xsl:template>
<xsl:template match="audioobject">
<xsl:apply-templates select="audiodata"/>
</xsl:template>
<xsl:template match="textobject">
<!-- TODO if mixed in with imageobjects, use subfigure (if appropriate) -->
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="mediaobject|inlinemediaobject">
<xsl:if test="local-name(.)='mediaobject' and position()=1">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="count(imageobject)<1">
<xsl:apply-templates select="textobject[1]"/>
</xsl:when>
<xsl:when test="$use.role.for.mediaobject='1' and $preferred.mediaobject.role!='' and count(imageobject/imagedata[@role='latex'])!=0">
<xsl:apply-templates select="imageobject/imagedata[@role=$preferred.mediaobject.role]"/>
</xsl:when>
<xsl:when test="$use.role.for.mediaobject='1' and count(imageobject/imagedata[@role='latex'])!=0">
<xsl:apply-templates select="imageobject/imagedata[@role='latex']"/>
</xsl:when>
<xsl:when test="$use.role.for.mediaobject='1' and count(imageobject/imagedata[@role='tex'])!=0">
<xsl:apply-templates select="imageobject/imagedata[@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:template>
<xsl:template match="imageobject">
<xsl:apply-templates select="imagedata"/>
</xsl:template>
<!--############################################################################# -->
<!-- DOCUMENTATION -->
<doc:template match="imagedata" xmlns="">
<refpurpose>XSL template for images.</refpurpose>
<refdescription>
<para></para>
<formalpara><title>Remarks and Bugs</title>
<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>
</formalpara>
</refdescription>
</doc:template>
<!--############################################################################# -->
<xsl:template match="imagedata">
<xsl:variable name="filename" select="@fileref"/>
<xsl:variable name="ext">
<xsl:call-template name="filename-extension">
<xsl:with-param name="filename" select="$filename"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="imageobjectscnt" select="count(../../..//imageobject)"/>
<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)>0)">
<xsl:text>\makebox[</xsl:text><xsl:value-of select='$width' /><xsl:text>]</xsl:text>
</xsl:if>
<xsl:text>{</xsl:text>
<!-- TODO this logic actually needs to make decisions based on the ALLOWED imagedata,
not all the imagedata present in the source file. -->
<xsl:if test="$imageobjectscnt > 1 and $latex.use.subfigure='1' and count(ancestor::figure) > 0">
<xsl:text>\subfigure[</xsl:text>
<xsl:if test="count(../../..//caption)>1">
<xsl:value-of select="../../caption"/>
</xsl:if>
<xsl:text>]</xsl:text>
</xsl:if>
<xsl:text>{\includegraphics[</xsl:text>
<xsl:choose>
<xsl:when test="$width!='' and (@scalefit='1' or count(@scale)<1)">
<xsl:text>width=</xsl:text><xsl:value-of select="normalize-space($width)"/>
</xsl:when>
<xsl:when test="@scale">
<xsl:text>scale=.</xsl:text><xsl:value-of select="normalize-space(@scale)"/>
</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:choose><!-- package graphicx and DeclareGraphicExtensions will take care of this -->
<xsl:when test="$ext != ''">
<xsl:value-of select="$filename"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$filename"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>}}} </xsl:text>
<!-- xsl:text>}}}\quad </xsl:text -->
</xsl:template>
<xsl:template match="videodata">
<xsl:variable name="filename">
<xsl:call-template name="mediaobject.filename"><xsl:with-param name="object" select=".."/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="alt">
<xsl:apply-templates select="(../../textobject/phrase)[1]"/>
</xsl:variable>
</xsl:template>
<xsl:template match="audiodata">
<xsl:variable name="filename">
<xsl:call-template name="mediaobject.filename"><xsl:with-param name="object" select=".."/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="alt">
<xsl:apply-templates select="(../../textobject/phrase)[1]"/>
</xsl:variable>
</xsl:template>
<xsl:template match="caption">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
|