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