trying to get HEAD building again. If you want the code
[abartlet/samba.git/.git] / docs / docbook / xslt / db2latex / mathml / mathml.content.functions.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  |- #############################################################################
9  |                                                                                                              
10  |   PURPOSE: MathML content markup.
11  |      Note: these elements are not part of the DocBook DTD. I have extended
12  |    the docbook DTD in order to support this tags, so that's why I have these 
13  |      templates here.
14  |   
15  |      MathML namespace used -> mml
16  + ############################################################################## -->
17
18 <xsl:stylesheet version='1.0'
19         xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
20         xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns="http://www.w3.org/1998/Math/MathML">
21
22 <xsl:template match="mml:fn">
23 </xsl:template>
24
25 <!--
26 <xsl:template match="mml:apply/lowlimit">
27 <xsl:variable name="first" select="../child::*[1]"/>
28 </xsl:template>
29
30 <xsl:template match="mml:apply/uplimit">
31 <xsl:variable name="first" select="../child::*[1]"/>
32 </xsl:template>
33
34 <xsl:template match="mml:apply/degree">
35 <xsl:variable name="first" select="../child::*[1]"/>
36 </xsl:template>
37 -->
38
39
40 <!-- conditions -->
41 <!-- no support for deprecated reln-->
42 <xsl:template match="mml:condition">
43         <xsl:text>{</xsl:text><xsl:apply-templates/><xsl:text>}</xsl:text>
44 </xsl:template>
45
46
47
48
49
50
51 <!--UNARY 
52           unary arithmetic                      exp, factorial, minus, abs, conjugate, arg, real, imaginary
53         unary logical                           not
54         unary functional                        inverse, ident
55         unary elementary classical
56         functions                                       sin, cos, tan, sec, csc, cot, sinh, cosh, tanh, sech, csch, coth, arcsin,
57                                           arccos, arctan, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsinh,
58                                           arctanh, exp, ln, log
59         unary linear algebra                    determinant, transpose
60         unary calculus and vector calculus
61                                           divergence, grad, curl, laplacian
62         unary set-theoretic                     card
63 -->
64
65 <!-- BINARY
66           binary arithmetic                     quotient, divide, minus, power, rem
67         binary logical                          implies, equivalent, approx
68         binary set operators                    setdiff
69         binary linear algebra                   vectorproduct, scalarproduct, outerproduct
70 -->
71
72 <!-- N-ARY and OTHER
73          n-ary statistical mean, sdev, variance, median, mode
74         n-ary logical and, or, xor
75         n-ary linear algebra selector
76         n-ary set operator union, intersect
77         n-ary functional fn, compose
78         integral, sum, product operators int, sum, product
79         differential operator diff, partialdiff
80         quantifier forall, exists
81 -->
82 <!-- Get the first child (operator), and check if its name is a fn , or operator-->
83 <!-- Is the operator taking qualifiers? -->
84 <!-- Operators  : int, sum, product, root, diff, partialdiff, limit, log, moment, min, max, forall, exists -->
85 <!-- Qualifiers : lowlimit, uplimit, bvar, degree, logbase, interval, condition  -->
86
87
88 <!-- apply/apply -->
89 <xsl:template match="mml:apply[mml:apply]">  <!-- when the function itself is defined by other functions: (F+G)(x) -->
90         <xsl:choose>
91                 <xsl:when test="count(child::*)>=2">
92                         <xsl:text>{</xsl:text><xsl:apply-templates select="child::*[position()=1]"/><xsl:text>}</xsl:text>      
93                         <xsl:text>{</xsl:text><xsl:apply-templates select="child::*[position()!=1]"/><xsl:text>}</xsl:text>     
94                 </xsl:when>
95         <xsl:otherwise> <!-- apply only contains apply, no operand-->
96                         <xsl:text>{</xsl:text><xsl:apply-templates select="child::*"/><xsl:text>}</xsl:text>    
97         </xsl:otherwise>
98         </xsl:choose>
99 </xsl:template>
100
101
102 <!-- force function or operator MathML 1.0 deprecated-->
103 <!-- partial support for func/operators defined using presentation markup-->
104 <xsl:template match="mml:apply[mml:fn]">
105 <mrow>
106 <xsl:choose>
107 <xsl:when test="*[position()=1 and self::mml:fn]/mml:mo/mml:mchar/@name='PlusMinus'">
108   <!--if operator is infix (we assume this to be the default when we have mchars(for instance PlusMinus); perhaps we should test further the name attribute)-->
109   <xsl:choose>
110   <xsl:when test="count(child::*)>=3">
111     <mrow>
112       <xsl:for-each select="child::*[position()!=last() and  position()!=1]">
113         <xsl:apply-templates select="."/><xsl:copy-of select="preceding-sibling::mml:fn/*"/>
114       </xsl:for-each>
115       <xsl:apply-templates select="child::*[position()!=1 and position()=last()]"/>
116     </mrow>
117   </xsl:when>
118   <xsl:when test="count(child::*)=2">
119     <mrow><xsl:copy-of select="child::mml:fn[position()=1]/*"/><xsl:apply-templates select="child::*[position()=2]"/></mrow>
120   </xsl:when>
121   <xsl:otherwise> <!-- apply only contains fn, no operand-->
122     <mrow><xsl:apply-templates select="child::mml:fn/*"/></mrow>
123   </xsl:otherwise>
124   </xsl:choose>
125 </xsl:when>  
126 <xsl:otherwise>  <!-- if operator is prefix (common case)-->
127   <xsl:choose>
128     <xsl:when test="name(mml:fn/*[position()=1])='apply'"> <!-- fn definition is complex, surround with brackets, but only one child-->
129       <mfenced separators=""><mrow><xsl:apply-templates select="mml:fn/*"/></mrow></mfenced>
130     </xsl:when>
131     <xsl:otherwise>
132       <mi><xsl:apply-templates select="mml:fn/*"/></mi>
133     </xsl:otherwise>
134   </xsl:choose>
135   <xsl:if test="count(*)>1">  <!-- if no operands, don't put empty parentheses-->
136     <mo><mchar name="ApplyFunction"/></mo>
137     <mfenced>
138       <xsl:apply-templates select="*[position()!=1]"/>
139     </mfenced>
140   </xsl:if>
141 </xsl:otherwise>
142 </xsl:choose>
143 </mrow>
144 </xsl:template>
145
146
147
148
149 <!-- quotient -->
150 <xsl:template match="mml:apply[mml:quotient]">
151   <mrow>  <!-- the third notation uses UNICODE chars x0230A and x0230B -->
152     <mo>integer part of</mo>
153     <mrow>
154       <xsl:choose> <!-- surround with brackets if operands are composed-->
155       <xsl:when test="child::*[position()=2] and name()='mml:apply'">
156         <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
157       </xsl:when>
158       <xsl:otherwise>
159         <xsl:apply-templates select="*[position()=2]"/>
160       </xsl:otherwise>
161       </xsl:choose>
162       <mo>/</mo>
163       <xsl:choose>
164       <xsl:when test="child::*[position()=3] and name()='mml:apply'">
165         <mfenced separators=""><xsl:apply-templates select="*[position()=3]"/></mfenced>
166       </xsl:when>
167       <xsl:otherwise>
168         <xsl:apply-templates select="*[position()=3]"/>
169       </xsl:otherwise>
170       </xsl:choose>
171     </mrow>
172   </mrow>
173 </xsl:template>
174
175
176 <!-- factorial -->
177 <xsl:template match="mml:apply[mml:factorial]">
178         <xsl:text>{</xsl:text>
179         <xsl:choose> 
180                 <xsl:when test="name(*[position()=2])='mml:apply'">
181                         <xsl:text>{</xsl:text><xsl:apply-templates select="*[position()=2]"/><xsl:text>}</xsl:text>
182                 </xsl:when>
183                 <xsl:otherwise>
184                         <xsl:apply-templates select="*[position()=2]"/>
185                 </xsl:otherwise>
186         </xsl:choose>
187         <xsl:text>!(fact)</xsl:text>
188         <xsl:text>}</xsl:text>
189 </xsl:template>
190
191
192 <!-- divide -->
193 <xsl:template match="mml:apply[mml:divide]">
194         <xsl:text>{ \frac</xsl:text>
195         <xsl:text>{ </xsl:text>
196         <xsl:apply-templates select="child::*[position()=2]"/>
197         <xsl:text>}</xsl:text>
198         <xsl:text>{ </xsl:text>
199         <xsl:apply-templates select="child::*[position()=3]"/>
200         <xsl:text>}</xsl:text>
201         <xsl:text>}</xsl:text>
202 </xsl:template>
203
204
205 <!-- APPLY CONTAINING MAX       -->
206 <xsl:template match="mml:apply/mml:max"/>
207 <xsl:template match="mml:apply[mml:max]">
208         <xsl:text>{</xsl:text>
209         <xsl:choose>
210                 <xsl:when test="mml:bvar"> <!-- if there are bvars-->
211                         <xsl:text>\max_{</xsl:text>
212                 <!-- Select every bvar except the last one (position() only counts bvars, not the other siblings)-->
213                         <xsl:for-each select="mml:bvar[position()!=last()]">  
214                         <xsl:apply-templates select="."/><xsl:text>,</xsl:text>
215                         </xsl:for-each>
216                         <xsl:apply-templates select="mml:bvar[position()=last()]"/>
217                         <xsl:text>}</xsl:text>
218                 </xsl:when>
219                 <xsl:otherwise> <!-- No bvars, no underscore... -->
220                         <xsl:text>\max</xsl:text>
221                 </xsl:otherwise>
222         </xsl:choose>
223         <xsl:text>\left\{</xsl:text>
224         <xsl:for-each select="child::*[name()!='mml:condition' and      name()!='mml:bvar' and  name()!='mml:max' and   position()!=last()]">
225                 <xsl:apply-templates select="."/><xsl:text>,</xsl:text>
226                 <xsl:message>RCAS: MathML mml:apply[mml:min] Applying templates to <xsl:copy-of select="name(.)"/></xsl:message>
227         </xsl:for-each>
228         <xsl:apply-templates select="child::*[name()!='mml:condition' and       name()!='mml:bvar' and  name()!='mml:max' and   position()=last()]"/>
229         <!-- If there is a condition, do not close... -->       
230         <xsl:if test="mml:condition">
231                 <xsl:text>|</xsl:text><xsl:apply-templates select="mml:condition"/>
232         </xsl:if>
233         <xsl:text>\right\}</xsl:text>
234         <xsl:text>}</xsl:text>
235 </xsl:template>
236
237
238 <!-- APPLY CONTAINING MIN       -->
239 <xsl:template match="mml:apply/mml:min"/>
240 <xsl:template match="mml:apply[mml:min]">
241         <xsl:text>{</xsl:text>
242         <xsl:choose>
243                 <xsl:when test="mml:bvar"> <!-- if there are bvars-->
244                         <xsl:text>\min_{</xsl:text>
245                         <!-- Select every bvar except the last one (position() only counts bvars, not the other siblings)-->
246                         <xsl:for-each select="mml:bvar[position()!=last()]">  
247                         <xsl:apply-templates select="."/><xsl:text>,</xsl:text>
248                         </xsl:for-each>
249                         <xsl:apply-templates select="mml:bvar[position()=last()]"/>
250                         <xsl:text>}</xsl:text>
251                 </xsl:when>
252                 <xsl:otherwise> <!-- No bvars, no underscore... -->
253                         <xsl:text>\min</xsl:text>
254                 </xsl:otherwise>
255         </xsl:choose>
256         <xsl:text>\left\{</xsl:text>
257         <xsl:for-each select="child::*[name()!='mml:condition' and      name()!='mml:bvar' and  name()!='mml:min' and   position()!=last()]">
258                 <xsl:message>RCAS: MathML mml:apply[mml:min] Applying templates to <xsl:copy-of select="name(.)"/></xsl:message>
259                 <xsl:apply-templates select="."/>
260                 <xsl:text>,</xsl:text>
261         </xsl:for-each>
262         <xsl:apply-templates select="child::*[name()!='mml:condition' and       name()!='mml:bvar' and  name()!='mml:min' and   position()=last()]"/>
263         <!-- If there is a condition, do not close... -->       
264         <xsl:if test="mml:condition">
265                 <xsl:text>|</xsl:text><xsl:apply-templates select="mml:condition"/>
266         </xsl:if>
267         <xsl:text>\right\}</xsl:text>
268         <xsl:text>}</xsl:text>
269 </xsl:template>
270
271
272
273
274
275
276
277
278 <!-- APPLY CONTAINING substraction(minus)       -->
279 <!-- unary or binary operator                   -->
280 <xsl:template match="mml:apply[mml:minus]">
281 <xsl:text>{</xsl:text>
282 <xsl:choose> <!-- binary -->
283         <xsl:when test="count(child::*)=3">
284                 <xsl:apply-templates select="child::*[position()=2]"/>
285                 <xsl:text>-</xsl:text>
286                 <xsl:choose>
287                 <xsl:when test="((name(*[position()=3])='mml:ci' or name(*[position()=3])='mml:cn') and contains(*[position()=3]/text(),'-')) or (name(*[position()=3])='mml:apply')">
288                         <xsl:text>\left(</xsl:text> <xsl:apply-templates select="*[position()=3]"/><xsl:text>\right)</xsl:text>
289                         <!-- surround negative or complex things with brackets -->
290                         </xsl:when>
291                 <xsl:otherwise>
292                         <xsl:apply-templates select="*[position()=3]"/>
293                       </xsl:otherwise>
294                 </xsl:choose>
295         </xsl:when>
296         <xsl:otherwise> <!-- unary -->
297                 <xsl:text>-</xsl:text>
298                 <xsl:choose>
299                 <xsl:when test=
300                         "((name(*[position()=2])='mml:ci' or name(*[position()=2])='mml:cn') and contains(*[position()=2]/text(),'-')) or (name(*[position()=2])='mml:apply')">
301                         <xsl:text>\left(</xsl:text>
302                                 <xsl:apply-templates select="child::*[position()=last()]"/>
303                         <xsl:text>\right)</xsl:text>
304                 </xsl:when>
305                 <xsl:otherwise>
306                         <xsl:apply-templates select="child::*[position()=last()]"/>
307                 </xsl:otherwise>
308                 </xsl:choose>
309         </xsl:otherwise>
310 </xsl:choose>
311 <xsl:text>}</xsl:text>
312 </xsl:template>
313
314
315 <!-- addition -->
316 <xsl:template match="mml:apply[mml:plus]">
317   <xsl:choose>
318   <xsl:when test="count(child::*)>=3">
319     <mrow>
320       <xsl:choose>
321         <xsl:when test="((name(*[position()=2])='mml:ci' or name(*[position()=2])='mml:cn') and contains(*[position()=2]/text(),'-')) or (*[position()=2 and self::mml:apply and child::mml:minus])">
322           <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced> <!-- surround negative things with brackets -->
323         </xsl:when>
324         <xsl:otherwise>
325           <xsl:apply-templates select="*[position()=2]"/>
326         </xsl:otherwise>
327       </xsl:choose>
328       <xsl:for-each select="child::*[position()!=1 and position()!=2]">
329         <xsl:choose>
330         <xsl:when test="((name(.)='mml:ci' or name(.)='mml:cn') and contains(./text(),'-')) or (self::mml:apply and child::mml:minus)"> <!-- surround negative things with brackets -->
331           <mo>+</mo><mfenced separators=""><xsl:apply-templates select="."/></mfenced>
332         </xsl:when>
333         <xsl:otherwise>
334           <mo>+</mo><xsl:apply-templates select="."/>
335         </xsl:otherwise>
336         </xsl:choose>
337       </xsl:for-each>
338     </mrow>
339   </xsl:when>
340   <xsl:when test="count(child::*)=2">
341     <mrow>
342       <mo>+</mo><xsl:apply-templates select="child::*[position()=2]"/>
343     </mrow>
344   </xsl:when>
345   <xsl:otherwise>
346     <mo>+</mo>
347   </xsl:otherwise>
348   </xsl:choose>
349 </xsl:template>
350
351 <!-- power -->
352 <xsl:template match="mml:apply[mml:power]">
353         <xsl:text> {</xsl:text>
354         <xsl:choose>
355                 <xsl:when test="name(*[position()=2])='mml:apply'">
356                         <xsl:text>\left(</xsl:text>
357                         <xsl:apply-templates select="child::*[position()=2]"/>
358                         <xsl:text>\rigth)</xsl:text>
359                 </xsl:when>
360                 <xsl:otherwise>
361                         <xsl:apply-templates select="child::*[position()=2]"/>
362                 </xsl:otherwise>
363         </xsl:choose>
364         <xsl:text>}^{</xsl:text>
365                 <xsl:apply-templates select="child::*[position()=3]"/>
366         <xsl:text>} </xsl:text>
367 </xsl:template>
368
369 <!-- remainder -->
370 <xsl:template match="mml:apply[mml:rem]">
371   <mrow>
372     <xsl:choose> <!-- surround with brackets if operands are composed-->
373     <xsl:when test="name(*[position()=2])='mml:apply'">
374       <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
375     </xsl:when>
376     <xsl:otherwise>
377       <xsl:apply-templates select="*[position()=2]"/>
378     </xsl:otherwise>
379     </xsl:choose>
380     <mo>mod</mo>
381     <xsl:choose>
382     <xsl:when test="name(*[position()=3])='mml:apply'">
383       <mfenced separators=""><xsl:apply-templates select="*[position()=3]"/></mfenced>
384     </xsl:when>
385     <xsl:otherwise>
386       <xsl:apply-templates select="*[position()=3]"/>
387     </xsl:otherwise>
388     </xsl:choose>
389   </mrow>
390 </xsl:template>
391
392 <!-- multiplication -->
393 <xsl:template match="mml:apply[mml:times]">
394 <xsl:choose>
395 <xsl:when test="count(child::*)>=3">
396   <mrow>
397     <xsl:for-each select="child::*[position()!=last() and  position()!=1]">
398       <xsl:choose>
399       <xsl:when test="mml:plus"> <!--add brackets around + children for priority purpose-->
400         <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><mchar name="InvisibleTimes"/></mo>
401       </xsl:when>
402       <xsl:when test="mml:minus"> <!--add brackets around - children for priority purpose-->
403         <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><mchar name="InvisibleTimes"/></mo>
404       </xsl:when>
405       <xsl:when test="(name(.)='mml:ci' or name(.)='mml:cn') and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in XT-->
406         <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><mchar name="InvisibleTimes"/></mo>
407       </xsl:when>
408       <xsl:otherwise>
409         <xsl:apply-templates select="."/><mo><mchar name="InvisibleTimes"/></mo>
410       </xsl:otherwise>
411       </xsl:choose>
412     </xsl:for-each>
413     <xsl:for-each select="child::*[position()=last()]">
414       <xsl:choose>
415       <xsl:when test="mml:plus">
416         <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
417       </xsl:when>
418       <xsl:when test="mml:minus">
419         <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
420       </xsl:when>
421       <xsl:when test="(name(.)='mml:ci' or name(.)='mml:cn') and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in  XT-->
422         <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
423       </xsl:when>
424       <xsl:otherwise>
425         <xsl:apply-templates select="."/>
426       </xsl:otherwise>
427       </xsl:choose>
428     </xsl:for-each>
429   </mrow>
430 </xsl:when>
431 <xsl:when test="count(child::*)=2">  <!-- unary -->
432   <mrow>
433     <mo><mchar name="InvisibleTimes"/></mo>
434     <xsl:choose>
435       <xsl:when test="mml:plus">
436         <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
437       </xsl:when>
438       <xsl:when test="mml:minus">
439         <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
440       </xsl:when>
441       <xsl:when test="(*[position()=2 and self::mml:ci] or *[position()=2 and self::mml:cn]) and contains(*[position()=2]/text(),'-')">
442         <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
443       </xsl:when>
444       <xsl:otherwise>
445         <xsl:apply-templates select="*[position()=2]"/>
446       </xsl:otherwise>
447     </xsl:choose>
448   </mrow>
449 </xsl:when>
450 <xsl:otherwise>  <!-- no operand -->
451   <mo><mchar name="InvisibleTimes"/></mo>
452 </xsl:otherwise>
453 </xsl:choose>
454 </xsl:template>
455
456 <!-- root -->
457 <xsl:template match="mml:apply[mml:root]">
458   <xsl:choose>
459   <xsl:when test="mml:degree">
460     <xsl:choose>
461     <xsl:when test="mml:degree/mml:cn/text()='2'"> <!--if degree=2 display a standard square root-->
462       <msqrt>
463         <xsl:apply-templates select="child::*[position()=3]"/>
464       </msqrt>
465     </xsl:when>
466     <xsl:otherwise>
467       <mroot>
468         <xsl:apply-templates select="child::*[position()=3]"/>
469         <mrow><xsl:apply-templates select="mml:degree/*"/></mrow>
470       </mroot>
471     </xsl:otherwise>
472     </xsl:choose>
473   </xsl:when>
474   <xsl:otherwise> <!-- no degree specified-->
475     <msqrt>
476       <xsl:apply-templates select="child::*[position()=2]"/>
477     </msqrt>
478   </xsl:otherwise>
479   </xsl:choose>
480 </xsl:template>
481
482 <!-- greatest common divisor -->
483 <xsl:template match="mml:apply[mml:gcd]">
484   <mrow>
485     <mi>gcd</mi><mo><mchar name="ApplyFunction"/></mo>
486     <mfenced>
487       <xsl:apply-templates select="child::*[position()!=1]"/>
488     </mfenced>
489   </mrow>
490 </xsl:template>
491
492 <!-- AND -->
493 <xsl:template match="mml:apply[mml:and]">
494 <mrow>
495   <xsl:choose>
496   <xsl:when test="count(*)>=3"> <!-- at least two operands (common case)-->
497     <xsl:for-each select="child::*[position()!=last() and  position()!=1]">
498       <xsl:choose>
499       <xsl:when test="mml:or"> <!--add brackets around OR children for priority purpose-->
500         <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><mchar name="And"/></mo>
501       </xsl:when>
502       <xsl:when test="mml:xor"> <!--add brackets around XOR children for priority purpose-->
503        <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><mchar name="And"/></mo> 
504       </xsl:when>
505       <xsl:otherwise>
506         <xsl:apply-templates select="."/><mo><mchar name="And"/></mo>
507       </xsl:otherwise>
508       </xsl:choose>
509     </xsl:for-each>
510     <xsl:for-each select="child::*[position()=last()]">
511       <xsl:choose>
512       <xsl:when test="mml:or">
513         <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
514       </xsl:when>
515       <xsl:when test="mml:xor">
516         <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
517       </xsl:when>
518       <xsl:otherwise>
519         <xsl:apply-templates select="."/>
520       </xsl:otherwise>
521       </xsl:choose>
522     </xsl:for-each>
523   </xsl:when>
524   <xsl:when test="count(*)=2">
525     <mo><mchar name="And"/></mo><xsl:apply-templates select="*[position()=last()]"/>
526   </xsl:when>
527   <xsl:otherwise>
528     <mo><mchar name="And"/></mo>
529   </xsl:otherwise>
530   </xsl:choose>
531 </mrow>
532 </xsl:template>
533
534 <!-- OR -->
535 <xsl:template match="mml:apply[mml:or]">
536 <mrow>
537   <xsl:choose>
538   <xsl:when test="count(*)>=3">
539     <xsl:for-each select="child::*[position()!=last() and  position()!=1]">
540       <xsl:apply-templates select="."/><mo><mchar name="Or"/></mo>
541     </xsl:for-each>
542     <xsl:apply-templates select="child::*[position()=last()]"/>
543     </xsl:when>
544     <xsl:when test="count(*)=2">
545       <mo><mchar name="Or"/></mo><xsl:apply-templates select="*[position()=last()]"/>
546   </xsl:when>
547   <xsl:otherwise>
548     <mo><mchar name="Or"/></mo>
549   </xsl:otherwise>
550   </xsl:choose>
551 </mrow>
552 </xsl:template>
553
554 <!-- XOR -->
555 <xsl:template match="mml:apply[mml:xor]">
556 <mrow>
557   <xsl:choose>
558   <xsl:when test="count(*)>=3">
559     <xsl:for-each select="child::*[position()!=last() and  position()!=1]">
560       <xsl:apply-templates select="."/><mo>xor</mo>
561     </xsl:for-each>
562     <xsl:apply-templates select="child::*[position()=last()]"/>
563     </xsl:when>
564     <xsl:when test="count(*)=2">
565       <mo>xor</mo><xsl:apply-templates select="*[position()=last()]"/>
566   </xsl:when>
567   <xsl:otherwise>
568     <mo>xor</mo>
569   </xsl:otherwise>
570   </xsl:choose>
571 </mrow>
572 </xsl:template>
573
574 <!-- NOT -->
575 <xsl:template match="mml:apply[mml:not]">
576   <mrow>
577     <mo><mchar name="Not"/></mo>
578     <xsl:choose>
579     <xsl:when test="child::mml:apply"><!--add brackets around OR,AND,XOR children for priority purpose-->
580       <mfenced separators="">
581         <xsl:apply-templates select="child::*[position()=2]"/>
582       </mfenced>
583     </xsl:when>
584     <xsl:otherwise>
585       <xsl:apply-templates select="child::*[position()=2]"/>
586     </xsl:otherwise>
587     </xsl:choose>
588   </mrow>
589 </xsl:template>
590
591 <!-- implies -->
592 <xsl:template match="mml:apply[mml:implies]">
593   <mrow>
594     <xsl:apply-templates select="child::*[position()=2]"/>
595     <mo><mchar name="DoubleRightArrow"/></mo>
596     <xsl:apply-templates select="child::*[position()=3]"/>
597   </mrow>
598 </xsl:template>
599
600 <xsl:template match="mml:reln[mml:implies]">
601   <mrow>
602     <xsl:apply-templates select="child::*[position()=2]"/>
603     <mo><mchar name="DoubleRightArrow"/></mo>
604     <xsl:apply-templates select="child::*[position()=3]"/>
605   </mrow>
606 </xsl:template>
607
608 <!-- for all-->
609 <xsl:template match="mml:apply[mml:forall]">
610   <mrow>
611     <mo><mchar name="ForAll"/></mo>
612     <mrow>
613       <xsl:for-each select="mml:bvar[position()!=last()]">
614         <xsl:apply-templates select="."/><mo>,</mo>
615       </xsl:for-each>
616       <xsl:apply-templates select="mml:bvar[position()=last()]"/>
617     </mrow>
618     <xsl:if test="mml:condition">
619       <mrow><mo>,</mo><xsl:apply-templates select="mml:condition"/></mrow>
620     </xsl:if>
621     <xsl:choose>
622       <xsl:when test="mml:apply">
623         <mo>:</mo><xsl:apply-templates select="mml:apply"/>
624       </xsl:when>
625       <xsl:when test="mml:reln">
626         <mo>:</mo><xsl:apply-templates select="mml:reln"/>
627       </xsl:when>
628     </xsl:choose>
629   </mrow>
630 </xsl:template>
631
632 <!-- in -->
633 <xsl:template match="mml:apply[mml:in]">
634         <xsl:text>{</xsl:text>
635         <xsl:apply-templates select="child::*[position()=2]"/>
636         <xsl:text>\in</xsl:text>
637         <xsl:apply-templates select="child::*[position()=3]"/>
638         <xsl:text>}</xsl:text>
639 </xsl:template>
640
641 <!-- notin -->
642 <xsl:template match="mml:apply[mml:notin]">
643         <xsl:text>{</xsl:text>
644         <xsl:apply-templates select="child::*[position()=2]"/>
645         <xsl:text>\notin</xsl:text>
646         <xsl:apply-templates select="child::*[position()=3]"/>
647         <xsl:text>}</xsl:text>
648 </xsl:template>
649
650 <!-- exist-->
651 <xsl:template match="mml:apply[mml:exists]">
652   <mrow>
653     <mo><mchar name="Exists"/></mo>
654     <mrow>
655       <xsl:for-each select="mml:bvar[position()!=last()]">
656         <xsl:apply-templates select="."/><mo>,</mo>
657       </xsl:for-each>
658       <xsl:apply-templates select="mml:bvar[position()=last()]"/>
659     </mrow>
660     <xsl:if test="mml:condition">
661       <mrow><mo>,</mo><xsl:apply-templates select="mml:condition"/></mrow>
662     </xsl:if>
663     <xsl:choose>
664       <xsl:when test="mml:apply">
665         <mo>:</mo><xsl:apply-templates select="mml:apply"/>
666       </xsl:when>
667       <xsl:when test="mml:reln">
668         <mo>:</mo><xsl:apply-templates select="mml:reln"/>
669       </xsl:when>
670     </xsl:choose>
671   </mrow>
672 </xsl:template>
673
674 <!-- absolute value -->
675 <xsl:template match="mml:apply[mml:abs]">
676   <mrow><mo>|</mo><xsl:apply-templates select="child::*[position()=last()]"/><mo>|</mo></mrow>
677 </xsl:template>
678
679 <!-- conjugate -->
680 <xsl:template match="mml:apply[mml:conjugate]">
681   <mover>
682     <xsl:apply-templates select="child::*[position()=2]"/>
683     <mo><mchar name="ovbar"/></mo>  <!-- does not work, UNICODE x0233D  or perhaps OverBar-->
684   </mover>
685 </xsl:template>
686
687 <!-- argument of complex number -->
688 <xsl:template match="mml:apply[mml:arg]">
689   <mrow>
690     <mi>arg</mi><mo><mchar name="ApplyFunction"/></mo><mfenced separators=""><xsl:apply-templates select="child::*[position()=2]"/></mfenced>
691   </mrow>
692 </xsl:template>
693
694 <!-- real part of complex number -->
695 <xsl:template match="mml:apply[mml:real]">
696   <mrow>
697     <mi><xsl:text disable-output-escaping='yes'>&amp;#x0211C;</xsl:text><!-- mchar Re or realpart should work--></mi>
698     <mo><mchar name="ApplyFunction"/></mo>
699     <mfenced separators=""><xsl:apply-templates select="child::*[position()=2]"/></mfenced>
700   </mrow>
701 </xsl:template>
702
703 <!-- imaginary part of complex number -->
704 <xsl:template match="mml:apply[mml:imaginary]">
705   <mrow>
706     <mi><xsl:text disable-output-escaping='yes'>&amp;#x02111;</xsl:text><!-- mchar Im or impart should work--></mi>
707     <mo><mchar name="ApplyFunction"/></mo>
708     <mfenced separators=""><xsl:apply-templates select="child::*[position()=2]"/></mfenced>
709   </mrow>
710 </xsl:template>
711
712 <!-- lowest common multiple -->
713 <xsl:template match="mml:apply[mml:lcm]">
714   <mrow>
715     <mi>lcm</mi><mo><mchar name="ApplyFunction"/></mo>
716     <mfenced>
717       <xsl:apply-templates select="child::*[position()!=1]"/>
718     </mfenced>
719   </mrow>
720 </xsl:template>
721
722
723 </xsl:stylesheet>