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