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