]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / DEVEL / mathml_editor / xsl / tml-mmlp.xsl
1 <?xml version="1.0"?>
2
3 <!--
4  This file is part of EdiTeX, an editor of mathematical
5  expressions based on TeX syntax.
6  
7  Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
8                     2003 Paolo Marinelli <pmarinel@cs.unibo.it>.
9
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 2.1 of the License, or (at your option) any later version.
14
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  Lesser General Public License for more details.
19
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24  For more information, please visit the project's home page
25  http://helm.cs.unibo.it/editex/
26  or send an email to <lpadovan@cs.unibo.it>
27 -->
28
29 <xsl:stylesheet
30      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
31      xmlns:tml="http://helm.cs.unibo.it/2002/TML"
32      xmlns:m="http://www.w3.org/1998/Math/MathML"
33      exclude-result-prefixes="tml"
34      version="1.0">
35
36   <xsl:output indent="yes"/>
37
38   <xsl:param name="id" select="/.."/>
39
40   <xsl:template match="/">
41     <xsl:choose>
42       <xsl:when test="$id">
43         <xsl:apply-templates select="descendant::*[@id=$id]"/>
44       </xsl:when>
45       <xsl:otherwise>
46         <xsl:apply-templates/>
47       </xsl:otherwise>
48     </xsl:choose>
49   </xsl:template>
50
51   <xsl:template match="tml:tex[not(tml:math)]">
52     <!-- This is an empty TeX document. We generate the corresponding  -->
53     <!-- empty MathML document.                                        -->
54     <m:math/>
55   </xsl:template>
56
57   <xsl:template match="tml:math">
58     <m:math>
59       <xsl:if test="@id">
60         <xsl:attribute name="xref">
61           <xsl:value-of select="@id"/>
62         </xsl:attribute>
63       </xsl:if>
64        <xsl:if test="@display='1'">
65         <xsl:attribute name="display">block</xsl:attribute>
66       </xsl:if>
67       <xsl:attribute name="display">block</xsl:attribute>
68       <xsl:apply-templates select="*"/>
69     </m:math>
70   </xsl:template>
71
72   <xsl:template match="tml:i">
73     <m:mi>
74       <xsl:if test="@id">
75         <xsl:attribute name="xref">
76           <xsl:value-of select="@id"/>
77         </xsl:attribute>
78       </xsl:if>
79       <xsl:value-of select="@val"/>
80     </m:mi>
81   </xsl:template>
82
83   <xsl:template match="tml:n">
84     <m:mn>
85       <xsl:if test="@id">
86         <xsl:attribute name="xref">
87           <xsl:value-of select="@id"/>
88         </xsl:attribute>
89       </xsl:if>
90       <xsl:value-of select="@val"/>
91     </m:mn>
92   </xsl:template>
93
94   <xsl:template match="tml:o">
95     <m:mo>
96       <xsl:if test="@id">
97         <xsl:attribute name="xref">
98           <xsl:value-of select="@id"/>
99         </xsl:attribute>
100       </xsl:if>
101       <xsl:value-of select="@val"/>
102     </m:mo>
103   </xsl:template>
104
105   <xsl:template match="tml:s">
106 <!-- this template is used only for testing purpose and should not be here-->
107     <m:mspace width="veryverythickmathspace">
108       <xsl:if test="@id">
109         <xsl:attribute name="xref">
110           <xsl:value-of select="@id"/>
111         </xsl:attribute>
112       </xsl:if>
113     </m:mspace>
114   </xsl:template>
115
116 <!--
117   <xsl:template name="cursor">
118     <xsl:choose>
119       <xsl:when test="contains(@val, '\')">
120         <m:mrow>
121           <xsl:if test="@id">
122             <xsl:attribute name="xref">
123               <xsl:value-of select="@id"/>
124             </xsl:attribute>
125           </xsl:if>
126           <xsl:if test="substring-before(@val, '\')">
127             <m:mtext><xsl:value-of select="substring-before(@val, '\')"/></m:mtext>
128           </xsl:if>
129           <m:mo stretchy="false">&#x2329;</m:mo>
130           <m:mtext mathcolor="blue"><xsl:value-of select="concat('\', substring-after(@val, '\'))"/></m:mtext>
131           <m:mo stretchy="false">&#x232a;</m:mo>
132         </m:mrow>
133       </xsl:when>
134       <xsl:when test="string-length(@val)>=1">
135         <m:mrow>
136           <xsl:if test="@id">
137             <xsl:attribute name="xref">
138               <xsl:value-of select="@id"/>
139             </xsl:attribute>
140           </xsl:if>
141           <xsl:choose>
142             <xsl:when test="contains('0123456789', substring(@val, 1, 1))">
143               <m:mn>
144                 <xsl:value-of select="@val"/>
145               </m:mn>
146             </xsl:when>
147             <xsl:otherwise>
148               <m:mi>
149                 <xsl:value-of select="@val"/>
150               </m:mi>
151             </xsl:otherwise>
152           </xsl:choose>
153           <m:mtext mathcolor="blue">I</m:mtext>
154         </m:mrow>
155       </xsl:when>
156       <xsl:otherwise>
157         <m:mtext mathcolor="blue">
158          <xsl:if test="@id">
159            <xsl:attribute name="xref">
160              <xsl:value-of select="@id"/>
161            </xsl:attribute>
162          </xsl:if>I</m:mtext>
163       </xsl:otherwise>
164     </xsl:choose>
165   </xsl:template>
166   -->
167
168   <xsl:template match="tml:o[@val='-']">
169     <m:mo>
170       <xsl:if test="@id">
171         <xsl:attribute name="xref">
172           <xsl:value-of select="@id"/>
173         </xsl:attribute>
174       </xsl:if>
175       &#x2212;
176     </m:mo>
177   </xsl:template>
178
179   <xsl:template match="tml:cursor">
180     <xsl:choose>
181       <xsl:when test="substring(@val,1,1)='\'">
182         <m:mrow>
183           <xsl:if test="@id">
184             <xsl:attribute name="xref">
185               <xsl:value-of select="@id"/>
186             </xsl:attribute>
187           </xsl:if>
188           <m:mo stretchy="false">&#x2329;</m:mo>
189           <m:mtext mathcolor="blue"><xsl:value-of select="@val"/></m:mtext>
190           <m:mo stretchy="false">&#x232a;</m:mo>
191         </m:mrow>
192       </xsl:when>
193       <xsl:when test="string-length(@val)>=1">
194         <m:mrow>
195           <xsl:if test="@id">
196             <xsl:attribute name="xref">
197               <xsl:value-of select="@id"/>
198             </xsl:attribute>
199           </xsl:if>
200           <xsl:choose>
201             <xsl:when test="contains('0123456789', substring(@val, 1, 1))">
202               <m:mn>
203                 <xsl:value-of select="@val"/>
204               </m:mn>
205             </xsl:when>
206             <xsl:otherwise>
207               <m:mi>
208                 <xsl:value-of select="@val"/>
209               </m:mi>
210             </xsl:otherwise>
211           </xsl:choose>
212           <xsl:if test="@visible='1'">
213            <m:mtext mathcolor="blue">I</m:mtext>
214           </xsl:if>
215         </m:mrow>
216       </xsl:when>
217       <xsl:otherwise>
218         <xsl:if test="@visible='1'">
219          <m:mtext mathcolor="blue">
220           <xsl:if test="@id">
221             <xsl:attribute name="xref">
222               <xsl:value-of select="@id"/>
223             </xsl:attribute>
224           </xsl:if>
225           <xsl:text>I</xsl:text>
226          </m:mtext>
227         </xsl:if>
228       </xsl:otherwise>
229     </xsl:choose>
230   </xsl:template>
231
232   <xsl:template match="tml:sb[@under='1'][*[1]/tml:sp[@over='1']]">
233     <m:munderover>
234       <xsl:if test="@id">
235         <xsl:attribute name="xref">
236           <xsl:value-of select="@id"/>
237         </xsl:attribute>
238       </xsl:if>
239       <xsl:apply-templates select="*[1]/*[1]"/>
240       <xsl:apply-templates select="*[2]"/>
241       <xsl:apply-templates select="*[1]/*[2]"/>
242     </m:munderover>
243   </xsl:template>
244
245   <xsl:template match="tml:sb[@under='1']">
246     <m:munder>
247       <xsl:if test="@id">
248         <xsl:attribute name="xref">
249           <xsl:value-of select="@id"/>
250         </xsl:attribute>
251       </xsl:if>
252       <xsl:apply-templates select="*[1]"/>
253       <xsl:apply-templates select="*[2]"/>
254     </m:munder>
255   </xsl:template>
256
257   <xsl:template match="tml:sb[*[1][self::tml:sp[not(@over) or @over='0']]]">
258     <m:msubsup>
259       <xsl:if test="@id">
260         <xsl:attribute name="xref">
261           <xsl:value-of select="@id"/>
262         </xsl:attribute>
263       </xsl:if>
264       <xsl:apply-templates select="*[1]/*[1]"/>
265       <xsl:apply-templates select="*[2]"/>
266       <xsl:apply-templates select="*[1]/*[2]"/>
267     </m:msubsup>
268   </xsl:template>
269
270   <xsl:template match="tml:sb">
271     <m:msub>
272       <xsl:if test="@id">
273         <xsl:attribute name="xref">
274           <xsl:value-of select="@id"/>
275         </xsl:attribute>
276       </xsl:if>
277       <xsl:apply-templates select="*[1]"/>
278       <xsl:apply-templates select="*[2]"/>
279     </m:msub>
280   </xsl:template>
281
282   <xsl:template match="tml:sp[@over='1'][*[1]/tml:sb[@under='1']]">
283     <m:munderover>
284       <xsl:if test="@id">
285         <xsl:attribute name="xref">
286           <xsl:value-of select="@id"/>
287         </xsl:attribute>
288       </xsl:if>
289       <xsl:apply-templates select="*[1]/*[1]"/>
290       <xsl:apply-templates select="*[1]/*[2]"/>
291       <xsl:apply-templates select="*[2]"/>
292     </m:munderover>
293   </xsl:template>
294
295   <xsl:template match="tml:sp[@over='1']">
296     <m:mover>
297       <xsl:if test="@id">
298         <xsl:attribute name="xref">
299           <xsl:value-of select="@id"/>
300         </xsl:attribute>
301       </xsl:if>
302       <xsl:apply-templates select="*[1]"/>
303       <xsl:apply-templates select="*[2]"/>
304     </m:mover>
305   </xsl:template>
306
307   <xsl:template match="tml:sp[*[1][self::tml:sb[not(@over) or @over='0']]]">
308     <m:msubsup>
309       <xsl:if test="@id">
310         <xsl:attribute name="xref">
311           <xsl:value-of select="@id"/>
312         </xsl:attribute>
313       </xsl:if>
314       <xsl:apply-templates select="*[1]/*[1]"/>
315       <xsl:apply-templates select="*[1]/*[2]"/>
316       <xsl:apply-templates select="*[2]"/>
317     </m:msubsup>
318   </xsl:template>
319
320   <xsl:template match="tml:sp">
321     <m:msup>
322       <xsl:if test="@id">
323         <xsl:attribute name="xref">
324           <xsl:value-of select="@id"/>
325         </xsl:attribute>
326       </xsl:if>
327       <xsl:apply-templates select="*[1]"/>
328       <xsl:apply-templates select="*[2]"/>
329     </m:msup>
330   </xsl:template>
331
332   <xsl:template match="tml:g">
333     <xsl:choose>
334       <xsl:when test="not(@id) and count(*) = 1">
335         <xsl:apply-templates select="*[1]"/>
336       </xsl:when>
337       <xsl:when test="tml:cursor">
338         <m:mstyle mathbackground="#e0e0e0">
339           <xsl:if test="@id">
340             <xsl:attribute name="xref">
341               <xsl:value-of select="@id"/>
342             </xsl:attribute>
343           </xsl:if>
344           <m:mrow>
345             <xsl:apply-templates select="*"/>
346           </m:mrow>
347         </m:mstyle>
348       </xsl:when>
349        <xsl:otherwise>
350         <m:mrow>
351           <xsl:if test="@id">
352             <xsl:attribute name="xref">
353               <xsl:value-of select="@id"/>
354             </xsl:attribute>
355           </xsl:if>
356           <xsl:apply-templates select="*"/>
357         </m:mrow>
358       </xsl:otherwise>
359     </xsl:choose>
360   </xsl:template>
361
362   <xsl:template match="tml:row">
363     <m:mtr>
364       <xsl:apply-templates select="cell"/>
365     </m:mtr>
366   </xsl:template>
367
368   <xsl:template match="tml:cell">
369     <m:mtd>
370       <xsl:apply-templates select="*"/>
371     </m:mtd>
372   </xsl:template>
373
374 <!--/// CONTROL SEQUENCES ///-->
375
376   <xsl:template match="tml:c">
377     <m:mrow>
378       <xsl:if test="@id">
379         <xsl:attribute name="xref">
380           <xsl:value-of select="@id"/>
381         </xsl:attribute>
382       </xsl:if>
383       <m:mtext mathcolor="blue">\<xsl:value-of select="@name"/></m:mtext>
384       <xsl:apply-templates select="*"/>
385     </m:mrow>
386   </xsl:template>
387
388   <xsl:template match="tml:c[@name='fun' and count(*)=3]">
389     <m:mrow>
390       <xsl:if test="@id">
391         <xsl:attribute name="xref">
392           <xsl:value-of select="@id"/>
393         </xsl:attribute>
394       </xsl:if>
395       <m:mo mathcolor="red">&#x03bb;</m:mo>
396       <xsl:apply-templates select="*[1]"/>
397       <m:mo>:</m:mo>
398       <xsl:apply-templates select="*[2]"/>
399       <m:mo>.</m:mo>
400       <xsl:apply-templates select="*[3]"/>
401     </m:mrow>
402   </xsl:template>
403
404   <xsl:template match="tml:c[@name='not'][*[1][self::tml:o]]">
405 <!-- not -->
406     <m:mo>
407       <xsl:if test="@id">
408         <xsl:attribute name="xref">
409           <xsl:value-of select="@id"/>
410         </xsl:attribute>
411       </xsl:if>
412       <xsl:value-of select="*[1]/@val"/>&#x0338;</m:mo>
413   </xsl:template>
414
415   <xsl:template match="tml:c[@name='buildrel']">
416 <!-- buildrel -->
417     <m:mover>
418       <xsl:if test="@id">
419         <xsl:attribute name="xref">
420           <xsl:value-of select="@id"/>
421         </xsl:attribute>
422       </xsl:if>
423       <xsl:apply-templates select="*[2]"/>
424       <xsl:apply-templates select="*[1]"/>
425     </m:mover>
426   </xsl:template>
427
428   <xsl:template match="tml:c[@name='left' or @name='right'][*[1][self::tml:o]]">
429 <!-- left -->
430     <m:mo stretchy="true">
431       <xsl:if test="@id">
432         <xsl:attribute name="xref">
433           <xsl:value-of select="@id"/>
434         </xsl:attribute>
435       </xsl:if>
436       <xsl:value-of select="*[1]/@val"/>
437     </m:mo>
438   </xsl:template>
439
440   <xsl:template match="tml:c[@name='bigl' or @name='bigr' or @name='bigm' or @name='big'][*[1][self::tml:o]]">
441 <!-- bigl -->
442     <m:mo stretchy="true" minsize="8.5pt">
443       <xsl:if test="@id">
444         <xsl:attribute name="xref">
445           <xsl:value-of select="@id"/>
446         </xsl:attribute>
447       </xsl:if>
448       <xsl:value-of select="*[1]/@val"/>
449     </m:mo>
450   </xsl:template>
451
452   <xsl:template match="tml:c[@name='Bigl' or @name='Bigr' or @name='Bigm'][*[1][self::tml:o]]">
453 <!-- Bigl -->
454     <m:mo stretchy="true" minsize="11.5pt">
455       <xsl:if test="@id">
456         <xsl:attribute name="xref">
457           <xsl:value-of select="@id"/>
458         </xsl:attribute>
459       </xsl:if>
460       <xsl:value-of select="*[1]/@val"/>
461     </m:mo>
462   </xsl:template>
463
464   <xsl:template match="tml:c[@name='biggl' or @name='biggr' or @name='biggm'][*[1][self::tml:o]]">
465 <!-- biggl -->
466     <m:mo stretchy="true" minsize="14.5pt">
467       <xsl:if test="@id">
468         <xsl:attribute name="xref">
469           <xsl:value-of select="@id"/>
470         </xsl:attribute>
471       </xsl:if>
472       <xsl:value-of select="*[1]/@val"/>
473     </m:mo>
474   </xsl:template>
475
476   <xsl:template match="tml:c[@name='Biggl' or @name='Biggr' or @name='Biggm'][*[1][self::tml:o]]">
477 <!-- biggl -->
478     <m:mo stretchy="true" minsize="17.5pt">
479       <xsl:if test="@id">
480         <xsl:attribute name="xref">
481           <xsl:value-of select="@id"/>
482         </xsl:attribute>
483       </xsl:if>
484       <xsl:value-of select="*[1]/@val"/>
485     </m:mo>
486   </xsl:template>
487
488   <xsl:template match="tml:c[@name='hat']">
489 <!-- hat -->
490     <m:mover accent="true">
491       <xsl:if test="@id">
492         <xsl:attribute name="xref">
493           <xsl:value-of select="@id"/>
494         </xsl:attribute>
495       </xsl:if>
496       <xsl:apply-templates select="*[1]"/>
497       <m:mo>&#x0302;</m:mo>
498     </m:mover>
499   </xsl:template>
500
501   <xsl:template match="tml:c[@name='widehat']">
502 <!-- widehat -->
503     <m:mover accent="false">
504       <xsl:if test="@id">
505         <xsl:attribute name="xref">
506           <xsl:value-of select="@id"/>
507         </xsl:attribute>
508       </xsl:if>
509       <xsl:apply-templates select="*[1]"/>
510       <m:mo stretchy="true">&#x0302;</m:mo>
511     </m:mover>
512   </xsl:template>
513
514   <xsl:template match="tml:c[@name='check']">
515 <!-- check -->
516     <m:mover accent="true">
517       <xsl:if test="@id">
518         <xsl:attribute name="xref">
519           <xsl:value-of select="@id"/>
520         </xsl:attribute>
521       </xsl:if>
522       <xsl:apply-templates select="*[1]"/>
523       <m:mo>&#x030c;</m:mo>
524     </m:mover>
525   </xsl:template>
526
527   <xsl:template match="tml:c[@name='tilde']">
528 <!-- tilde -->
529     <m:mover accent="true">
530       <xsl:if test="@id">
531         <xsl:attribute name="xref">
532           <xsl:value-of select="@id"/>
533         </xsl:attribute>
534       </xsl:if>
535       <xsl:apply-templates select="*[1]"/>
536       <m:mo>&#x0303;</m:mo>
537     </m:mover>
538   </xsl:template>
539
540   <xsl:template match="tml:c[@name='widetilde']">
541 <!-- widetilde -->
542     <m:mover>
543       <xsl:if test="@id">
544         <xsl:attribute name="xref">
545           <xsl:value-of select="@id"/>
546         </xsl:attribute>
547       </xsl:if>
548       <xsl:apply-templates select="*[1]"/>
549       <m:mo stretchy="true">&#x0303;</m:mo>
550     </m:mover>>
551   </xsl:template>
552
553   <xsl:template match="tml:c[@name='acute']">
554 <!-- acute -->
555     <m:mover accent="true">
556       <xsl:if test="@id">
557         <xsl:attribute name="xref">
558           <xsl:value-of select="@id"/>
559         </xsl:attribute>
560       </xsl:if>
561       <xsl:apply-templates select="*[1]"/>
562       <m:mo>&#x0301;</m:mo>
563     </m:mover>
564   </xsl:template>
565
566   <xsl:template match="tml:c[@name='grave']">
567 <!-- grave -->
568     <m:mover accent="true">
569       <xsl:if test="@id">
570         <xsl:attribute name="xref">
571           <xsl:value-of select="@id"/>
572         </xsl:attribute>
573       </xsl:if>
574       <xsl:apply-templates select="*[1]"/>
575       <m:mo>&#x0300;</m:mo>
576     </m:mover>>
577   </xsl:template>
578
579   <xsl:template match="tml:c[@name='dot']">
580 <!-- dot -->
581     <m:mover accent="true">
582       <xsl:if test="@id">
583         <xsl:attribute name="xref">
584           <xsl:value-of select="@id"/>
585         </xsl:attribute>
586       </xsl:if>
587       <xsl:apply-templates select="*[1]"/>
588       <m:mo>&#x0307;</m:mo>
589     </m:mover>
590   </xsl:template>
591
592   <xsl:template match="tml:c[@name='ddot']">
593 <!-- ddot -->
594     <m:mover accent="true">
595       <xsl:if test="@id">
596         <xsl:attribute name="xref">
597           <xsl:value-of select="@id"/>
598         </xsl:attribute>
599       </xsl:if>
600       <xsl:apply-templates select="*[1]"/>
601       <m:mo>&#x0308;</m:mo>
602     </m:mover>
603   </xsl:template>
604
605   <xsl:template match="tml:c[@name='breve']">
606 <!-- breve -->
607     <m:mover accent="true">
608       <xsl:if test="@id">
609         <xsl:attribute name="xref">
610           <xsl:value-of select="@id"/>
611         </xsl:attribute>
612       </xsl:if>
613       <xsl:apply-templates select="*[1]"/>
614       <m:mo>&#x0306;</m:mo>
615     </m:mover>
616   </xsl:template>
617
618   <xsl:template match="tml:c[@name='bar']">
619 <!-- bar -->
620     <m:mover accent="true">
621       <xsl:if test="@id">
622         <xsl:attribute name="xref">
623           <xsl:value-of select="@id"/>
624         </xsl:attribute>
625       </xsl:if>
626       <xsl:apply-templates select="*[1]"/>
627       <m:mo>&#x0304;</m:mo>
628     </m:mover>
629   </xsl:template>
630
631   <xsl:template match="tml:c[@name='vec']">
632 <!-- vec -->
633     <m:mover accent="true">
634       <xsl:if test="@id">
635         <xsl:attribute name="xref">
636           <xsl:value-of select="@id"/>
637         </xsl:attribute>
638       </xsl:if>
639       <xsl:apply-templates select="*[1]"/>
640       <m:mo>&#x20d7;</m:mo>
641     </m:mover>
642   </xsl:template>
643
644   <xsl:template match="tml:c[@name='overline']">
645 <!-- overline -->
646     <m:mover>
647       <xsl:if test="@id">
648         <xsl:attribute name="xref">
649           <xsl:value-of select="@id"/>
650         </xsl:attribute>
651       </xsl:if>
652       <xsl:apply-templates select="*[1]"/>
653       <m:mo stretchy="true">&#x0305;</m:mo>
654     </m:mover>
655   </xsl:template>
656
657   <xsl:template match="tml:c[@name='underline']">
658 <!-- underline -->
659     <m:munder>
660       <xsl:if test="@id">
661         <xsl:attribute name="xref">
662           <xsl:value-of select="@id"/>
663         </xsl:attribute>
664       </xsl:if>
665       <xsl:apply-templates select="*[1]"/>
666       <m:mo stretchy="true">&#x0332;</m:mo>
667     </m:munder>
668   </xsl:template>
669
670   <xsl:template match="tml:c[@name='sqrt']">
671 <!-- sqrt -->
672     <m:msqrt>
673       <xsl:if test="@id">
674         <xsl:attribute name="xref">
675           <xsl:value-of select="@id"/>
676         </xsl:attribute>
677       </xsl:if>
678       <xsl:apply-templates select="*"/>
679     </m:msqrt>
680   </xsl:template>
681
682   <xsl:template match="tml:c[@name='root']">
683 <!-- root -->
684     <m:mroot>
685       <xsl:if test="@id">
686         <xsl:attribute name="xref">
687           <xsl:value-of select="@id"/>
688         </xsl:attribute>
689       </xsl:if>
690       <xsl:choose>
691         <xsl:when test="count(*) &lt; 2">
692           <m:mrow/>
693           <xsl:apply-templates select="*[1]"/>
694         </xsl:when>
695         <xsl:otherwise>
696           <xsl:apply-templates select="*[2]"/>
697           <xsl:apply-templates select="*[1]"/>
698         </xsl:otherwise>
699       </xsl:choose>
700     </m:mroot>
701   </xsl:template>
702
703   <xsl:template match="tml:c[@name='frac']">
704 <!-- frac -->
705     <m:mfrac>
706       <xsl:if test="@id">
707         <xsl:attribute name="xref">
708           <xsl:value-of select="@id"/>
709         </xsl:attribute>
710       </xsl:if>
711       <xsl:apply-templates select="*[1]"/>
712       <xsl:apply-templates select="*[2]"/>
713     </m:mfrac>
714   </xsl:template>
715
716   <xsl:template match="tml:c[@name='over']">
717 <!-- over -->
718     <m:mfrac>
719       <xsl:if test="@id">
720         <xsl:attribute name="xref">
721           <xsl:value-of select="@id"/>
722         </xsl:attribute>
723       </xsl:if>
724       <xsl:apply-templates select="*[1]"/>
725       <xsl:apply-templates select="*[2]"/>
726     </m:mfrac>
727   </xsl:template>
728
729   <xsl:template match="tml:c[@name='atop']">
730 <!-- atop -->
731     <m:mfrac linethickness="0">
732       <xsl:if test="@id">
733         <xsl:attribute name="xref">
734           <xsl:value-of select="@id"/>
735         </xsl:attribute>
736       </xsl:if>
737       <xsl:apply-templates select="*[1]"/>
738       <xsl:apply-templates select="*[2]"/>
739     </m:mfrac>
740   </xsl:template>
741
742   <xsl:template match="tml:c[@name='choose']">
743 <!-- choose -->
744     <m:mrow>
745       <xsl:if test="@id">
746         <xsl:attribute name="xref">
747           <xsl:value-of select="@id"/>
748         </xsl:attribute>
749       </xsl:if>
750       <m:mo stretchy="true">(</m:mo>
751       <m:mfrac linethickness="0">
752         <xsl:apply-templates select="*[1]"/>
753         <xsl:apply-templates select="*[2]"/>
754       </m:mfrac>
755       <m:mo stretchy="true">)</m:mo>
756     </m:mrow>
757   </xsl:template>
758
759   <xsl:template match="tml:c[@name='brace']">
760 <!-- brace -->
761     <m:mrow>
762       <xsl:if test="@id">
763         <xsl:attribute name="xref">
764           <xsl:value-of select="@id"/>
765         </xsl:attribute>
766       </xsl:if>
767       <m:mo stretchy="true">{</m:mo>
768       <m:mfrac linethickness="0">
769         <xsl:apply-templates select="*[1]"/>
770         <xsl:apply-templates select="*[2]"/>
771       </m:mfrac>
772       <m:mo stretchy="true">}</m:mo>
773     </m:mrow>
774   </xsl:template>
775
776   <xsl:template match="tml:c[@name='brack']">
777 <!-- brack -->
778     <m:mrow>
779       <xsl:if test="@id">
780         <xsl:attribute name="xref">
781           <xsl:value-of select="@id"/>
782         </xsl:attribute>
783       </xsl:if>
784       <m:mo stretchy="true">[</m:mo>
785       <m:mfrac linethickness="0">
786         <xsl:apply-templates select="*[1]"/>
787         <xsl:apply-templates select="*[2]"/>
788       </m:mfrac>
789       <m:mo stretchy="true">]</m:mo>
790     </m:mrow>
791   </xsl:template>
792
793   <xsl:template match="tml:c[@name='displaystyle']">
794 <!-- displaystyle -->
795     <m:mstyle displaystyle="true">
796       <xsl:if test="@id">
797         <xsl:attribute name="xref">
798           <xsl:value-of select="@id"/>
799         </xsl:attribute>
800       </xsl:if>
801       <xsl:apply-templates select="*[1]"/>
802     </m:mstyle>
803   </xsl:template>
804
805   <xsl:template match="tml:c[@name='textstyle']">
806 <!-- textstyle -->
807     <m:mstyle scriptlevel="0">
808       <xsl:if test="@id">
809         <xsl:attribute name="xref">
810           <xsl:value-of select="@id"/>
811         </xsl:attribute>
812       </xsl:if>
813       <xsl:apply-templates select="*[1]"/>
814       <xsl:if test="tml:g/tml:cursor[@visible='1']">
815         <m:msub>
816           <m:mtext mathcolor="#808080">}</m:mtext>
817           <m:mtext><xsl:value-of select="@name"/></m:mtext>
818         </m:msub>
819       </xsl:if>
820     </m:mstyle>
821   </xsl:template>
822
823   <xsl:template match="tml:c[@name='scriptstyle']">
824 <!-- scriptstyle -->
825     <m:mstyle scriptlevel="1">
826       <xsl:if test="@id">
827         <xsl:attribute name="xref">
828           <xsl:value-of select="@id"/>
829         </xsl:attribute>
830       </xsl:if>
831       <xsl:apply-templates select="*[1]"/>
832     </m:mstyle>
833   </xsl:template>
834
835   <xsl:template match="tml:c[@name='scriptscriptstyle']">
836 <!-- scriptscriptstyle -->
837     <m:mstyle scriptlevel="2">
838       <xsl:if test="@id">
839         <xsl:attribute name="xref">
840           <xsl:value-of select="@id"/>
841         </xsl:attribute>
842       </xsl:if>
843       <xsl:apply-templates select="*[1]"/>
844     </m:mstyle>
845   </xsl:template>
846
847   <xsl:template match="tml:c[@name='pmod']">
848 <!-- pmod -->
849     <m:mrow>
850       <xsl:if test="@id">
851         <xsl:attribute name="xref">
852           <xsl:value-of select="@id"/>
853         </xsl:attribute>
854       </xsl:if>
855       <m:mo>(</m:mo>
856       <m:mrow>
857         <m:mo>mod</m:mo>
858         <xsl:apply-templates select="*[1]"/>
859       </m:mrow>
860       <m:mo>)</m:mo>
861     </m:mrow>
862   </xsl:template>
863
864   <xsl:template match="tml:c[@name='rm']">
865 <!-- rm -->
866     <m:mstyle mathvariant="normal">
867       <xsl:if test="@id">
868         <xsl:attribute name="xref">
869           <xsl:value-of select="@id"/>
870         </xsl:attribute>
871       </xsl:if>
872       <xsl:apply-templates select="*[1]"/>
873     </m:mstyle>
874   </xsl:template>
875
876   <xsl:template match="tml:c[@name='bf']">
877 <!-- bf -->
878     <m:mstyle mathvariant="bold">
879       <xsl:if test="@id">
880         <xsl:attribute name="xref">
881           <xsl:value-of select="@id"/>
882         </xsl:attribute>
883       </xsl:if>
884       <xsl:apply-templates select="*[1]"/>
885     </m:mstyle>
886   </xsl:template>
887
888   <xsl:template match="tml:c[@name='tt']">
889 <!-- tt -->
890     <m:mstyle mathvariant="monospace">
891       <xsl:if test="@id">
892         <xsl:attribute name="xref">
893           <xsl:value-of select="@id"/>
894         </xsl:attribute>
895       </xsl:if>
896       <xsl:apply-templates select="*[1]"/>
897     </m:mstyle>
898   </xsl:template>
899
900   <xsl:template match="tml:c[@name='sl']">
901 <!-- sl -->
902     <m:mstyle mathvariant="italic">
903       <xsl:if test="@id">
904         <xsl:attribute name="xref">
905           <xsl:value-of select="@id"/>
906         </xsl:attribute>
907       </xsl:if>
908       <xsl:apply-templates select="*[1]"/>
909     </m:mstyle>
910   </xsl:template>
911
912   <xsl:template match="tml:c[@name='it']">
913 <!-- it -->
914     <m:mstyle mathvariant="italic">
915       <xsl:if test="@id">
916         <xsl:attribute name="xref">
917           <xsl:value-of select="@id"/>
918         </xsl:attribute>
919       </xsl:if>
920       <xsl:apply-templates select="*[1]"/>
921     </m:mstyle>
922   </xsl:template>
923
924   <xsl:template match="tml:c[@name='_']">
925 <!-- _ -->
926     <m:mi>
927       <xsl:if test="@id">
928         <xsl:attribute name="xref">
929           <xsl:value-of select="@id"/>
930         </xsl:attribute>
931       </xsl:if>
932       <xsl:text>_</xsl:text>
933     </m:mi>
934   </xsl:template>
935
936   <xsl:template match="tml:c[@name=',']">
937 <!-- , -->
938     <m:mspace width="thinmathspace">
939       <xsl:if test="@id">
940         <xsl:attribute name="xref">
941           <xsl:value-of select="@id"/>
942         </xsl:attribute>
943       </xsl:if>
944     </m:mspace>
945   </xsl:template>
946
947   <xsl:template match="tml:c[@name='&gt;']">
948 <!-- > -->
949     <m:mspace width="mediummathspace">
950       <xsl:if test="@id">
951         <xsl:attribute name="xref">
952           <xsl:value-of select="@id"/>
953         </xsl:attribute>
954       </xsl:if>
955     </m:mspace>
956   </xsl:template>
957
958   <xsl:template match="tml:c[@name=';']">
959 <!-- ; -->
960     <m:mspace width="thickmathspace">
961       <xsl:if test="@id">
962         <xsl:attribute name="xref">
963           <xsl:value-of select="@id"/>
964         </xsl:attribute>
965       </xsl:if>
966     </m:mspace>
967   </xsl:template>
968
969   <xsl:template match="tml:c[@name='!']">
970 <!-- ! -->
971     <m:mspace width="-0.166667em">
972       <xsl:if test="@id">
973         <xsl:attribute name="xref">
974           <xsl:value-of select="@id"/>
975         </xsl:attribute>
976       </xsl:if>
977     </m:mspace>
978   </xsl:template>
979
980   <xsl:template name="table-content">
981       <xsl:choose>
982         <xsl:when test="tml:row">
983           <xsl:apply-templates select="tml:row"/>
984         </xsl:when>
985         <xsl:otherwise>
986           <m:mtr>
987             <m:mtd>
988               <xsl:apply-templates select="*"/>
989             </m:mtd>
990           </m:mtr>
991         </xsl:otherwise>
992       </xsl:choose>
993   </xsl:template>
994
995   <xsl:template match="tml:c[@name='matrix']">
996 <!-- matrix -->
997     <m:mtable>
998       <xsl:if test="@id">
999         <xsl:attribute name="xref">
1000           <xsl:value-of select="@id"/>
1001         </xsl:attribute>
1002       </xsl:if>
1003       <xsl:call-template name="table-content"/>
1004     </m:mtable>
1005   </xsl:template>
1006
1007   <xsl:template match="tml:row">
1008     <m:mtr>
1009       <xsl:apply-templates select="tml:cell"/>
1010     </m:mtr>
1011   </xsl:template>
1012
1013   <xsl:template match="tml:cell">
1014     <m:mtd>
1015       <xsl:apply-templates select="*"/>
1016     </m:mtd>
1017   </xsl:template>
1018
1019   <xsl:template match="tml:c[@name='pmatrix']">
1020 <!-- pmatrix -->
1021     <m:mrow>
1022       <xsl:if test="@id">
1023         <xsl:attribute name="xref">
1024           <xsl:value-of select="@id"/>
1025         </xsl:attribute>
1026       </xsl:if>
1027       <m:mo stretchy="true">(</m:mo>
1028       <m:mtable>
1029         <xsl:call-template name="table-content"/>
1030       </m:mtable>
1031       <m:mo stretchy="true">)</m:mo>
1032     </m:mrow>
1033   </xsl:template>
1034
1035   <xsl:template match="tml:c[@name='bordermatrix']">
1036 <!-- bordermatrix -->
1037     <m:mtable>
1038       <xsl:if test="@id">
1039         <xsl:attribute name="xref">
1040           <xsl:value-of select="@id"/>
1041         </xsl:attribute>
1042       </xsl:if>
1043       <m:mtr>
1044         <xsl:apply-templates select="tml:row[1]/tml:cell[1]"/>
1045         <m:mtd/>
1046         <xsl:apply-templates select="tml:row[1]/tml:cell[position() &gt; 1]"/>
1047         <m:mtd/>
1048       </m:mtr>
1049       <xsl:for-each select="tml:row[position() &gt; 1]">
1050         <m:mtr>
1051           <xsl:apply-templates select="tml:cell[1]"/>
1052           <xsl:if test="position() = 1">
1053             <m:mtd rowspan="{count(../tml:row) - 1}">
1054               <m:mo stretchy="true">(</m:mo>
1055             </m:mtd>
1056           </xsl:if>
1057           <xsl:apply-templates select="tml:cell[position() &gt; 1]"/>
1058           <xsl:if test="position() = 1">
1059             <m:mtd rowspan="{count(../tml:row) - 1}">
1060               <m:mo stretchy="true">)</m:mo>
1061             </m:mtd>
1062           </xsl:if>         
1063         </m:mtr>
1064       </xsl:for-each>      
1065     </m:mtable>
1066   </xsl:template>
1067
1068   <xsl:template match="tml:c[@name='overbrace']">
1069 <!-- overbrace -->
1070     <m:mover>
1071       <xsl:if test="@id">
1072         <xsl:attribute name="xref">
1073           <xsl:value-of select="@id"/>
1074         </xsl:attribute>
1075       </xsl:if>
1076       <xsl:apply-templates select="*[1]"/>
1077       <m:mo stretchy="true">????</m:mo>
1078     </m:mover>>
1079   </xsl:template>
1080
1081   <xsl:template match="tml:c[@name='underbrace']">
1082 <!-- underbrace -->
1083     <m:munder>
1084       <xsl:if test="@id">
1085         <xsl:attribute name="xref">
1086           <xsl:value-of select="@id"/>
1087         </xsl:attribute>
1088       </xsl:if>
1089       <xsl:apply-templates select="*[1]"/>
1090       <m:mo stretchy="true">????</m:mo>
1091     </m:munder>
1092   </xsl:template>
1093
1094   <xsl:template match="tml:c[@name='cases']">
1095 <!-- cases -->
1096     <m:mrow>
1097       <xsl:if test="@id">
1098         <xsl:attribute name="xref">
1099           <xsl:value-of select="@id"/>
1100         </xsl:attribute>
1101       </xsl:if>
1102       <m:mo stretchy="true">{</m:mo>
1103       <m:mtable>
1104         <xsl:call-template name="table-content"/>
1105       </m:mtable>
1106     </m:mrow>
1107   </xsl:template>
1108
1109   <xsl:template match="tml:c[@name='red']">
1110 <!-- red  -->
1111     <m:mstyle mathcolor="red">
1112       <xsl:if test="@id">
1113         <xsl:attribute name="xref">
1114           <xsl:value-of select="@id"/>
1115         </xsl:attribute>
1116         <xsl:apply-templates/>
1117       </xsl:if>
1118     </m:mstyle>
1119   </xsl:template>
1120
1121   <xsl:template match="tml:c[@name='green']">
1122 <!-- green  -->
1123     <m:mstyle mathcolor="green">
1124       <xsl:if test="@id">
1125         <xsl:attribute name="xref">
1126           <xsl:value-of select="@id"/>
1127         </xsl:attribute>
1128         <xsl:apply-templates/>
1129       </xsl:if>
1130     </m:mstyle>
1131   </xsl:template>
1132
1133   <xsl:template match="tml:c[@name='duedelim']">
1134 <!-- duedelim  -->
1135     <m:mfrac>
1136       <xsl:if test="@id">
1137         <xsl:attribute name="xref">
1138           <xsl:value-of select="@id"/>
1139         </xsl:attribute>
1140       </xsl:if>
1141       <xsl:apply-templates select="*[1]"/>
1142       <xsl:apply-templates select="*[2]"/>
1143     </m:mfrac>
1144   </xsl:template>
1145
1146   <xsl:template match="tml:c[@name='nodeside']">
1147 <!-- nodeside  -->
1148     <m:mfrac>
1149       <xsl:if test="@id">
1150         <xsl:attribute name="xref">
1151           <xsl:value-of select="@id"/>
1152         </xsl:attribute>
1153       </xsl:if>
1154       <xsl:apply-templates select="*[1]"/>
1155       <xsl:apply-templates select="*[2]"/>
1156     </m:mfrac>
1157   </xsl:template>
1158
1159 </xsl:stylesheet>