a1dc5dbf27a33b712f2d0b4a1930c3d458a13622
[samba.git] / docs / xslt / db2latex-xsl / xsl / latex.mapping.xsl
1 <?xml version='1.0'?>
2 <!DOCTYPE xsl:stylesheet [ <!ENTITY % xsldoc.ent SYSTEM "./xsldoc.ent"> %xsldoc.ent; ]>
3 <!--#############################################################################
4 |      $Id: latex.mapping.xsl,v 1.18 2004/01/14 14:54:32 j-devenish Exp $
5 |- #############################################################################
6 |      $Author: j-devenish $
7 |
8 |   PURPOSE:
9 + ############################################################################## -->
10
11 <xsl:stylesheet
12     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
13     xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
14     exclude-result-prefixes="doc" version='1.0'>
15
16         <!--############################################################################# -->
17         <!-- DOCUMENTATION                                                                -->
18         <doc:reference id="latex.mapping" xmlns="">
19                 <referenceinfo>
20                         <releaseinfo role="meta">
21                         $Id: latex.mapping.xsl,v 1.18 2004/01/14 14:54:32 j-devenish Exp $
22                         </releaseinfo>
23                         <authorgroup>
24                                 &ramon; &james;
25                         </authorgroup>
26                         <copyright>
27                         <year>2000</year> <year>2001</year> <year>2002</year> <year>2003</year>
28                         <holder>Ramon Casellas</holder>
29                         </copyright>
30                         <revhistory>
31                                 <doc:revision rcasver="1.11">&rev_2003_05;</doc:revision>
32                         </revhistory>
33                 </referenceinfo>
34                 <title>The &DB2LaTeX; mapping system <filename>latex.mapping.xsl</filename></title>
35                 <partintro>
36                         <section><title>Introduction</title>
37                         <para>The &DB2LaTeX; mapping system centralises the mapping
38                         of &DocBook; tags (e.g. <doc:db>chapter</doc:db>)
39                         to &LaTeX; commands (e.g. <function condition="latex">chapter</function>).
40                         It uses an auxiliary file, <filename>latex.mapping.xml</filename>,
41                         to define the start and end of each mapping.
42                         You can override this <quote>mapping file</quote>
43                         in order to customise &DB2LaTeX;.</para>
44                         </section>
45                 </partintro>
46         </doc:reference>
47         <!--############################################################################# -->
48
49         <doc:param name="latex.mapping.xml">
50                 <refpurpose>The primary mapping file</refpurpose>
51                 <doc:description>
52                         <para>
53                                 &DB2LaTeX; will search for mappings in this file.
54                                 The value of this variable must be an XML document.
55                                 If mappings cannot be found in this file, &DB2LaTeX; will
56                                 search the <link linkend="param.latex.mapping.xml.default">default mapping file</link>.
57                         </para>
58                 </doc:description>
59                 <doc:samples>
60                         <simplelist type='inline'>
61                                 &test_mapping;
62                         </simplelist>
63                 </doc:samples>
64         </doc:param>
65     <xsl:param name="latex.mapping.xml" select="document('latex.mapping.xml')"/>
66
67         <doc:param name="latex.mapping.xml.default">
68                 <refpurpose>The default mapping file</refpurpose>
69                 <doc:description>
70                         <para>
71                                 Defines the mapping file that &DB2LaTeX; will search
72                                 when it cannot find a template in the
73                                 <link linkend="param.latex.mapping.xml">primary mapping file</link>.
74                                 The value of this variable must be an XML document.
75                         </para>
76                 </doc:description>
77         </doc:param>
78     <xsl:param name="latex.mapping.xml.default" select="document('latex.mapping.xml')"/>
79
80         <doc:template xmlns="">
81                 <refpurpose>Perform &DocBook; to &LaTeX; mapping</refpurpose>
82                 <doc:description>
83                         
84                         
85                         
86                 </doc:description>
87                 <doc:variables>
88                         &no_var;
89                 </doc:variables>
90                 <doc:seealso>
91                         <itemizedlist>
92                                 <listitem><simpara><xref linkend="param.latex.mapping.xml"/></simpara></listitem>
93                                 <listitem><simpara><xref linkend="param.latex.mapping.xml.default"/></simpara></listitem>
94                         </itemizedlist>
95                 </doc:seealso>
96         </doc:template>
97         <xsl:template name="latex.mapping">
98                 <xsl:param name="object" select="."/>
99                 <xsl:param name="keyword" select="local-name($object)"/>
100                 <xsl:param name="role" select="begin"/>
101                 <xsl:param name="string">
102                         <xsl:call-template name="extract.object.title">
103                                 <xsl:with-param name="object" select="$object"/>
104                         </xsl:call-template>
105                 </xsl:param>
106                 <xsl:variable name="id">
107                         <xsl:call-template name="generate.label.id">
108                                 <xsl:with-param name="object" select="$object"/>
109                         </xsl:call-template>
110                 </xsl:variable>
111                 <xsl:variable name="title">
112                         <xsl:choose>
113                         <xsl:when test="starts-with(local-name($object),'informal')">
114                                 <xsl:if test="$string!=''">
115                                         <xsl:message>Ignoring title for <xsl:value-of select="local-name($object)"/>.</xsl:message>
116                                 </xsl:if>
117                         </xsl:when>
118                         <xsl:when test="$string=''">
119                                 <xsl:call-template name="gentext.element.name"/>
120                         </xsl:when>
121                         <xsl:otherwise>
122                                 <xsl:value-of select="normalize-space($string)"/>
123                         </xsl:otherwise>
124                         </xsl:choose>
125                 </xsl:variable>
126                 <xsl:variable name="local.mapping" select="$latex.mapping.xml/latexbindings/latexmapping[@role=$role]/mapping[@key=$keyword]"/>
127                 <xsl:variable name="default.mapping" select="$latex.mapping.xml.default/latexbindings/latexmapping[@role=$role]/mapping[@key=$keyword]"/>
128                 
129                 <xsl:choose>
130                         <xsl:when test="$local.mapping and ($local.mapping/@text!='' or not($local.mapping/line))">
131                                 <xsl:call-template name="string-replace">
132                                         <xsl:with-param name="to"><xsl:value-of select="$id"/></xsl:with-param>
133                                         <xsl:with-param name="from">%id%</xsl:with-param>
134                                         <xsl:with-param name="string">
135                                                 <xsl:call-template name="string-replace">
136                                                         <xsl:with-param name="to"><xsl:value-of select="$title"/></xsl:with-param>
137                                                         <xsl:with-param name="from">%title%</xsl:with-param>
138                                                         <xsl:with-param name="string">
139                                                                 <xsl:value-of select="$local.mapping/@text"/>
140                                                         </xsl:with-param>
141                                                 </xsl:call-template>
142                                         </xsl:with-param>
143                                 </xsl:call-template>
144                         </xsl:when>
145
146                         <xsl:when test="$local.mapping/line">
147                                 <xsl:for-each select="$local.mapping/line">
148                                         <xsl:call-template name="string-replace">
149                                                 <xsl:with-param name="to"><xsl:value-of select="$id"/></xsl:with-param>
150                                                 <xsl:with-param name="from">%id%</xsl:with-param>
151                                                 <xsl:with-param name="string">
152                                                         <xsl:call-template name="string-replace">
153                                                                 <xsl:with-param name="to"><xsl:value-of select="$title"/></xsl:with-param>
154                                                                 <xsl:with-param name="from">%title%</xsl:with-param>
155                                                                 <xsl:with-param name="string" select="."/>
156                                                         </xsl:call-template>
157                                                 </xsl:with-param>
158                                         </xsl:call-template>
159                                 </xsl:for-each>
160                         </xsl:when>
161
162                         <xsl:when test="$default.mapping/@text!=''">
163                                 <xsl:call-template name="string-replace">
164                                         <xsl:with-param name="to"><xsl:value-of select="$id"/></xsl:with-param>
165                                         <xsl:with-param name="from">%id%</xsl:with-param>
166                                         <xsl:with-param name="string">
167                                                 <xsl:call-template name="string-replace">
168                                                         <xsl:with-param name="to"><xsl:value-of select="$title"/></xsl:with-param>
169                                                         <xsl:with-param name="from">%title%</xsl:with-param>
170                                                         <xsl:with-param name="string">
171                                                                 <xsl:value-of select="$default.mapping/@text"/>
172                                                         </xsl:with-param>
173                                                 </xsl:call-template>
174                                         </xsl:with-param>
175                                 </xsl:call-template>
176                         </xsl:when>
177
178                         <xsl:when test="$default.mapping">
179                         <xsl:for-each select="$default.mapping/line">
180                                 <xsl:call-template name="string-replace">
181                                         <xsl:with-param name="to"><xsl:value-of select="$id"/></xsl:with-param>
182                                         <xsl:with-param name="from">%id%</xsl:with-param>
183                                         <xsl:with-param name="string">
184                                                 <xsl:call-template name="string-replace">
185                                                         <xsl:with-param name="to"><xsl:value-of select="$title"/></xsl:with-param>
186                                                         <xsl:with-param name="from">%title%</xsl:with-param>
187                                                         <xsl:with-param name="string" select="."/>
188                                                 </xsl:call-template>
189                                         </xsl:with-param>
190                                 </xsl:call-template>
191                         </xsl:for-each>
192
193                         </xsl:when>
194                                 <xsl:otherwise>
195                                         <xsl:message terminate="no">
196                                                 <xsl:text>Warning: Unable to find LaTeX mapping for &#10;</xsl:text>
197                                                 <xsl:text>KEYWORD:</xsl:text><xsl:value-of select="$keyword"/><xsl:text>&#10;</xsl:text>
198                                                 <xsl:text>ROLE:</xsl:text><xsl:value-of select="$role"/><xsl:text>&#10;</xsl:text>
199                                         </xsl:message>
200                                 </xsl:otherwise>
201                 </xsl:choose>
202         </xsl:template>
203
204
205
206
207     <xsl:template name="map.begin">
208         <xsl:param name="object"  select="."/>
209         <xsl:param name="keyword" select="local-name($object)"/>
210         <xsl:param name="string">
211                 <xsl:call-template name="extract.object.title">
212                         <xsl:with-param name="object" select="$object"/>
213                 </xsl:call-template>
214         </xsl:param>
215         <xsl:call-template name="latex.mapping">
216             <xsl:with-param name="keyword" select="$keyword"/>
217             <xsl:with-param name="role">begin</xsl:with-param>
218             <xsl:with-param name="string" select="$string"/>
219         </xsl:call-template>
220     </xsl:template>
221
222     <xsl:template name="map.end">
223         <xsl:param name="object"  select="."/>
224         <xsl:param name="keyword" select="local-name($object)"/>
225         <xsl:param name="role"    select="begin"/>
226         <xsl:param name="string">
227                 <xsl:call-template name="extract.object.title">
228                         <xsl:with-param name="object" select="$object"/>
229                 </xsl:call-template>
230         </xsl:param>
231         <xsl:call-template name="latex.mapping">
232             <xsl:with-param name="keyword" select="$keyword"/>
233             <xsl:with-param name="string" select="$string"/>
234             <xsl:with-param name="role">end</xsl:with-param>
235         </xsl:call-template>
236     </xsl:template>
237
238         <doc:template name="extract.object.title">
239                 <refpurpose>Choose a title for an object</refpurpose>
240                 <doc:description>
241                         <para>
242                                 Processes the <sgmltag class="element">title</sgmltag> child
243                                 of the specified object. Uses the context node as the default object.
244                         </para>
245                 </doc:description>
246                 <doc:variables>
247                         <itemizedlist>
248                                 <listitem><simpara><xref linkend="param.latex.apply.title.templates"/></simpara></listitem>
249                         </itemizedlist>
250                 </doc:variables>
251                 <doc:params>
252                         <variablelist>
253                                 <varlistentry><term>object</term><listitem><simpara>The node for which a title is desired.</simpara></listitem></varlistentry>
254                         </variablelist>
255                 </doc:params>
256         </doc:template>
257         <xsl:template name="extract.object.title">
258                 <xsl:param name="object"  select="."/>
259                 <xsl:choose>
260                         <xsl:when test="$latex.apply.title.templates='1'">
261                                 <xsl:apply-templates select="$object/title" mode="latex"/>
262                         </xsl:when>
263                         <xsl:otherwise>
264                                 <xsl:call-template name="normalize-scape">
265                                         <xsl:with-param name="string" select="$object/title"/>
266                                 </xsl:call-template>
267                         </xsl:otherwise>
268                 </xsl:choose>
269         </xsl:template>
270
271         <doc:template match="title" mode="latex">
272                 <refpurpose>Process <doc:db>title</doc:db> elements</refpurpose>
273                 <doc:description>
274                         <para>Applies templates with no mode. This template is called by <xref linkend="template.extract.object.title"/>.</para>
275                         <para>This differs from the modeless <doc:db>title</doc:db>
276                         templates because they suppress the output of titles.</para>
277                 </doc:description>
278         </doc:template>
279         <xsl:template match="title" mode="latex"><xsl:apply-templates/></xsl:template>
280
281 </xsl:stylesheet>
282