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