This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[ira/wip.git] / docs / docbook / xslt / db2latex / latex.mapping.xsl
1 <?xml version='1.0'?>
2 <!--#############################################################################
3 |      $Id: latex.mapping.xsl,v 1.1 2003/04/30 21:39:49 ab Exp $
4 |- #############################################################################
5 |      $Author: ab $
6 |
7 |   PURPOSE:
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     <xsl:variable name="latex.mapping.xml" select="document('latex.mapping.xml')"/>
16
17
18     <!--############################################################################# -->
19     <!-- DOCUMENTATION                                                                -->
20     <doc:reference id="glossary" xmlns="">
21         <referenceinfo>
22             <releaseinfo role="meta">
23                 $Id: latex.mapping.xsl,v 1.1 2003/04/30 21:39:49 ab Exp $
24             </releaseinfo>
25             <author>
26                 <firstname>Ramon</firstname><surname>Casellas</surname>
27             </author>
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         <title>The DB2LaTeX mapping system <filename>latex.mapping.xsl</filename></title>
34         <partintro>
35             <section><title>Introduction</title>
36                 <para>The DB2LaTeX mapping system centralizes mapping docbook tags (e.g. <sgmltag>chapter</sgmltag>)
37                 to LaTeX commands <literal>\chapter</literal>. It used an auxiliary file, <filename>latex.mapping.xml</filename>
38                 that defines how the mapping is to be done.</para>
39             </section>
40         </partintro>
41     </doc:reference>
42     <!--############################################################################# -->
43
44
45     <!--############################################################################# -->
46     <!-- DOCUMENTATION -->
47     <doc:template name="latex.mapping" xmlns="">
48         <refpurpose></refpurpose>
49         <refdescription>
50             <para></para>
51             <formalpara><title>Remarks and Bugs</title>
52                 <itemizedlist>
53                 </itemizedlist>
54             </formalpara>
55             <formalpara><title>Default Behaviour</title>
56                 <screen></screen>
57             </formalpara>
58         </refdescription>
59     </doc:template>
60     <!--############################################################################# -->
61
62
63
64     <xsl:template name="latex.mapping">
65         <xsl:param name="object"  select="."/>
66         <xsl:param name="keyword" select="local-name($object)"/>
67         <xsl:param name="role"    select="begin"/>
68         <xsl:param name="string">
69                 <xsl:call-template name="extract.object.title">
70                         <xsl:with-param name="object" select="$object"/>
71                 </xsl:call-template>
72         </xsl:param>
73         <xsl:param name="use.label"     select="1"/>
74         <xsl:param name="use.hypertarget"       select="1"/>
75         <xsl:variable name="id">
76             <xsl:choose>
77                 <xsl:when test="$object/@id"> <xsl:value-of select="$object/@id"/> </xsl:when>
78                 <xsl:otherwise> <xsl:value-of select="generate-id($object)"/> </xsl:otherwise>
79             </xsl:choose>
80         </xsl:variable>
81         <xsl:variable name="title">
82             <xsl:choose>
83                 <xsl:when test="$string=''">
84                     <xsl:call-template name="gentext.element.name"/>
85                 </xsl:when>
86                 <xsl:otherwise>
87                         <xsl:value-of select="normalize-space($string)"/>
88                 </xsl:otherwise>
89             </xsl:choose>
90         </xsl:variable>
91         <xsl:variable name="latex.mapping.node" 
92             select="($latex.mapping.xml/latexbindings/latexmapping[@role=$role]/mapping[@key=$keyword])"/>
93         <xsl:choose>
94             <xsl:when test="$latex.mapping.node/@text!=''">
95                 <xsl:call-template name="string-replace">
96                     <xsl:with-param name="to"><xsl:value-of select="$id"/></xsl:with-param>
97                     <xsl:with-param name="from">%id</xsl:with-param>
98                     <xsl:with-param name="string">
99                         <xsl:call-template name="string-replace">
100                             <xsl:with-param name="to"><xsl:value-of select="$title"/></xsl:with-param>
101                             <xsl:with-param name="from">%title</xsl:with-param>
102                             <xsl:with-param name="string">
103                                 <xsl:value-of select="$latex.mapping.node/@text"/>
104                             </xsl:with-param>
105                         </xsl:call-template>
106                     </xsl:with-param>
107                 </xsl:call-template>
108             </xsl:when>
109             <xsl:otherwise>
110                 <xsl:for-each select="$latex.mapping.node/line">
111                     <xsl:call-template name="string-replace">
112                         <xsl:with-param name="to"><xsl:value-of select="$id"/></xsl:with-param>
113                         <xsl:with-param name="from">%id</xsl:with-param>
114                         <xsl:with-param name="string">
115                             <xsl:call-template name="string-replace">
116                                 <xsl:with-param name="to"><xsl:value-of select="$title"/></xsl:with-param>
117                                 <xsl:with-param name="from">%title</xsl:with-param>
118                                 <xsl:with-param name="string" select="."/>
119                             </xsl:call-template>
120                         </xsl:with-param>
121                     </xsl:call-template>
122                 </xsl:for-each>
123             </xsl:otherwise>
124         </xsl:choose>
125     </xsl:template>
126
127
128
129
130     <xsl:template name="map.begin">
131         <xsl:param name="object"  select="."/>
132         <xsl:param name="keyword" select="local-name($object)"/>
133         <xsl:param name="string">
134                 <xsl:call-template name="extract.object.title">
135                         <xsl:with-param name="object" select="$object"/>
136                 </xsl:call-template>
137         </xsl:param>
138         <xsl:call-template name="latex.mapping">
139             <xsl:with-param name="keyword" select="$keyword"/>
140             <xsl:with-param name="role">begin</xsl:with-param>
141             <xsl:with-param name="string" select="$string"/>
142         </xsl:call-template>
143     </xsl:template>
144
145     <xsl:template name="map.end">
146         <xsl:param name="object"  select="."/>
147         <xsl:param name="keyword" select="local-name($object)"/>
148         <xsl:param name="role"    select="begin"/>
149         <xsl:param name="string">
150                 <xsl:call-template name="extract.object.title">
151                         <xsl:with-param name="object" select="$object"/>
152                 </xsl:call-template>
153         </xsl:param>
154         <xsl:call-template name="latex.mapping">
155             <xsl:with-param name="keyword" select="$keyword"/>
156             <xsl:with-param name="string" select="$string"/>
157             <xsl:with-param name="role">end</xsl:with-param>
158         </xsl:call-template>
159     </xsl:template>
160
161         <xsl:template match="title" mode="latex"><xsl:apply-templates/></xsl:template>
162
163         <xsl:template name="extract.object.title">
164                 <xsl:param name="object"  select="."/>
165                 <xsl:choose>
166                         <xsl:when test="$latex.apply.title.templates='1'">
167                                 <xsl:apply-templates select="$object/title" mode="latex"/>
168                         </xsl:when>
169                         <xsl:otherwise>
170                                 <xsl:call-template name="normalize-scape">
171                                         <xsl:with-param name="string" select="$object/title"/>
172                                 </xsl:call-template>
173                         </xsl:otherwise>
174                 </xsl:choose>
175         </xsl:template>
176 </xsl:stylesheet>
177