Use system-provided dblatex to build the docs rather than included
[sfrench/samba-autobuild/.git] / docs-xml / xslt / db2latex-xsl / xsl / mathml / mathml.content.token.mod.xsl
1 <?xml version='1.0'?>
2 <!DOCTYPE xsl:stylesheet
3 [
4  <!ENTITY % mmlalias PUBLIC "MathML alias" "ent/mmlalias.ent">  %mmlalias;
5  <!ENTITY % mmlextra PUBLIC "MathML extra" "ent/mmlextra.ent">  %mmlextra;
6 ]>
7 <!--############################################################################# 
8  |      $Id: mathml.content.token.mod.xsl,v 1.1.1.1 2003/03/14 10:42:54 rcasellas Exp $
9  |- #############################################################################
10  |      $Author: rcasellas $                                                                                            
11  |      
12  |      PURPOSE: MathML Content Markup, tokens (ci, cn, csymbol)
13  |      MathML namespace used -> mml
14  + ############################################################################## -->
15
16 <xsl:stylesheet version='1.0'
17         xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
18         xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns="http://www.w3.org/1998/Math/MathML">
19
20 <xsl:strip-space elements="mml:math mml:mrow"/>
21
22
23 <!-- Content Number --> 
24 <!-- support for bases and types-->
25 <xsl:template match="mml:cn">
26         <xsl:text>{</xsl:text>
27         <xsl:text>{</xsl:text>
28         <xsl:choose>  
29         <xsl:when test="./@type='complex-cartesian' or ./@type='complex'">
30                         <mn><xsl:value-of select="text()[position()=1]"/></mn>
31                         <xsl:choose>
32                                 <xsl:when test="contains(text()[position()=2],'-')">
33                                         <xsl:text>-</xsl:text><xsl:value-of select="substring-after(text()[position()=2],'-')"/>
34                                 <!--    substring-after does not seem to work well in XT :
35                                         if imaginary part is expressed with at least one space char 
36                                         before the minus sign, then it does not work (we end up with 
37                                         two minus sign since the one in the text is kept)-->
38                                 </xsl:when>
39                                 <xsl:otherwise>
40                                         <xsl:text>+</xsl:text> <xsl:value-of select="text()[position()=2]"/>
41                                 </xsl:otherwise>
42                         </xsl:choose>
43                         <xsl:text>\dot\textrm{i}</xsl:text>
44                 </xsl:when>
45         <xsl:when test="./@type='complex-polar'">
46                         <xsl:text>\textrm{Polar}(</xsl:text><xsl:value-of select="text()[position()=1]"/><xsl:text>,</xsl:text>
47                                                 <xsl:value-of select="text()[position()=2]"/>
48                         <xsl:text>)</xsl:text>
49                 </xsl:when>
50                 <xsl:when test="./@type='rational'">
51                         <xsl:text>\frac{</xsl:text><xsl:value-of select="text()[position()=1]"/><xsl:text>}{</xsl:text>
52                                 <xsl:value-of select="text()[position()=2]"/>
53                         <xsl:text>}</xsl:text>
54                 </xsl:when>
55                 <xsl:otherwise>
56                         <xsl:value-of select="."/>
57                 </xsl:otherwise>
58         </xsl:choose>
59         <xsl:text>}</xsl:text>
60         <xsl:if test="@base and @base!=10">  <!-- base specified and different from 10 ; if base = 10 we do not display it -->
61                         <xsl:text>_{</xsl:text><xsl:value-of select="@base"/><xsl:text>}</xsl:text>
62         </xsl:if>
63         <xsl:text>}</xsl:text>
64 </xsl:template>
65
66
67
68 <!-- Content Identifier --> 
69 <!-- identifier -->
70 <!--support for presentation markup-->
71 <xsl:template match="mml:ci">
72 <xsl:choose>  
73 <xsl:when test="./@type='complex-cartesian' or ./@type='complex'">
74         <xsl:choose>
75                 <xsl:when test="count(*)>0">  <!--if identifier is composed of real+imag parts-->
76                         <xsl:text>{</xsl:text>
77                         <xsl:choose>
78                                 <xsl:when test="*[self::mml:mchar and position()=1]">  <!-- if real part is an mchar -->
79                                         <xsl:text>\textrm{</xsl:text><xsl:copy-of select="*[position()=1]"/><xsl:text>}</xsl:text>
80                                 </xsl:when>
81                                 <xsl:otherwise>  <!-- if real part is simple text -->
82                                         <xsl:text>\textrm{</xsl:text><xsl:copy-of select="*[position()=1]"/><xsl:text>}</xsl:text>
83                                 </xsl:otherwise>
84                         </xsl:choose>
85                         <xsl:choose> <!-- im part is negative-->
86                                 <xsl:when test="contains(text()[preceding-sibling::*[position()=1 and self::mml:sep]],'-')">
87                                         <xsl:text>-\textrm{</xsl:text>
88                                         <xsl:choose>
89                                                 <xsl:when test="mml:mchar[preceding-sibling::*[self::mml:sep]]"><!-- if im part is an mchar -->
90                                                         <xsl:copy-of select="mml:mchar[preceding-sibling::*[self::mml:sep]]"/>
91                                                 </xsl:when>
92                                                 <xsl:otherwise><!-- if im part is simple text -->
93                                                         <xsl:value-of select="substring-after(text()[preceding-sibling::*[position()=1 and self::mml:sep]],'-')"/>
94                                                 </xsl:otherwise>
95                                         </xsl:choose>
96                                         <xsl:text>}</xsl:text>
97                                         <xsl:text>\dot\textrm{i}</xsl:text>
98                                 </xsl:when>
99                                 <xsl:otherwise> <!-- im part is not negative-->
100                                         <xsl:text>+\textrm{</xsl:text>
101                                         <xsl:choose><!-- if im part is an mchar -->
102                                                 <xsl:when test="mml:mchar[preceding-sibling::*[self::mml:sep]]">
103                                                         <xsl:copy-of select="mml:mchar[preceding-sibling::*[self::mml:sep]]"/>
104                                                 </xsl:when>
105                                                 <xsl:otherwise><!-- if im part is simple text -->
106                                                         <xsl:value-of select="text()[preceding-sibling::*[position()=1 and self::mml:sep]]"/>
107                                                 </xsl:otherwise>
108                                         </xsl:choose>
109                                         <xsl:text>}</xsl:text>
110                                         <xsl:text>\dot\textrm{i}</xsl:text>
111                                 </xsl:otherwise>
112                         </xsl:choose>
113                         <xsl:text>}</xsl:text>
114                 </xsl:when>
115                 <xsl:otherwise>  <!-- if identifier is composed only of one text child-->
116                         <xsl:text>\dot\textrm{</xsl:text><xsl:value-of select="."/><xsl:text>}</xsl:text>
117                 </xsl:otherwise>
118         </xsl:choose>
119 </xsl:when>
120 <xsl:when test="./@type='complex-polar'">
121     <xsl:choose>
122     <xsl:when test="count(*)>0">   <!--if identifier is composed of real+imag parts-->
123       <xsl:text>{</xsl:text>
124         <mi>Polar</mi>
125         <mfenced><mi>
126         <xsl:value-of select="text()[following-sibling::*[self::mml:sep]]"/>
127         <xsl:if test="mml:mchar[following-sibling::*[self::mml:sep]]">
128           <xsl:copy-of select="mml:mchar[following-sibling::*[self::mml:sep]]"/>
129         </xsl:if>
130         </mi>
131         <mi>
132         <xsl:value-of select="text()[preceding-sibling::*[self::mml:sep]]"/>
133         <xsl:if test="mml:mchar[preceding-sibling::*[self::mml:sep]]">
134           <xsl:copy-of select="mml:mchar[preceding-sibling::*[self::mml:sep]]"/>
135         </xsl:if>
136         </mi></mfenced>
137       <xsl:text>}</xsl:text>
138     </xsl:when>
139     <xsl:otherwise>   <!-- if identifier is composed only of one text child-->
140       <mi><xsl:value-of select="."/></mi>
141     </xsl:otherwise>
142     </xsl:choose>
143 </xsl:when> 
144 <xsl:when test="./@type='rational'">
145     <xsl:choose>
146     <xsl:when test="count(*)>0"> <!--if identifier is composed of two parts-->
147       <xsl:text>{</xsl:text><mi>
148       <xsl:value-of select="text()[following-sibling::*[self::mml:sep]]"/>
149       <xsl:if test="mml:mchar[following-sibling::*[self::mml:sep]]">
150         <xsl:copy-of select="mml:mchar[following-sibling::*[self::mml:sep]]"/>
151       </xsl:if>
152       </mi>
153       <mo>/</mo>
154       <mi>
155       <xsl:value-of select="text()[preceding-sibling::*[self::mml:sep]]"/>
156       <xsl:if test="mml:mchar[preceding-sibling::*[self::mml:sep]]">
157         <xsl:copy-of select="mml:mchar[preceding-sibling::*[self::mml:sep]]"/>
158       </xsl:if>
159       </mi><xsl:text>}</xsl:text>
160     </xsl:when>
161     <xsl:otherwise>   <!-- if identifier is composed only of one text child-->
162       <mi><xsl:value-of select="."/></mi>
163     </xsl:otherwise>
164     </xsl:choose>
165   </xsl:when>
166   <xsl:when test="./@type='vector'">
167     <mi fontweight="bold">
168       <xsl:value-of select="text()"/>
169       <xsl:if test="mml:mchar">
170         <xsl:copy-of select="mml:mchar"/>
171       </xsl:if>
172     </mi>
173 </xsl:when>
174   <!-- type 'set' seems to be deprecated (use 4.4.12 instead); besides, there is no easy way to translate set identifiers to chars in ISOMOPF -->
175 <xsl:otherwise>  <!-- no type attribute provided -->
176         <xsl:choose>
177                 <xsl:when test="mml:mchar"> <!-- test if identifier is expressed using mchar nodes -->
178       <mi><xsl:value-of select="text()"/><xsl:copy-of select="mml:mchar"/></mi>
179     </xsl:when>
180     <xsl:when test="count(node()) != count(text())">
181       <!--test if children are not all text nodes, meaning there is markup assumed 
182       to be presentation markup (the case where there are mchar nodes has been tested just before)-->
183         <xsl:text>{</xsl:text><xsl:copy-of select="child::*"/><xsl:text>}</xsl:text>
184     </xsl:when>
185     <xsl:otherwise>  <!-- common case -->
186       <mi><xsl:value-of select="."/></mi>
187     </xsl:otherwise>
188     </xsl:choose>
189 </xsl:otherwise>
190 </xsl:choose>
191 </xsl:template>
192
193
194
195
196
197
198 <!-- externally defined symbols-->
199 <xsl:template match="mml:apply[mml:csymbol]">
200         <xsl:text>{</xsl:text>
201                 <xsl:apply-templates select="mml:csymbol[position()=1]"/>
202         <xsl:text>\left(</xsl:text>
203         <xsl:for-each select="child::*[position()!=1]">
204                 <xsl:apply-templates select="."/>
205         </xsl:for-each>
206         <xsl:text>\right)</xsl:text>
207         <xsl:text>}</xsl:text>
208 </xsl:template>
209
210
211 <xsl:template match="mml:csymbol">
212 <xsl:choose>
213         <!--test if children are not all text nodes, meaning there is markup assumed to be presentation markup-->
214         <!--perhaps it would be sufficient to test if there is more than one node or text node-->
215         <xsl:when test="count(node()) != count(text())"> 
216                 <xsl:text>{</xsl:text> <xsl:copy-of select="child::*"/> <xsl:text>}</xsl:text>
217         </xsl:when>
218         <xsl:otherwise>
219                 <xsl:text>\textrm{</xsl:text> <xsl:copy-of select="."/> <xsl:text>}</xsl:text>
220         </xsl:otherwise>
221 </xsl:choose>
222 </xsl:template>
223
224 <xsl:template match="mml:mchar">
225   <xsl:copy-of select="."/>
226 </xsl:template>
227 <!--
228 <xsl:template match="mml:mtext">
229   <xsl:copy-of select="."/>
230 </xsl:template>
231 -->
232 </xsl:stylesheet>