This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.
[tprouty/samba.git] / docs / docbook / xslt / db2latex / mediaobject.mod.xsl
1 <?xml version='1.0'?>
2 <!--############################################################################# 
3 |       $Id: mediaobject.mod.xsl,v 1.1.2.1 2003/05/01 14:06:15 jelmer Exp $
4 |- #############################################################################
5 |       $Author: jelmer $                                                                                               
6 |                                                                                                               
7 |   PURPOSE: Manage Imageobject related tags.
8 + ############################################################################## -->
9
10 <xsl:stylesheet 
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'>
14
15
16
17     <!--############################################################################# -->
18     <!-- DOCUMENTATION                                                                -->
19     <doc:reference id="mediaobject" xmlns="">
20         <referenceinfo>
21             <releaseinfo role="meta">
22                 $Id: mediaobject.mod.xsl,v 1.1.2.1 2003/05/01 14:06:15 jelmer Exp $
23             </releaseinfo>
24         <authorgroup>
25             <author> <firstname>Ramon</firstname> <surname>Casellas</surname> </author>
26             <author> <firstname>James</firstname> <surname>Devenish</surname> </author>
27         </authorgroup>
28             <copyright>
29                 <year>2000</year> <year>2001</year> <year>2002</year> <year>2003</year>
30                 <holder>Ramon Casellas</holder>
31             </copyright>
32         </referenceinfo>
33
34         <title>MediaObjects <filename>mediaobject.mod.xsl</filename></title>
35         <partintro>
36             <section><title>Introduction</title>
37                 <para></para>
38             </section>
39         </partintro>
40     </doc:reference>
41
42
43
44     <xsl:template match="videoobject">
45         <xsl:apply-templates select="videodata"/>
46     </xsl:template>
47     <xsl:template match="audioobject">
48         <xsl:apply-templates select="audiodata"/>
49     </xsl:template>
50     <xsl:template match="textobject">
51         <!-- TODO if mixed in with imageobjects, use subfigure (if appropriate) -->
52         <xsl:apply-templates/>
53     </xsl:template>
54
55
56     <xsl:template match="mediaobject">
57                 <xsl:if test="local-name(preceding-sibling::*[1])!='mediaobject'">
58                         <xsl:text>&#10;</xsl:text>
59                 </xsl:if>
60                 <xsl:call-template name="mediacontent"/>
61                 <xsl:text>&#10;</xsl:text>
62         </xsl:template>
63
64     <xsl:template match="inlinemediaobject">
65                 <xsl:call-template name="mediacontent"/>
66         </xsl:template>
67
68     <xsl:template name="mediacontent">
69         <xsl:choose>
70                 <xsl:when test="count(imageobject)&lt;1">
71                         <xsl:apply-templates select="textobject[1]"/>
72                 </xsl:when>
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]"/>
75                 </xsl:when>
76                 <xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='latex'])!=0">
77                         <xsl:apply-templates select="imageobject[@role='latex']"/>
78                 </xsl:when>
79                 <xsl:when test="$use.role.for.mediaobject='1' and count(imageobject[@role='tex'])!=0">
80                         <xsl:apply-templates select="imageobject[@role='tex']"/>
81                 </xsl:when>
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,','))]"/>
87                         <xsl:choose>
88                                 <xsl:when test="count($candidates)!=0">
89                                         <xsl:apply-templates select="$candidates[1]"/>
90                                 </xsl:when>
91                                 <xsl:otherwise>
92                                         <xsl:variable name="fallbacks" select="imageobject/imagedata[@format='']"/>
93                                         <xsl:choose>
94                                                 <xsl:when test="count($fallbacks)!=0">
95                                                         <xsl:apply-templates select="$fallbacks[1]"/>
96                                                 </xsl:when>
97                                                 <xsl:when test="count(textobject)!=0">
98                                                         <xsl:apply-templates select="textobject[1]"/>
99                                                 </xsl:when>
100                                                 <xsl:otherwise>
101                                                         <xsl:apply-templates select="imageobject[1]"/>
102                                                 </xsl:otherwise>
103                                         </xsl:choose>
104                                 </xsl:otherwise>
105                         </xsl:choose>
106                 </xsl:when>
107                 <xsl:otherwise>
108                         <xsl:apply-templates select="imageobject[1]"/>
109                 </xsl:otherwise>
110         </xsl:choose>
111     </xsl:template>
112
113     <xsl:template match="imageobject">
114         <xsl:apply-templates select="imagedata"/>
115     </xsl:template>
116
117
118
119
120
121
122
123
124     <!--############################################################################# -->
125     <!-- DOCUMENTATION -->
126     <doc:template match="imagedata" xmlns="">
127         <refpurpose>XSL template for images.</refpurpose>
128         <refdescription>
129             <para></para>
130             <formalpara><title>Remarks and Bugs</title>
131                 <itemizedlist>
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>
135                 </itemizedlist>
136             </formalpara>
137         </refdescription>
138     </doc:template>
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"/>
145             </xsl:call-template>
146         </xsl:variable>
147         <xsl:variable name="imageobjectscnt" select="count(../../..//imageobject)"/>
148         <xsl:variable name="width">
149             <xsl:choose>
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>
153                 </xsl:when>
154                 <xsl:otherwise>
155                     <xsl:value-of select="@width"/>
156                 </xsl:otherwise>
157             </xsl:choose>
158         </xsl:variable>
159         <xsl:if test="$width!='' and (@scalefit='0' or count(@scale)&gt;0)">
160                 <xsl:text>\makebox[</xsl:text><xsl:value-of select='$width' /><xsl:text>]</xsl:text>
161         </xsl:if>
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 &gt; 1 and $latex.use.subfigure='1' and count(ancestor::figure) &gt; 0">
166             <xsl:text>\subfigure[</xsl:text>
167                 <xsl:if test="count(../../..//caption)&gt;1">
168                         <xsl:value-of select="../../caption"/>
169                 </xsl:if>
170                 <xsl:text>]</xsl:text>
171         </xsl:if>
172         <xsl:text>{\includegraphics[</xsl:text>
173         <xsl:choose>
174             <xsl:when test="@scale"> 
175                 <xsl:text>scale=</xsl:text>
176                 <xsl:value-of select="number(@scale) div 100"/>
177             </xsl:when>
178                 <xsl:when test="$width!='' and @scalefit='1'">
179                 <xsl:text>width=</xsl:text><xsl:value-of select="normalize-space($width)"/>
180                 </xsl:when>
181                 <xsl:when test="@depth!='' and @scalefit='1'">
182                 <xsl:text>height=</xsl:text><xsl:value-of select="normalize-space(@depth)"/>
183                 </xsl:when>
184         </xsl:choose>
185         <xsl:choose>
186             <xsl:when test="@format = 'PRN'"><xsl:text>,angle=270</xsl:text></xsl:when>
187         </xsl:choose>
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"/>
192             </xsl:when>
193             <xsl:otherwise> 
194                 <xsl:value-of select="$filename"/>
195             </xsl:otherwise>
196         </xsl:choose>
197         <xsl:text>}}}</xsl:text>
198     </xsl:template>
199
200
201
202     <xsl:template match="videodata">
203         <xsl:variable name="filename">
204             <xsl:call-template name="mediaobject.filename"><xsl:with-param name="object" select=".."/>
205             </xsl:call-template>
206         </xsl:variable>
207         <xsl:variable name="alt">
208             <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
209         </xsl:variable>
210     </xsl:template>
211
212     <xsl:template match="audiodata">
213         <xsl:variable name="filename">
214             <xsl:call-template name="mediaobject.filename"><xsl:with-param name="object" select=".."/>
215             </xsl:call-template>
216         </xsl:variable>
217         <xsl:variable name="alt">
218             <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
219         </xsl:variable>
220     </xsl:template>
221
222
223     <xsl:template match="caption">
224         <xsl:apply-templates/>
225     </xsl:template>
226
227 </xsl:stylesheet>