]> matita.cs.unibo.it Git - helm.git/blob - helm/style/mmlctop.xsl-0.14
Initial revision
[helm.git] / helm / style / mmlctop.xsl-0.14
1 <?xml version="1.0"?>
2
3 <!-- ******************************************************
4     
5      XSL Transform of MathML content to MathML presentation
6                                                     
7      Version 0.14, Dec. 13, 2000       
8      Authors Igor Rodionov <igor@csd.uwo.ca>,
9              Stephen Watt  <watt@csd.uwo.ca>.
10     
11      (C) Copyright 2000  Symbolic Computation Laboratory,
12                          University of Western Ontario,
13                          London, Canada N6A 5B7.
14      ****************************************************** -->
15
16
17 <!-- ====================================================== -->
18 <!--  April,28 2001 - HELM group:                           -->
19 <!--  Added the namespace prefix to all the output elements -->
20 <!--  Added the namespace prefix to all the xref attributes -->
21 <!--  Changed the mml prefix into m                         -->
22 <!--  Added m:xref to every mo element                      -->
23 <!--  Changed mchar into the corresponding entity           -->
24 <!--  First draft: April 27 2001, Irene Schena              -->
25 <!-- ====================================================== -->
26
27 <!-- Mostly complies with the W3C MathML 2.0 Candidate Recommenation 
28      of November 13, 2000.  The main difference is the use of <mchar>
29      which was removed from MathML 2.0 in the last working draft.
30   -->
31
32 <xsl:stylesheet id="mmlctop.xsl"
33                 version="1.0"
34                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
35                 xmlns:m="http://www.w3.org/1998/Math/MathML">
36
37 <!-- HELM: we don't have a default namespace.
38      Removed xmlns="http://www.w3.org/1998/Math/MathML" -->
39
40 <xsl:output method="xml" indent="yes"/>
41
42 <xsl:strip-space elements="apply semantics annotation-xml
43         csymbol fn cn ci interval matrix matrixrow vector
44         lambda bvar condition logbase degree set list
45         lowlimit uplimit"/>
46
47
48 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
49 <!--         Parameters, variables and constants           -->
50 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
51
52 <!-- ~~~~~~~~ Semantics related *constants*: ~~~~~~~~ -->
53
54 <!-- Strip off semantics -->
55 <xsl:variable name="SEM_STRIP" select="-1"/>
56
57 <!-- Pass semantics "as is" -->
58 <xsl:variable name="SEM_PASS" select="0"/>
59
60 <!-- Add semantics at top level only -->
61 <xsl:variable name="SEM_TOP" select="1"/>
62
63 <!-- Add semantics at all levels -->
64 <xsl:variable name="SEM_ALL" select="2"/>
65
66 <!-- Semantics at top level only, with id refs -->
67 <!-- NOTE: ids have to be already present in the
68            input for this feature to work. -->
69 <xsl:variable name="SEM_XREF" select="3"/>
70
71 <!-- No semantics at top level, with id refs -->
72 <!-- NOTE: ids have to be already present in the
73            input for this feature to work. -->
74 <xsl:variable name="SEM_XREF_EXT" select="4"/>
75
76
77 <!-- ~~~~~~~~~~ Stylesheet *parameter*: SEM_SW ~~~~~~~~~~~~~~ -->
78 <!-- Assumes one of the above values; SEM_PASS is the default -->
79 <!-- The default can be overridden by specifying different    -->
80 <!-- value on the command line when the stylesheet is invoked -->
81
82 <!-- HELM: $SEM_SW was SEM_PASS (error!) -->
83 <xsl:param name="SEM_SW" select="$SEM_XREF"/>
84
85 <!-- ~~~~~~ Operator precedence definitions ~~~~~~ -->
86
87 <xsl:variable name="NO_PREC" select="0"/>
88 <xsl:variable name="UNION_PREC" select="1"/>
89 <xsl:variable name="SETDIFF_PREC" select="1"/>
90 <xsl:variable name="INTERSECT_PREC" select="3"/>
91 <xsl:variable name="OR_PREC" select="5"/>
92 <xsl:variable name="XOR_PREC" select="5"/>
93 <xsl:variable name="AND_PREC" select="7"/>
94 <xsl:variable name="PLUS_PREC" select="9"/>
95 <xsl:variable name="MINUS_PREC" select="9"/>
96 <xsl:variable name="MUL_PREC" select="11"/>
97 <xsl:variable name="DIV_PREC" select="11"/>
98 <xsl:variable name="NEG_PREC" select="13"/>
99 <xsl:variable name="FUNCTION_PREC" select="99"/>
100
101 <!-- ~~~~~ Miscellaneous constant definitions ~~~~~ -->
102
103 <xsl:variable name="YES" select="1"/>
104 <xsl:variable name="NO" select="0"/>
105 <xsl:variable name="NO_PARAM" select="-1"/>
106 <xsl:variable name="PAR_SAME" select="-3"/>
107 <xsl:variable name="PAR_YES" select="-5"/>
108 <xsl:variable name="PAR_NO" select="-7"/>
109
110
111 <!-- +++++++++++++++++ INDEX OF TEMPLATES +++++++++++++++++++ -->
112
113 <!-- All templates are subdivided into the following categories
114      (listed in the order of appearance in the stylesheet):
115
116 THE TOPMOST ELEMENT: MATH
117  math
118
119 SEMANTICS HANDLING
120  semantics
121
122 BASIC CONTAINER ELEMENTS
123  cn, ci, csymbol
124
125 BASIC CONTENT ELEMENTS
126  fn, interval, inverse, sep, condition, declare, lambda, compose, ident
127
128 ARITHMETIC, ALGEBRA & LOGIC
129  quotient, exp, factorial, max, min, minus, plus, power, rem, divide,
130  times, root, gcd, and, or, xor, not, forall, exists, abs, conjugate,
131  arg, real, imaginary
132
133 RELATIONS
134  neq, approx, tendsto, implies, in, notin, notsubset, notprsubset,
135  subset, prsubset, eq, gt, lt, geq, leq, equivalent
136
137 CALCULUS
138  ln, log, diff, partialdiff, lowlimit, uplimit, bvar, degree,
139  logbase, divergence, grad, curl, laplacian
140
141 SET THEORY
142  set, list, union, intersect, setdiff, card
143
144 SEQUENCES AND SERIES
145  sum, product, limit
146
147 TRIGONOMETRY
148  sin, cos, tan, sec, csc, cot, sinh, cosh, tanh, sech, csch, coth,
149  arcsin, arccos, arctan
150
151 STATISTICS
152  mean, sdev, variance, median, mode, moment
153
154 LINEAR ALGEBRA
155  vector, matrix, matrixrow, determinant, transpose, selector,
156  vectorproduct, scalarproduct, outerproduct
157 -->
158
159
160 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
161 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~ TEMPLATES ~~~~~~~~~~~~~~~~~~~~~~~~~ -->
162 <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
163
164
165 <!-- ***************** THE TOPMOST ELEMENT: MATH ***************** -->
166
167 <xsl:template match = "m:math">
168   <xsl:choose>
169     <xsl:when test="$SEM_SW=$SEM_TOP or $SEM_SW=$SEM_ALL and *[2] or
170                                                     $SEM_SW=$SEM_XREF">
171       <m:semantics>
172         <m:mrow>
173           <xsl:apply-templates mode = "semantics"/>
174         </m:mrow>
175         <m:annotation-xml encoding="MathML">
176           <xsl:copy-of select="*"/>
177         </m:annotation-xml>
178       </m:semantics>
179     </xsl:when>
180     <xsl:otherwise>
181       <m:mrow>
182         <xsl:apply-templates mode = "semantics"/>
183       </m:mrow>  
184     </xsl:otherwise>
185   </xsl:choose>
186 </xsl:template>
187
188
189 <!-- ***************** SEMANTICS HANDLING ***************** -->
190
191 <!-- This template is called recursively.  At each level   -->
192 <!-- in the source tree it decides whether to strip off,   -->
193 <!-- pass or add semantics at that level (depending on the -->
194 <!-- value of SEM_SW parameter).  Then the actual template -->
195 <!-- is applied to the node.                               -->
196
197 <xsl:template match = "m:*" mode = "semantics">
198   <xsl:param name="IN_PREC" select="$NO_PREC"/>
199   <xsl:param name="PARAM" select="$NO_PARAM"/>
200   <xsl:param name="PAREN" select="$PAR_NO"/>
201   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
202   <xsl:choose>
203     <xsl:when test="$SEM_SW=$SEM_STRIP and self::m:semantics">
204       <xsl:apply-templates select="m:annotation-xml[@encoding='MathML']">
205         <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
206         <xsl:with-param name="PARAM" select="$PARAM"/>
207         <xsl:with-param name="PAREN" select="$PAREN"/>
208         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
209       </xsl:apply-templates>
210     </xsl:when>
211     <xsl:when test="($SEM_SW=$SEM_PASS or $SEM_SW=$SEM_TOP) and self::m:semantics">
212       <m:semantics>
213         <xsl:apply-templates select="*[1]">
214           <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
215           <xsl:with-param name="PARAM" select="$PARAM"/>
216           <xsl:with-param name="PAREN" select="$PAREN"/>
217           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
218         </xsl:apply-templates>
219         <xsl:copy-of select="m:annotation-xml"/>
220       </m:semantics>
221     </xsl:when>
222     <xsl:when test="$SEM_SW=$SEM_ALL">
223       <m:semantics>
224         <xsl:choose>
225           <xsl:when test="self::m:semantics">
226             <xsl:apply-templates select="*[1]">
227               <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
228               <xsl:with-param name="PARAM" select="$PARAM"/>
229               <xsl:with-param name="PAREN" select="$PAREN"/>
230               <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
231             </xsl:apply-templates>
232             <xsl:copy-of select="m:annotation-xml"/>
233           </xsl:when>
234           <xsl:otherwise>
235             <xsl:apply-templates select=".">
236               <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
237               <xsl:with-param name="PARAM" select="$PARAM"/>
238               <xsl:with-param name="PAREN" select="$PAREN"/>
239               <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
240             </xsl:apply-templates>
241             <m:annotation-xml encoding="MathML">
242               <xsl:copy-of select="."/>
243             </m:annotation-xml>
244           </xsl:otherwise>
245         </xsl:choose>
246       </m:semantics>
247     </xsl:when>
248     <xsl:when test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
249       <xsl:choose>
250 <!-- HELM: syntax error: sematics -->
251         <xsl:when test="self::m:semantics">
252           <xsl:copy>
253             <xsl:copy-of select="@*"/>
254             <xsl:attribute name="m:xref">
255               <xsl:value-of select="@id"/>
256             </xsl:attribute>
257             <xsl:copy-of select="*[1]"/>
258             <xsl:copy-of select="m:annotation-xml"/>
259           </xsl:copy>
260         </xsl:when>
261         <xsl:otherwise>
262           <xsl:apply-templates select=".">
263             <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
264             <xsl:with-param name="PARAM" select="$PARAM"/>
265             <xsl:with-param name="PAREN" select="$PAREN"/>
266             <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
267           </xsl:apply-templates>
268         </xsl:otherwise>
269       </xsl:choose>
270     </xsl:when>
271     <xsl:otherwise>
272       <xsl:choose>
273         <xsl:when test="self::m:semantics">
274           <xsl:copy-of select="."/>
275         </xsl:when>
276         <xsl:otherwise>
277           <xsl:apply-templates select=".">
278             <xsl:with-param name="IN_PREC" select="$IN_PREC"/>
279             <xsl:with-param name="PARAM" select="$PARAM"/>
280             <xsl:with-param name="PAREN" select="$PAREN"/>
281             <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
282           </xsl:apply-templates>
283         </xsl:otherwise>
284       </xsl:choose>
285     </xsl:otherwise>
286   </xsl:choose>
287 </xsl:template>
288
289 <xsl:template match = "m:semantics">
290   <xsl:apply-templates select="." mode = "semantics"/>
291 </xsl:template>
292
293
294 <!-- ***************** BASIC CONTAINER ELEMENTS ***************** -->
295
296 <!-- HELM: cn could not contain MAthML presentation -->
297 <xsl:template match = "m:cn">
298   <xsl:param name="IN_PREC" select="$NO_PREC"/>
299   <xsl:param name="PAREN" select="$PAR_NO"/>
300   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
301 <!-- HELM: added -->
302 <xsl:choose>
303   <xsl:when test="child::text()">
304 <!-- HELM -->
305   <xsl:choose>
306     <xsl:when test=". &lt; 0 and $IN_PREC &gt; $NO_PREC and $PAREN=$PAR_NO
307                                                    and $PAR_NO_IGNORE=$NO">
308       <m:mfenced separators="">
309         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
310           <xsl:attribute name="m:xref">
311             <xsl:value-of select="@id"/>
312           </xsl:attribute>
313         </xsl:if>
314         <xsl:apply-templates select="." mode="cn"/>
315       </m:mfenced>
316     </xsl:when>
317     <xsl:otherwise>
318       <xsl:choose>
319         <xsl:when test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
320           <xsl:apply-templates select="." mode="cnid"/>
321         </xsl:when>
322         <xsl:otherwise>
323           <xsl:apply-templates select="." mode="cn"/>
324         </xsl:otherwise>
325       </xsl:choose>
326     </xsl:otherwise>
327   </xsl:choose>
328 <!-- HELM: added -->
329   </xsl:when>
330   <xsl:otherwise>
331    <m:mrow>
332     <xsl:attribute name="m:xref">
333      <xsl:value-of select="@id"/>
334     </xsl:attribute>
335     <xsl:copy-of select="*"/>
336    </m:mrow> 
337   </xsl:otherwise>
338  </xsl:choose>
339 <!-- HELM -->
340 </xsl:template>
341
342 <xsl:template match = "m:cn" mode="cn">
343   <xsl:choose>
344     <xsl:when test="@base and (not(@type) or @type='integer' or @type='real')">
345       <m:msub>
346         <m:mn> <xsl:apply-templates mode = "semantics"/> </m:mn>
347         <m:mn> <xsl:value-of select="@base"/> </m:mn>
348       </m:msub>
349     </xsl:when>
350     <xsl:when test="@type='complex' and not(@base) and child::m:sep[1]">
351       <m:mfenced separators="">
352         <m:mn> <xsl:apply-templates select="text()[1]" mode = "semantics"/> </m:mn>
353         <xsl:if test="text()[2] &lt; 0">
354           <m:mo>-</m:mo>
355           <m:mn> <xsl:value-of select="-text()[2]"/> </m:mn>
356         </xsl:if>
357         <xsl:if test="not(text()[2] &lt; 0)">
358           <m:mo>+</m:mo>
359           <m:mn> <xsl:value-of select="text()[2]"/> </m:mn>
360         </xsl:if>
361         <m:mo>&#x02062;</m:mo>
362         <m:mo>i</m:mo>
363       </m:mfenced>
364     </xsl:when>
365     <xsl:when test="@type='complex' and @base and child::m:sep[1]">
366       <m:msub>
367         <m:mfenced separators="">
368           <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
369           <xsl:if test="text()[2] &lt; 0">
370             <m:mo>-</m:mo>
371             <m:mn> <xsl:value-of select="-text()[2]"/> </m:mn>
372           </xsl:if>
373           <xsl:if test="not(text()[2] &lt; 0)">
374             <m:mo>+</m:mo>
375             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
376           </xsl:if>
377           <m:mo>&#x02062;</m:mo>
378           <m:mo>i</m:mo>
379         </m:mfenced>
380         <m:mn> <xsl:value-of select="@base"/> </m:mn>
381       </m:msub>
382     </xsl:when>
383     <xsl:when test="@type='rational' and not(@base) and child::m:sep[1]">
384       <m:mfrac>
385         <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
386         <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
387       </m:mfrac>
388     </xsl:when>
389     <xsl:when test="@type='rational' and @base and child::m:sep[1]">
390       <m:msub>
391         <m:mfenced>
392           <m:mfrac>
393             <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
394             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
395           </m:mfrac>
396         </m:mfenced>
397         <m:mn> <xsl:value-of select="@base"/> </m:mn>
398       </m:msub>
399     </xsl:when>
400     <xsl:when test="@type='polar' and not(@base) and child::m:sep[1]">
401       <m:mrow>
402         <m:mo>Polar</m:mo>
403         <m:mo>&#x02062;</m:mo>
404         <m:mfenced separators=",">
405           <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
406           <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
407         </m:mfenced>
408       </m:mrow>
409     </xsl:when>
410     <xsl:when test="@type='polar' and @base and child::m:sep[1]">
411       <m:msub>
412         <m:mrow>
413           <m:mo>Polar</m:mo>
414           <m:mo>&#x02062;</m:mo>
415           <m:mfenced separators=",">
416             <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
417             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
418           </m:mfenced>
419         </m:mrow>
420         <m:mn> <xsl:value-of select="@base"/> </m:mn>
421       </m:msub>
422    </xsl:when>
423     <xsl:otherwise>
424       <m:mn> <xsl:apply-templates mode = "semantics"/> </m:mn>
425     </xsl:otherwise>
426   </xsl:choose>
427 </xsl:template>
428
429 <xsl:template match = "m:cn" mode="cnid">
430   <xsl:choose>
431     <xsl:when test="@base and (not(@type) or @type='integer' or @type='real')">
432       <m:msub m:xref="{@id}">
433         <m:mn> <xsl:apply-templates mode = "semantics"/> </m:mn>
434         <m:mn> <xsl:value-of select="@base"/> </m:mn>
435       </m:msub>
436     </xsl:when>
437     <xsl:when test="@type='complex' and not(@base) and child::m:sep[1]">
438       <m:mfenced separators="" m:xref="{@id}">
439         <m:mn> <xsl:apply-templates select="text()[1]" mode = "semantics"/> </m:mn>
440         <xsl:if test="text()[2] &lt; 0">
441           <m:mo>-</m:mo>
442           <m:mn> <xsl:value-of select="-text()[2]"/> </m:mn>
443         </xsl:if>
444         <xsl:if test="not(text()[2] &lt; 0)">
445           <m:mo>+</m:mo>
446           <m:mn> <xsl:value-of select="text()[2]"/> </m:mn>
447         </xsl:if>
448         <m:mo>&#x02062;</m:mo>
449         <m:mo>i</m:mo>
450       </m:mfenced>
451     </xsl:when>
452     <xsl:when test="@type='complex' and @base and child::m:sep[1]">
453       <m:msub m:xref="{@id}">
454         <m:mfenced separators="">
455           <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
456           <xsl:if test="text()[2] &lt; 0">
457             <m:mo>-</m:mo>
458             <m:mn> <xsl:value-of select="-text()[2]"/> </m:mn>
459           </xsl:if>
460           <xsl:if test="not(text()[2] &lt; 0)">
461             <m:mo>+</m:mo>
462             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
463           </xsl:if>
464           <m:mo>&#x02062;</m:mo>
465           <m:mo>i</m:mo>
466         </m:mfenced>
467         <m:mn> <xsl:value-of select="@base"/> </m:mn>
468       </m:msub>
469     </xsl:when>
470     <xsl:when test="@type='rational' and not(@base) and child::m:sep[1]">
471       <m:mfrac m:xref="{@id}">
472         <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
473         <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
474       </m:mfrac>
475     </xsl:when>
476     <xsl:when test="@type='rational' and @base and child::m:sep[1]">
477       <m:msub m:xref="{@id}">
478         <m:mfenced>
479           <m:mfrac>
480             <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
481             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
482           </m:mfrac>
483         </m:mfenced>
484         <m:mn> <xsl:value-of select="@base"/> </m:mn>
485       </m:msub>
486     </xsl:when>
487     <xsl:when test="@type='polar' and not(@base) and child::m:sep[1]">
488       <m:mrow m:xref="{@id}">
489         <m:mo>Polar</m:mo>
490         <m:mo>&#x02062;</m:mo>
491         <m:mfenced separators=",">
492           <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
493           <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
494         </m:mfenced>
495       </m:mrow>
496     </xsl:when>
497     <xsl:when test="@type='polar' and @base and child::m:sep[1]">
498       <m:msub m:xref="{@id}">
499         <m:mrow>
500           <m:mo>Polar</m:mo>
501           <m:mo>&#x02062;</m:mo>
502           <m:mfenced separators=",">
503             <m:mn> <xsl:apply-templates select="text()[1]"/> </m:mn>
504             <m:mn> <xsl:apply-templates select="text()[2]"/> </m:mn>
505           </m:mfenced>
506         </m:mrow>
507         <m:mn> <xsl:value-of select="@base"/> </m:mn>
508       </m:msub>
509    </xsl:when>
510     <xsl:otherwise>
511       <m:mn m:xref="{@id}"> <xsl:apply-templates mode = "semantics"/> </m:mn>
512     </xsl:otherwise>
513   </xsl:choose>
514 </xsl:template>
515
516 <!-- HELM: ci could not contain MAthML presentation -->
517 <xsl:template match = "m:ci">
518 <!-- HELM: added -->
519 <xsl:choose>
520   <xsl:when test="child::text()">
521 <!-- HELM -->
522   <xsl:choose>
523     <xsl:when test="@type='vector' or @type=matrix or @type=set">
524       <m:mi fontweight="bold">
525         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
526           <xsl:attribute name="m:xref">
527             <xsl:value-of select="@id"/>
528           </xsl:attribute>
529         </xsl:if>
530         <xsl:apply-templates mode = "semantics"/>
531       </m:mi>
532     </xsl:when>
533     <xsl:when test="child::text() and not(child::*[1])">
534       <m:mi>
535         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
536           <xsl:attribute name="m:xref">
537             <xsl:value-of select="@id"/>
538           </xsl:attribute>
539         </xsl:if>
540 <!-- HELM: added mode=semantics -->
541         <xsl:apply-templates mode = "semantics"/>
542       </m:mi>
543     </xsl:when>
544     <xsl:when test="child::text() and *[1] and not(*[1]=m:sep)">
545       <m:mrow>
546         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
547           <xsl:attribute name="m:xref">
548             <xsl:value-of select="@id"/>
549           </xsl:attribute>
550         </xsl:if>
551 <!-- HELM: added mode=semantics -->
552         <xsl:apply-templates mode = "semantics"/>
553       </m:mrow>
554     </xsl:when>
555     <xsl:otherwise>
556       <xsl:if test="*[2]">
557         <m:mrow>
558           <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
559             <xsl:attribute name="m:xref">
560               <xsl:value-of select="@id"/>
561             </xsl:attribute>
562           </xsl:if>
563           <xsl:apply-templates select="*"/>
564         </m:mrow>
565       </xsl:if>
566       <xsl:if test="not(*[2])">
567         <xsl:apply-templates select="*[1]"/>
568       </xsl:if>
569     </xsl:otherwise>
570   </xsl:choose>
571 <!-- HELM: added -->
572 </xsl:when>
573   <xsl:otherwise>
574    <m:mrow>
575     <xsl:copy-of select="*"/>
576     <xsl:attribute name="m:xref">
577      <xsl:value-of select="@id"/>
578     </xsl:attribute>
579    </m:mrow> 
580   </xsl:otherwise>
581  </xsl:choose>
582 <!-- HELM -->
583 </xsl:template>
584
585 <xsl:template match = "m:ci/m:*[not(self::m:sep)]">
586   <xsl:copy-of select = "."/>
587 </xsl:template>
588
589 <!-- HELM: previous Version x.xx from Feb. 18, 2000 -->
590 <xsl:template match = "m:csymbol">
591 <!-- HELM: added -->
592    <m:mrow>
593     <xsl:attribute name="m:xref">
594      <xsl:value-of select="@id"/>
595     </xsl:attribute>
596 <!-- HELM -->
597    <xsl:choose>
598     <xsl:when test="*[1]">
599      <xsl:copy-of select = "*"/>
600     </xsl:when>
601    <xsl:otherwise>
602     <m:mo>
603      <xsl:apply-templates mode = "semantics"/>
604     </m:mo>
605    </xsl:otherwise>
606   </xsl:choose>
607  </m:mrow>
608 </xsl:template>
609
610
611 <!-- HELM: csymbol cannot contain ci or cn elements, but only text or 
612 presentation elements. PCDATA should render as if it were wrapped in 
613 an mo. Mixed content: mrow which contains mo + presentation elements -->
614 <!--<xsl:template match = "m:csymbol/m:*">
615   <xsl:choose>
616     <xsl:when test="self::m:cn or self::m:ci">
617       <xsl:apply-templates mode = "semantics"/>
618     </xsl:when>
619     <xsl:otherwise>
620       <xsl:copy-of select = "."/>
621     </xsl:otherwise>
622   </xsl:choose>
623 </xsl:template>
624
625 <xsl:template match = "m:csymbol/text()">
626   <xsl:choose>
627     <xsl:when test=". &lt; 0 or . = 0 or . &gt; 0">
628       <mn> <xsl:copy-of select = "."/> </mn>
629     </xsl:when>
630     <xsl:otherwise>
631       <mi> <xsl:copy-of select = "."/> </mi>
632     </xsl:otherwise>
633   </xsl:choose>
634 </xsl:template>-->
635
636
637 <!-- ***************** BASIC CONTENT ELEMENTS ***************** -->
638
639 <xsl:template match = "m:apply[m:*[1][self::m:fn]]">
640   <m:mrow>
641     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
642       <xsl:attribute name="m:xref">
643         <xsl:value-of select="@id"/>
644       </xsl:attribute>
645     </xsl:if>
646     <xsl:apply-templates select = "m:fn[1]" mode = "semantics"/>
647     <m:mo> 
648 <!-- HELM: added -->        
649         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
650           <xsl:attribute name="m:xref">
651             <xsl:value-of select="m:fn/@id"/>
652           </xsl:attribute>
653         </xsl:if>&#x02061;</m:mo>
654     <m:mfenced separators=",">
655       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
656     </m:mfenced>
657   </m:mrow>
658 </xsl:template>
659
660 <xsl:template match = "m:fn">
661   <xsl:apply-templates select = "*[1]" mode = "semantics">
662     <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
663   </xsl:apply-templates>
664 </xsl:template>
665
666 <xsl:template match = "m:interval">
667   <m:mfenced separators=",">
668     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
669       <xsl:attribute name="m:xref">
670         <xsl:value-of select="@id"/>
671       </xsl:attribute>
672     </xsl:if>
673     <xsl:if test="@closure='closed' or @closure='closed-open'">
674       <xsl:attribute name="open">[</xsl:attribute>
675     </xsl:if>
676     <xsl:if test="@closure='closed' or @closure='open-closed'">
677       <xsl:attribute name="close">]</xsl:attribute>
678     </xsl:if>
679     <xsl:apply-templates select="*" mode = "semantics"/>
680   </m:mfenced>
681 </xsl:template>
682
683 <xsl:template match = "m:apply[m:*[1][self::m:apply[m:inverse[1]]]]">
684   <m:mrow>
685     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
686       <xsl:attribute name="m:xref">
687         <xsl:value-of select="@id"/>
688       </xsl:attribute>
689     </xsl:if>
690     <xsl:apply-templates select = "*[1]" mode = "semantics"/>
691     <m:mo>&#x02061;</m:mo>
692     <m:mfenced separators=",">
693       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
694     </m:mfenced>
695  </m:mrow>
696 </xsl:template>
697
698 <xsl:template match = "m:apply[*[1][self::m:inverse]]">
699   <xsl:choose>
700     <xsl:when test="*[2]=m:exp or *[2]=m:ln or *[2]=m:sin or *[2]=m:cos or
701                     *[2]=m:tan or *[2]=m:sec or *[2]=m:csc or *[2]=m:cot or
702                     *[2]=m:sinh or *[2]=m:cosh or *[2]=m:tanh or *[2]=m:sech or
703                     *[2]=m:csch or *[2]=m:coth or *[2]=m:arcsin or
704                     *[2]=m:arccos or *[2]=m:arctan">
705       <m:mo>
706         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
707           <xsl:attribute name="m:xref">
708             <xsl:value-of select="@id"/>
709           </xsl:attribute>
710         </xsl:if>
711         <xsl:apply-templates select="*[2]" mode="inverse"/>
712       </m:mo>
713     </xsl:when>
714     <xsl:otherwise>
715       <m:msup>
716         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
717           <xsl:attribute name="m:xref">
718             <xsl:value-of select="@id"/>
719           </xsl:attribute>
720         </xsl:if>
721         <xsl:apply-templates select = "*[2]"/>
722         <m:mfenced>
723           <m:mn>-1</m:mn>
724         </m:mfenced>
725       </m:msup>
726     </xsl:otherwise>
727   </xsl:choose>
728 </xsl:template>
729
730 <xsl:template match = "*" mode="inverse">
731   <xsl:choose>
732     <xsl:when test="self::m:exp">
733       <xsl:value-of select="'ln'"/>
734     </xsl:when>
735     <xsl:when test="self::m:ln">
736       <xsl:value-of select="'exp'"/>
737     </xsl:when>
738     <xsl:when test="self::m:sin">
739       <xsl:value-of select="'arcsin'"/>
740     </xsl:when>
741     <xsl:when test="self::m:cos">
742       <xsl:value-of select="'arccos'"/>
743     </xsl:when>
744     <xsl:when test="self::m:tan">
745       <xsl:value-of select="'arctan'"/>
746     </xsl:when>
747     <xsl:when test="self::m:sec">
748       <xsl:value-of select="'arcsec'"/>
749     </xsl:when>
750     <xsl:when test="self::m:csc">
751       <xsl:value-of select="'arccsc'"/>
752     </xsl:when>
753     <xsl:when test="self::m:cot">
754       <xsl:value-of select="'arccot'"/>
755     </xsl:when>
756     <xsl:when test="self::m:sinh">
757       <xsl:value-of select="'arcsinh'"/>
758     </xsl:when>
759     <xsl:when test="self::m:cosh">
760       <xsl:value-of select="'arccosh'"/>
761     </xsl:when>
762     <xsl:when test="self::m:tanh">
763       <xsl:value-of select="'arctanh'"/>
764     </xsl:when>
765     <xsl:when test="self::m:sech">
766       <xsl:value-of select="'arcsech'"/>
767     </xsl:when>
768     <xsl:when test="self::m:csch">
769       <xsl:value-of select="'arccsch'"/>
770     </xsl:when>
771     <xsl:when test="self::m:coth">
772       <xsl:value-of select="'arccoth'"/>
773     </xsl:when>
774     <xsl:when test="self::m:arcsin">
775       <xsl:value-of select="'sin'"/>
776     </xsl:when>
777     <xsl:when test="self::m:arccos">
778       <xsl:value-of select="'cos'"/>
779     </xsl:when>
780     <xsl:when test="self::m:arctan">
781       <xsl:value-of select="'tan'"/>
782     </xsl:when>
783   </xsl:choose>
784 </xsl:template>
785
786 <xsl:template match = "m:sep"/>
787
788 <xsl:template match = "m:condition">
789   <xsl:choose>
790     <xsl:when test="parent::m:apply[m:forall[1]]"/>
791     <xsl:otherwise>
792       <xsl:choose>
793         <xsl:when test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
794           <m:mrow m:xref="{@id}">
795             <xsl:apply-templates select="*" mode = "semantics"/>
796           </m:mrow>
797         </xsl:when>
798         <xsl:otherwise>
799           <xsl:if test="not(*[2])">
800             <xsl:apply-templates select="*" mode = "semantics"/>
801           </xsl:if>
802           <xsl:if test="*[2]">
803             <m:mrow>
804               <xsl:apply-templates select="*" mode = "semantics"/>
805             </m:mrow>
806           </xsl:if>
807         </xsl:otherwise>
808       </xsl:choose>
809     </xsl:otherwise>
810   </xsl:choose>
811 </xsl:template>
812
813 <xsl:template match = "m:declare"/>
814
815 <xsl:template match = "m:lambda">
816   <m:mrow>
817     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
818       <xsl:attribute name="m:xref">
819         <xsl:value-of select="@id"/>
820       </xsl:attribute>
821     </xsl:if>
822     <m:mo>&#x0039B;</m:mo>
823     <m:mo>&#x02061;</m:mo>
824     <m:mfenced separators=",">
825       <xsl:for-each select = "*">
826         <xsl:choose>
827           <xsl:when test="self::m:ci or self::m:cn">
828             <xsl:apply-templates select = "." mode="semantics"/>
829           </xsl:when>
830           <xsl:otherwise>
831             <m:mrow>
832               <xsl:apply-templates select = "." mode="semantics"/>
833             </m:mrow>
834           </xsl:otherwise>
835         </xsl:choose>
836       </xsl:for-each>
837     </m:mfenced>
838   </m:mrow>
839 </xsl:template>
840
841 <xsl:template match = "m:apply[*[1][self::m:apply[m:compose[1]]]]">
842   <m:mrow>
843     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
844       <xsl:attribute name="m:xref">
845         <xsl:value-of select="@id"/>
846       </xsl:attribute>
847     </xsl:if>
848     <xsl:apply-templates select = "*[1]" mode = "semantics"/>
849     <m:mo>&#x02061;</m:mo>
850     <m:mfenced separators=",">
851       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
852     </m:mfenced>
853  </m:mrow>
854 </xsl:template>
855
856 <xsl:template match = "m:apply[*[1][self::m:compose]]">
857   <m:mfenced separators="">
858     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
859       <xsl:attribute name="m:xref">
860         <xsl:value-of select="@id"/>
861       </xsl:attribute>
862     </xsl:if>
863     <xsl:apply-templates select = "m:*[2][self::m:ci[@type='fn'] |
864                                        self::m:fn]" mode="semantics"/>
865     <xsl:for-each select = "m:*[position()>2][self::m:ci[@type='fn'] |
866                                                             self::m:fn]">
867       <m:mo>
868  <!-- HELM: added -->        
869         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
870           <xsl:attribute name="m:xref">
871             <xsl:value-of select="../m:compose/@id"/>
872           </xsl:attribute>
873         </xsl:if>&#x02218;</m:mo>
874       <xsl:apply-templates select = "." mode="semantics"/>
875     </xsl:for-each>
876   </m:mfenced>
877 </xsl:template>
878
879 <xsl:template match = "m:ident">
880   <xsl:choose>
881     <xsl:when test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
882       <m:mo m:xref="{@id}">id</m:mo>
883     </xsl:when>
884     <xsl:otherwise>
885       <m:mo>id</m:mo>
886     </xsl:otherwise>
887   </xsl:choose>
888 </xsl:template>
889
890
891 <!-- ***************** ARITHMETIC, ALGEBRA & LOGIC ***************** -->
892
893 <xsl:template match = "m:apply[m:quotient[1]]">
894   <m:mrow>
895     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
896       <xsl:attribute name="m:xref">
897         <xsl:value-of select="@id"/>
898       </xsl:attribute>
899     </xsl:if>
900     <m:mo form="prefix" fence="true" stretchy="true" lspace="0em" rspace="0em">&#x0230A;</m:mo>
901     <m:mfrac>
902 <!-- HELM: added -->        
903         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
904           <xsl:attribute name="m:xref">
905             <xsl:value-of select="m:quotient/@id"/>
906           </xsl:attribute>
907         </xsl:if>
908       <m:mrow>
909         <xsl:apply-templates select="*[2]" mode = "semantics">
910           <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
911         </xsl:apply-templates>
912       </m:mrow>
913       <m:mrow>
914         <xsl:apply-templates select="*[3]" mode = "semantics">
915           <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
916           <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
917         </xsl:apply-templates>
918       </m:mrow>
919     </m:mfrac>
920     <m:mo form="postfix" fence="true" stretchy="true" lspace="0em" rspace="0em">&#x0230A;</m:mo>
921   </m:mrow>
922 </xsl:template>
923
924 <xsl:template match = "m:apply[*[1][self::m:exp]]">
925   <m:msup>
926     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
927       <xsl:attribute name="m:xref">
928         <xsl:value-of select="@id"/>
929       </xsl:attribute>
930     </xsl:if>
931     <m:mo>
932     <!-- HELM: added -->        
933         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
934           <xsl:attribute name="m:xref">
935             <xsl:value-of select="m:exp/@id"/>
936           </xsl:attribute>
937         </xsl:if>e</m:mo>
938     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
939   </m:msup>
940 </xsl:template>
941
942 <xsl:template match = "m:apply[m:factorial[1]]">
943   <m:mrow>
944     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
945       <xsl:attribute name="m:xref">
946         <xsl:value-of select="@id"/>
947       </xsl:attribute>
948     </xsl:if>
949     <xsl:apply-templates select = "*[2]" mode = "semantics">
950       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
951       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
952     </xsl:apply-templates>
953     <m:mo>
954 <!-- HELM: added -->        
955         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
956           <xsl:attribute name="m:xref">
957             <xsl:value-of select="m:factorial/@id"/>
958           </xsl:attribute>
959         </xsl:if>!</m:mo>
960   </m:mrow>
961 </xsl:template>
962
963 <xsl:template match = "m:apply[m:max[1] | m:min[1]]">
964   <m:mrow>
965     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
966       <xsl:attribute name="m:xref">
967         <xsl:value-of select="@id"/>
968       </xsl:attribute>
969     </xsl:if>
970     <xsl:if test="*[2]=m:bvar">
971       <m:munder>
972         <xsl:if test="*[1]=m:max">
973           <m:mo>
974 <!-- HELM: added -->        
975         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
976           <xsl:attribute name="m:xref">
977             <xsl:value-of select="m:max/@id"/>
978           </xsl:attribute>
979         </xsl:if>max</m:mo>
980         </xsl:if>
981         <xsl:if test="*[1]=m:min">
982           <m:mo>
983 <!-- HELM: added -->        
984         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
985           <xsl:attribute name="m:xref">
986             <xsl:value-of select="m:min/@id"/>
987           </xsl:attribute>
988         </xsl:if>min</m:mo>
989         </xsl:if>
990         <xsl:apply-templates select="*[2]" mode = "semantics"/>
991       </m:munder>
992       <xsl:if test="*[3]=m:condition">
993         <m:mfenced open="{{" close="}}" separators="">
994           <m:mfenced open="" close="" separators=",">
995             <xsl:for-each select = "*[position()>3]">
996               <xsl:apply-templates select = "." mode="semantics"/>
997             </xsl:for-each>
998           </m:mfenced>
999           <m:mo>|</m:mo>
1000           <xsl:apply-templates select="*[3]" mode = "semantics"/>
1001         </m:mfenced>
1002       </xsl:if>
1003       <xsl:if test="not(*[3]=m:condition)">
1004         <m:mfenced open="{{" close="}}" separators=",">
1005           <xsl:for-each select = "*[position()>2]">
1006             <xsl:apply-templates select = "." mode="semantics"/>
1007           </xsl:for-each>
1008         </m:mfenced>
1009       </xsl:if>
1010     </xsl:if>
1011     <xsl:if test="*[2]=m:condition">
1012       <xsl:if test="*[1]=m:max">
1013         <m:mo>max</m:mo>
1014       </xsl:if>
1015       <xsl:if test="*[1]=m:min">
1016         <m:mo>min</m:mo>
1017       </xsl:if>
1018       <m:mfenced open="{{" close="}}" separators="">
1019         <xsl:if test="*[3]">
1020           <m:mfenced open="" close="" separators=",">
1021             <xsl:for-each select = "*[position()>2]">
1022               <xsl:apply-templates select = "." mode="semantics"/>
1023             </xsl:for-each>
1024           </m:mfenced>
1025           <m:mo>|</m:mo>
1026         </xsl:if>
1027         <xsl:apply-templates select="*[2]" mode = "semantics"/>
1028       </m:mfenced>
1029     </xsl:if>
1030     <xsl:if test="not(*[2]=m:condition) and not(*[2]=m:bvar)">
1031       <xsl:if test="*[1]=m:max">
1032         <m:mo>max</m:mo>
1033       </xsl:if>
1034       <xsl:if test="*[1]=m:min">
1035         <m:mo>min</m:mo>
1036       </xsl:if>
1037       <m:mfenced open="{{" close="}}" separators=",">
1038         <xsl:for-each select = "*[position()>1]">
1039           <xsl:apply-templates select = "." mode="semantics"/>
1040         </xsl:for-each>
1041       </m:mfenced>
1042     </xsl:if>
1043   </m:mrow>
1044 </xsl:template>
1045
1046 <xsl:template match = "m:apply[m:minus[1]]">
1047   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1048   <xsl:param name="PARAM" select="$NO_PARAM"/>
1049   <xsl:param name="PAREN" select="$PAR_NO"/>
1050   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1051   <xsl:choose>
1052     <xsl:when test="$IN_PREC &gt; $MINUS_PREC or $IN_PREC=$MINUS_PREC and
1053                                                         $PARAM=$PAR_SAME">
1054       <m:mfenced separators="">
1055         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1056           <xsl:attribute name="m:xref">
1057             <xsl:value-of select="@id"/>
1058           </xsl:attribute>
1059         </xsl:if>
1060         <xsl:apply-templates select="." mode="minus">
1061           <xsl:with-param name="PARAM" select="$PARAM"/>
1062           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1063           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1064         </xsl:apply-templates>
1065       </m:mfenced>
1066     </xsl:when>
1067     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1068                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1069                     and not($SEM_SW=$SEM_XREF_EXT)">
1070       <xsl:apply-templates select="." mode="minus">
1071         <xsl:with-param name="PARAM" select="$PARAM"/>
1072         <xsl:with-param name="PAREN" select="$PAREN"/>
1073         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1074       </xsl:apply-templates>
1075     </xsl:when>
1076     <xsl:otherwise>
1077       <m:mrow>
1078         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1079           <xsl:attribute name="m:xref">
1080             <xsl:value-of select="@id"/>
1081           </xsl:attribute>
1082         </xsl:if>
1083         <xsl:apply-templates select="." mode="minus">
1084           <xsl:with-param name="PARAM" select="$PARAM"/>
1085           <xsl:with-param name="PAREN" select="$PAREN"/>
1086           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1087         </xsl:apply-templates>
1088       </m:mrow>
1089     </xsl:otherwise>
1090   </xsl:choose>
1091 </xsl:template>
1092
1093 <xsl:template match = "m:apply[m:minus[1]]" mode="minus">
1094   <xsl:param name="PARAM" select="$NO_PARAM"/>
1095   <xsl:param name="PAREN" select="$PAR_NO"/>
1096   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1097   <xsl:if test="not(*[3])">
1098     <m:mo>
1099 <!-- HELM: added -->        
1100         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1101           <xsl:attribute name="m:xref">
1102             <xsl:value-of select="m:minus/@id"/>
1103           </xsl:attribute>
1104         </xsl:if>-</m:mo>
1105     <xsl:apply-templates select="*[2]" mode = "semantics">
1106       <xsl:with-param name="IN_PREC" select="$NEG_PREC"/>
1107       <xsl:with-param name="PAREN" select="$PAREN"/>
1108       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1109     </xsl:apply-templates>
1110   </xsl:if>
1111   <xsl:if test="*[3]">
1112     <xsl:apply-templates select="*[2]" mode = "semantics">
1113       <xsl:with-param name="IN_PREC" select="$MINUS_PREC"/>
1114       <xsl:with-param name="PARAM" select="$PARAM"/>
1115       <xsl:with-param name="PAREN" select="$PAREN"/>
1116       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1117     </xsl:apply-templates>
1118     <m:mo>
1119 <!-- HELM: added -->        
1120         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1121           <xsl:attribute name="m:xref">
1122             <xsl:value-of select="m:minus/@id"/>
1123           </xsl:attribute>
1124         </xsl:if>-</m:mo>
1125     <xsl:apply-templates select="*[3]" mode = "semantics">
1126       <xsl:with-param name="IN_PREC" select="$MINUS_PREC"/>
1127       <xsl:with-param name="PARAM" select="$PAR_SAME"/>
1128       <xsl:with-param name="PAREN" select="$PAREN"/>
1129       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1130     </xsl:apply-templates>
1131   </xsl:if>
1132 </xsl:template>
1133
1134 <xsl:template match = "m:apply[m:plus[1]]">
1135   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1136   <xsl:param name="PARAM" select="$NO_PARAM"/>
1137   <xsl:param name="PAREN" select="$PAR_NO"/>
1138   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1139   <xsl:choose>
1140     <xsl:when test="$IN_PREC &gt; $PLUS_PREC or $IN_PREC=$PLUS_PREC and
1141                                                       $PARAM=$PAR_SAME">
1142       <m:mfenced separators="">
1143         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1144           <xsl:attribute name="m:xref">
1145             <xsl:value-of select="@id"/>
1146           </xsl:attribute>
1147         </xsl:if>
1148         <xsl:apply-templates select="." mode="plus">
1149           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1150           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1151           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1152         </xsl:apply-templates>
1153       </m:mfenced>
1154     </xsl:when>
1155     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1156                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1157                     and not($SEM_SW=$SEM_XREF_EXT)">
1158       <xsl:apply-templates select="." mode="plus">
1159         <xsl:with-param name="PARAM" select="$PARAM"/>
1160         <xsl:with-param name="PAREN" select="$PAREN"/>
1161         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1162       </xsl:apply-templates>
1163     </xsl:when>
1164     <xsl:otherwise>
1165       <m:mrow>
1166         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1167           <xsl:attribute name="m:xref">
1168             <xsl:value-of select="@id"/>
1169           </xsl:attribute>
1170         </xsl:if>
1171         <xsl:apply-templates select="." mode="plus">
1172           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1173           <xsl:with-param name="PAREN" select="$PAREN"/>
1174           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1175         </xsl:apply-templates>
1176       </m:mrow>
1177     </xsl:otherwise>
1178   </xsl:choose>
1179 </xsl:template>
1180
1181 <xsl:template match = "m:apply[m:plus[1]]" mode="plus">
1182   <xsl:param name="PARAM" select="$NO_PARAM"/>
1183   <xsl:param name="PAREN" select="$PAR_NO"/>
1184   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1185   <xsl:if test="*[2]">
1186     <xsl:apply-templates select="*[2]" mode = "semantics">
1187       <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
1188       <xsl:with-param name="PARAM" select="$PARAM"/>
1189       <xsl:with-param name="PAREN" select="$PAREN"/>
1190       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1191     </xsl:apply-templates>
1192     <xsl:for-each select = "*[position()>2]">
1193       <xsl:choose>
1194         <xsl:when test=". &lt; 0">
1195           <m:mo>-</m:mo>
1196           <m:mn> <xsl:value-of select="-."/> </m:mn>
1197         </xsl:when>
1198         <xsl:when test="self::m:apply[m:minus[1]] and not(*[3])">
1199           <xsl:apply-templates select="." mode = "semantics">
1200             <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
1201             <xsl:with-param name="PAREN" select="$PAREN"/>
1202             <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1203           </xsl:apply-templates>
1204         </xsl:when>
1205         <xsl:otherwise>
1206           <m:mo>
1207 <!-- HELM: added -->        
1208         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1209           <xsl:attribute name="m:xref">
1210             <xsl:value-of select="../m:plus/@id"/>
1211           </xsl:attribute>
1212         </xsl:if>+</m:mo>
1213           <xsl:apply-templates select="." mode = "semantics">
1214             <xsl:with-param name="IN_PREC" select="$PLUS_PREC"/>
1215             <xsl:with-param name="PAREN" select="$PAREN"/>
1216             <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1217           </xsl:apply-templates>
1218         </xsl:otherwise>
1219       </xsl:choose>
1220     </xsl:for-each>
1221   </xsl:if>
1222 </xsl:template>
1223
1224 <xsl:template match = "m:apply[m:power[1]]">
1225   <xsl:choose>
1226     <xsl:when test="*[2]=m:apply[m:ln[1] | m:log[1] | m:abs[1] |
1227                          m:gcd[1] | m:sin[1] | m:cos[1] | m:tan[1] |
1228                          m:sec[1] | m:csc[1] | m:cot[1] | m:sinh[1] |
1229                          m:cosh[1] | m:tanh[1] | m:sech[1] | m:csch[1] |
1230                          m:coth[1] | m:arcsin[1] | m:arccos[1] |
1231                          m:arctan[1]]">
1232       <xsl:apply-templates select="*[2]" mode = "semantics"/>
1233     </xsl:when>
1234     <xsl:otherwise>
1235       <m:msup>
1236         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1237           <xsl:attribute name="m:xref">
1238             <xsl:value-of select="@id"/>
1239           </xsl:attribute>
1240         </xsl:if>
1241         <xsl:apply-templates select = "*[2]" mode = "semantics">
1242           <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1243           <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1244         </xsl:apply-templates>
1245         <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1246       </m:msup>
1247     </xsl:otherwise>
1248   </xsl:choose>
1249 </xsl:template>
1250
1251 <xsl:template match = "m:apply[m:rem[1] | m:divide[1]]">
1252   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1253   <xsl:param name="PARAM" select="$NO_PARAM"/>
1254   <xsl:param name="PAREN" select="$PAR_NO"/>
1255   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1256   <xsl:choose>
1257     <xsl:when test="$IN_PREC &gt; $DIV_PREC or $IN_PREC=$DIV_PREC and
1258                                                     $PARAM=$PAR_SAME">
1259       <m:mfenced separators="">
1260         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1261           <xsl:attribute name="m:xref">
1262             <xsl:value-of select="@id"/>
1263           </xsl:attribute>
1264         </xsl:if>
1265         <xsl:apply-templates select="." mode="remdiv">
1266           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1267           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1268           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1269         </xsl:apply-templates>
1270       </m:mfenced>
1271     </xsl:when>
1272     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1273                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1274                     and not($SEM_SW=$SEM_XREF_EXT)">
1275       <xsl:apply-templates select="." mode="remdiv">
1276         <xsl:with-param name="PARAM" select="$PARAM"/>
1277         <xsl:with-param name="PAREN" select="$PAREN"/>
1278         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1279       </xsl:apply-templates>
1280     </xsl:when>
1281     <xsl:otherwise>
1282       <m:mrow>
1283         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1284           <xsl:attribute name="m:xref">
1285             <xsl:value-of select="@id"/>
1286           </xsl:attribute>
1287         </xsl:if>
1288         <xsl:apply-templates select="." mode="remdiv">
1289           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1290           <xsl:with-param name="PAREN" select="$PAREN"/>
1291           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1292         </xsl:apply-templates>
1293       </m:mrow>
1294     </xsl:otherwise>
1295   </xsl:choose>
1296 </xsl:template>
1297
1298 <xsl:template match = "m:apply[m:rem[1] | m:divide[1]]" mode="remdiv">
1299   <xsl:param name="PARAM" select="$NO_PARAM"/>
1300   <xsl:param name="PAREN" select="$PAR_NO"/>
1301   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1302   <xsl:apply-templates select = "*[2]" mode = "semantics">
1303     <xsl:with-param name="IN_PREC" select="$DIV_PREC"/>
1304       <xsl:with-param name="PARAM" select="$PARAM"/>
1305       <xsl:with-param name="PAREN" select="$PAREN"/>
1306       <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1307   </xsl:apply-templates>
1308   <m:mo>
1309     <xsl:if test="m:rem">
1310 <!-- HELM: added -->        
1311         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1312           <xsl:attribute name="m:xref">
1313             <xsl:value-of select="m:rem/@id"/>
1314           </xsl:attribute>
1315         </xsl:if>
1316       <xsl:value-of select="'%'"/>
1317     </xsl:if>
1318     <xsl:if test="m:divide">
1319 <!-- HELM: added -->        
1320         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1321           <xsl:attribute name="m:xref">
1322             <xsl:value-of select="m:divide/@id"/>
1323           </xsl:attribute>
1324         </xsl:if>
1325       <xsl:value-of select="'/'"/>
1326     </xsl:if>
1327   </m:mo>
1328   <xsl:apply-templates select = "*[3]" mode = "semantics">
1329     <xsl:with-param name="IN_PREC" select="$DIV_PREC"/>
1330     <xsl:with-param name="PARAM" select="$PAR_SAME"/>
1331     <xsl:with-param name="PAREN" select="$PAREN"/>
1332     <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1333   </xsl:apply-templates>
1334 </xsl:template>
1335
1336 <xsl:template match = "m:apply[m:times[1]]">
1337   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1338   <xsl:param name="PARAM" select="$NO_PARAM"/>
1339   <xsl:param name="PAREN" select="$PAR_NO"/>
1340   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1341   <xsl:choose>
1342     <xsl:when test="$IN_PREC &gt; $MUL_PREC or $IN_PREC=$MUL_PREC and
1343                                                     $PARAM=$PAR_SAME">
1344       <m:mfenced separators="">
1345         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1346           <xsl:attribute name="m:xref">
1347             <xsl:value-of select="@id"/>
1348           </xsl:attribute>
1349         </xsl:if>
1350         <xsl:apply-templates select="." mode="times">
1351           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1352           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1353           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1354         </xsl:apply-templates>
1355       </m:mfenced>
1356     </xsl:when>
1357     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1358                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1359                     and not($SEM_SW=$SEM_XREF_EXT)">
1360       <xsl:apply-templates select="." mode="times">
1361         <xsl:with-param name="PARAM" select="$PARAM"/>
1362         <xsl:with-param name="PAREN" select="$PAREN"/>
1363         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1364       </xsl:apply-templates>
1365     </xsl:when>
1366     <xsl:otherwise>
1367       <m:mrow>
1368         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1369           <xsl:attribute name="m:xref">
1370             <xsl:value-of select="@id"/>
1371           </xsl:attribute>
1372         </xsl:if>
1373         <xsl:apply-templates select="." mode="times">
1374           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1375           <xsl:with-param name="PAREN" select="$PAREN"/>
1376           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1377         </xsl:apply-templates>
1378       </m:mrow>
1379     </xsl:otherwise>
1380   </xsl:choose>
1381 </xsl:template>
1382
1383 <xsl:template match = "m:apply[m:times[1]]" mode="times">
1384   <xsl:param name="PARAM" select="$NO_PARAM"/>
1385   <xsl:param name="PAREN" select="$PAR_NO"/>
1386   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1387   <xsl:apply-templates select="*[2]" mode = "semantics">
1388     <xsl:with-param name="IN_PREC" select="$MUL_PREC"/>
1389     <xsl:with-param name="PARAM" select="$PARAM"/>
1390     <xsl:with-param name="PAREN" select="$PAREN"/>
1391     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1392   </xsl:apply-templates>
1393   <xsl:if test="*[3]">
1394     <xsl:for-each select = "*[position()>2]">
1395 <!-- HELM: to distinguish between * and the application -->
1396 <!--      <m:mo>&#x02062;</m:mo> -->
1397       <m:mo>
1398 <!-- HELM: added -->        
1399         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1400           <xsl:attribute name="m:xref">
1401             <xsl:value-of select="../m:times/@id"/>
1402           </xsl:attribute>
1403         </xsl:if>*</m:mo>
1404       <xsl:apply-templates select="." mode = "semantics">
1405         <xsl:with-param name="IN_PREC" select="$MUL_PREC"/>
1406         <xsl:with-param name="PAREN" select="$PAREN"/>
1407         <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1408       </xsl:apply-templates>
1409     </xsl:for-each>
1410   </xsl:if>
1411 </xsl:template>
1412
1413 <xsl:template match = "m:apply[m:root[1]]">
1414   <m:msqrt>
1415     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1416       <xsl:attribute name="m:xref">
1417         <xsl:value-of select="@id"/>
1418       </xsl:attribute>
1419     </xsl:if>
1420     <xsl:if test="*[2]=m:degree">
1421       <xsl:apply-templates select="*[3]" mode = "semantics">
1422         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1423         <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1424       </xsl:apply-templates>
1425       <xsl:apply-templates select="*[2]" mode = "semantics"/>
1426     </xsl:if>
1427     <xsl:if test="not(*[2]=m:degree)">
1428       <xsl:apply-templates select="*[2]" mode = "semantics">
1429         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1430         <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1431       </xsl:apply-templates>
1432       <m:mn>2</m:mn>
1433     </xsl:if>
1434   </m:msqrt>
1435 </xsl:template>
1436
1437 <xsl:template match = "m:apply[m:gcd[1]]">
1438   <m:mrow>
1439     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1440       <xsl:attribute name="m:xref">
1441         <xsl:value-of select="@id"/>
1442       </xsl:attribute>
1443     </xsl:if>
1444     <xsl:if test="not(parent::m:apply[m:power[1]])">
1445       <m:mo>
1446 <!-- HELM: added -->        
1447         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1448           <xsl:attribute name="m:xref">
1449             <xsl:value-of select="m:gcd/@id"/>
1450           </xsl:attribute>
1451         </xsl:if>gcd</m:mo>
1452     </xsl:if>
1453     <xsl:if test="parent::m:apply[m:power[1]]">
1454       <m:msup>
1455         <m:mo>
1456 <!-- HELM: added -->        
1457         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1458           <xsl:attribute name="m:xref">
1459             <xsl:value-of select="m:gcd/@id"/>
1460           </xsl:attribute>
1461         </xsl:if>gcd</m:mo>
1462         <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1463       </m:msup>
1464     </xsl:if>
1465     <m:mfenced separators=",">
1466       <xsl:for-each select = "*[position()>1]">
1467         <xsl:apply-templates select = "." mode="semantics"/>
1468       </xsl:for-each>
1469     </m:mfenced>
1470   </m:mrow>
1471 </xsl:template>
1472
1473 <xsl:template match = "m:apply[m:and[1]]">
1474   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1475   <xsl:param name="PAREN" select="$PAR_NO"/>
1476   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1477   <xsl:choose>
1478     <xsl:when test="$IN_PREC &gt; $AND_PREC">
1479       <m:mfenced separators="">
1480         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1481           <xsl:attribute name="m:xref">
1482             <xsl:value-of select="@id"/>
1483           </xsl:attribute>
1484         </xsl:if>
1485         <xsl:apply-templates select="." mode="and">
1486           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1487           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1488         </xsl:apply-templates>
1489       </m:mfenced>
1490     </xsl:when>
1491     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1492                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1493                     and not($SEM_SW=$SEM_XREF_EXT)">
1494       <xsl:apply-templates select="." mode="and">
1495         <xsl:with-param name="PARAM" select="$IN_PREC"/>
1496         <xsl:with-param name="PAREN" select="$PAREN"/>
1497         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1498       </xsl:apply-templates>
1499     </xsl:when>
1500     <xsl:otherwise>
1501       <m:mrow>
1502         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1503           <xsl:attribute name="m:xref">
1504             <xsl:value-of select="@id"/>
1505           </xsl:attribute>
1506         </xsl:if>
1507         <xsl:apply-templates select="." mode="and">
1508           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1509           <xsl:with-param name="PAREN" select="$PAREN"/>
1510           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1511         </xsl:apply-templates>
1512       </m:mrow>
1513     </xsl:otherwise>
1514   </xsl:choose>
1515 </xsl:template>
1516
1517 <xsl:template match = "m:apply[m:and[1]]" mode="and">
1518   <xsl:param name="PARAM" select="$NO_PARAM"/>
1519   <xsl:param name="PAREN" select="$PAR_NO"/>
1520   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1521   <xsl:apply-templates select="*[2]" mode = "semantics">
1522     <xsl:with-param name="IN_PREC" select="$AND_PREC"/>
1523     <xsl:with-param name="PARAM" select="$PARAM"/>
1524     <xsl:with-param name="PAREN" select="$PAREN"/>
1525     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1526   </xsl:apply-templates>
1527   <xsl:for-each select = "*[position()>2]">
1528     <m:mo>
1529 <!-- HELM: added -->        
1530         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1531           <xsl:attribute name="m:xref">
1532             <xsl:value-of select="../m:and/@id"/>
1533           </xsl:attribute>
1534         </xsl:if>&#x02227;</m:mo>
1535     <xsl:apply-templates select="." mode = "semantics">
1536       <xsl:with-param name="IN_PREC" select="$AND_PREC"/>
1537       <xsl:with-param name="PAREN" select="$PAREN"/>
1538       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1539     </xsl:apply-templates>
1540   </xsl:for-each>
1541 </xsl:template>
1542
1543 <xsl:template match = "m:apply[m:or[1]]">
1544   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1545   <xsl:param name="PAREN" select="$PAR_NO"/>
1546   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1547   <xsl:choose>
1548     <xsl:when test="$IN_PREC &gt; $OR_PREC">
1549       <m:mfenced separators="">
1550         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1551           <xsl:attribute name="m:xref">
1552             <xsl:value-of select="@id"/>
1553           </xsl:attribute>
1554         </xsl:if>
1555         <xsl:apply-templates select="." mode="or">
1556           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1557           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1558         </xsl:apply-templates>
1559       </m:mfenced>
1560     </xsl:when>
1561     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1562                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
1563                     and not($SEM_SW=$SEM_XREF_EXT)">
1564       <xsl:apply-templates select="." mode="or">
1565         <xsl:with-param name="PARAM" select="$IN_PREC"/>
1566         <xsl:with-param name="PAREN" select="$PAREN"/>
1567         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1568       </xsl:apply-templates>
1569     </xsl:when>
1570     <xsl:otherwise>
1571       <m:mrow>
1572         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1573           <xsl:attribute name="m:xref">
1574             <xsl:value-of select="@id"/>
1575           </xsl:attribute>
1576         </xsl:if>
1577         <xsl:apply-templates select="." mode="or">
1578           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1579           <xsl:with-param name="PAREN" select="$PAREN"/>
1580           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1581         </xsl:apply-templates>
1582       </m:mrow>
1583     </xsl:otherwise>
1584   </xsl:choose>
1585 </xsl:template>
1586
1587 <xsl:template match = "m:apply[m:or[1]]" mode="or">
1588   <xsl:param name="PARAM" select="$NO_PARAM"/>
1589   <xsl:param name="PAREN" select="$PAR_NO"/>
1590   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1591   <xsl:apply-templates select="*[2]" mode = "semantics">
1592     <xsl:with-param name="IN_PREC" select="$OR_PREC"/>
1593     <xsl:with-param name="PARAM" select="$PARAM"/>
1594     <xsl:with-param name="PAREN" select="$PAREN"/>
1595     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1596   </xsl:apply-templates>
1597   <xsl:for-each select = "*[position()>2]">
1598     <m:mo> 
1599 <!-- HELM: added -->        
1600         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1601           <xsl:attribute name="m:xref">
1602             <xsl:value-of select="../m:or/@id"/>
1603           </xsl:attribute>
1604         </xsl:if>&#x02228;</m:mo>
1605     <xsl:apply-templates select="." mode = "semantics">
1606       <xsl:with-param name="IN_PREC" select="$OR_PREC"/>
1607       <xsl:with-param name="PAREN" select="$PAREN"/>
1608       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1609     </xsl:apply-templates>
1610   </xsl:for-each>
1611 </xsl:template>
1612
1613 <xsl:template match = "m:apply[m:xor[1]]">
1614   <xsl:param name="IN_PREC" select="$NO_PREC"/>
1615   <xsl:param name="PAREN" select="$PAR_NO"/>
1616   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1617   <xsl:choose>
1618     <xsl:when test="$IN_PREC &gt; $XOR_PREC">
1619       <m:mfenced separators="">
1620         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1621           <xsl:attribute name="m:xref">
1622             <xsl:value-of select="@id"/>
1623           </xsl:attribute>
1624         </xsl:if>
1625         <xsl:apply-templates select="." mode="xor">
1626           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1627           <xsl:with-param name="PAREN" select="$PAR_YES"/>
1628           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1629         </xsl:apply-templates>
1630       </m:mfenced>
1631     </xsl:when>
1632     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
1633                                                 and not($SEM_SW=$SEM_ALL)">
1634       <xsl:apply-templates select="." mode="xor">
1635         <xsl:with-param name="PARAM" select="$IN_PREC"/>
1636         <xsl:with-param name="PAREN" select="$PAREN"/>
1637       </xsl:apply-templates>
1638     </xsl:when>
1639     <xsl:otherwise>
1640       <m:mrow>
1641         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1642           <xsl:attribute name="m:xref">
1643             <xsl:value-of select="@id"/>
1644           </xsl:attribute>
1645         </xsl:if>
1646         <xsl:apply-templates select="." mode="xor">
1647           <xsl:with-param name="PARAM" select="$IN_PREC"/>
1648           <xsl:with-param name="PAREN" select="$PAREN"/>
1649           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1650         </xsl:apply-templates>
1651       </m:mrow>
1652     </xsl:otherwise>
1653   </xsl:choose>
1654 </xsl:template>
1655
1656 <xsl:template match = "m:apply[m:xor[1]]" mode="xor">
1657   <xsl:param name="PARAM" select="$NO_PARAM"/>
1658   <xsl:param name="PAREN" select="$PAR_NO"/>
1659   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
1660   <xsl:apply-templates select="*[2]" mode = "semantics">
1661     <xsl:with-param name="IN_PREC" select="$XOR_PREC"/>
1662     <xsl:with-param name="PARAM" select="$PARAM"/>
1663     <xsl:with-param name="PAREN" select="$PAREN"/>
1664     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
1665   </xsl:apply-templates>
1666   <xsl:for-each select = "*[position()>2]">
1667     <m:mo>
1668  <!-- HELM: added -->        
1669         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1670           <xsl:attribute name="m:xref">
1671             <xsl:value-of select="../m:xor/@id"/>
1672           </xsl:attribute>
1673         </xsl:if>&#x022BB;</m:mo>
1674     <xsl:apply-templates select="." mode = "semantics">
1675       <xsl:with-param name="IN_PREC" select="$XOR_PREC"/>
1676       <xsl:with-param name="PAREN" select="$PAREN"/>
1677       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
1678     </xsl:apply-templates>
1679   </xsl:for-each>
1680 </xsl:template>
1681
1682 <xsl:template match = "m:apply[m:not[1]]">
1683   <m:mrow>
1684     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1685       <xsl:attribute name="m:xref">
1686         <xsl:value-of select="@id"/>
1687       </xsl:attribute>
1688     </xsl:if>
1689 <!-- HELM: was <m:mo>not</m:mo> -->
1690     <m:mo>
1691 <!-- HELM: added -->        
1692         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1693           <xsl:attribute name="m:xref">
1694             <xsl:value-of select="m:not/@id"/>
1695           </xsl:attribute>
1696         </xsl:if>&#x000AC;</m:mo>
1697     <xsl:apply-templates select = "*[2]" mode = "semantics">
1698       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
1699     </xsl:apply-templates>
1700   </m:mrow>
1701 </xsl:template>
1702
1703 <xsl:template match = "m:apply[m:forall[1]]">
1704   <m:mrow>
1705     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1706       <xsl:attribute name="m:xref">
1707         <xsl:value-of select="@id"/>
1708       </xsl:attribute>
1709     </xsl:if>
1710     <m:mo>
1711 <!-- HELM: added -->        
1712         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1713           <xsl:attribute name="m:xref">
1714             <xsl:value-of select="m:forall/@id"/>
1715           </xsl:attribute>
1716         </xsl:if>for all</m:mo>
1717     <xsl:if test="count(m:bvar) &gt; 1">
1718       <m:mfenced separators=",">
1719         <xsl:for-each select = "m:bvar">
1720           <xsl:apply-templates select = "." mode="semantics"/>
1721         </xsl:for-each>
1722       </m:mfenced>
1723     </xsl:if>
1724     <xsl:if test="count(m:bvar)=1">
1725       <xsl:apply-templates select = "m:bvar" mode="semantics"/>
1726     </xsl:if>
1727     <xsl:if test="m:condition">
1728       <m:mo>:</m:mo>
1729       <xsl:apply-templates select = "m:condition/*" mode = "semantics"/>
1730       <m:mo>,</m:mo>
1731     </xsl:if>
1732     <xsl:apply-templates select = "*[position()>1 and not(self::m:bvar) and
1733                                 not(self::m:condition)]" mode = "semantics"/>
1734   </m:mrow>
1735 </xsl:template>
1736
1737 <xsl:template match = "m:apply[m:exists[1]]">
1738   <m:mrow>
1739     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1740       <xsl:attribute name="m:xref">
1741         <xsl:value-of select="@id"/>
1742       </xsl:attribute>
1743     </xsl:if>
1744     <m:mo> 
1745 <!-- HELM: added -->        
1746         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1747           <xsl:attribute name="m:xref">
1748             <xsl:value-of select="m:exists/@id"/>
1749           </xsl:attribute>
1750         </xsl:if>&#x02203;</m:mo>
1751     <xsl:if test="count(m:bvar) &gt; 1">
1752       <m:mfenced separators=",">
1753         <xsl:for-each select = "m:bvar">
1754           <xsl:apply-templates select = "." mode="semantics"/>
1755         </xsl:for-each>
1756       </m:mfenced>
1757     </xsl:if>
1758     <xsl:if test="count(m:bvar)=1">
1759       <xsl:apply-templates select = "m:bvar" mode="semantics"/>
1760     </xsl:if>
1761     <xsl:if test="m:condition">
1762       <m:mo>,</m:mo>
1763       <xsl:apply-templates select = "m:condition/*" mode = "semantics"/>
1764     </xsl:if>
1765     <xsl:if test="*[position()>1 and not(self::m:bvar) and not(self::m:condition)]">
1766       <m:mo>:</m:mo>
1767       <xsl:apply-templates select = "*[position()>1 and not(self::m:bvar) and
1768                                 not(self::m:condition)]" mode = "semantics"/>
1769     </xsl:if>
1770   </m:mrow>
1771 </xsl:template>
1772
1773 <xsl:template match = "m:apply[m:abs[1]]">
1774   <xsl:if test="not(parent::m:apply[m:power[1]])">
1775     <m:mfenced open="|" close="|" separators="">
1776       <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1777         <xsl:attribute name="m:xref">
1778           <xsl:value-of select="@id"/>
1779         </xsl:attribute>
1780       </xsl:if>
1781       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1782     </m:mfenced>
1783   </xsl:if>
1784   <xsl:if test="parent::m:apply[m:power[1]]">
1785     <m:msup>
1786       <m:mfenced open="|" close="|" separators="">
1787         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1788           <xsl:attribute name="m:xref">
1789             <xsl:value-of select="@id"/>
1790           </xsl:attribute>
1791         </xsl:if>
1792         <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1793       </m:mfenced>
1794       <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
1795     </m:msup>
1796   </xsl:if>
1797 </xsl:template>
1798
1799 <xsl:template match = "m:apply[m:conjugate[1]]">
1800   <m:mover>
1801     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1802       <xsl:attribute name="m:xref">
1803         <xsl:value-of select="@id"/>
1804       </xsl:attribute>
1805     </xsl:if>
1806     <m:mrow>
1807       <xsl:apply-templates select = "*[position()>1]" mode = "semantics"/>
1808     </m:mrow>
1809     <m:mo>
1810  <!-- HELM: added -->        
1811         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1812           <xsl:attribute name="m:xref">
1813             <xsl:value-of select="m:conjugate/@id"/>
1814           </xsl:attribute>
1815         </xsl:if>&#x00332;</m:mo>
1816   </m:mover>
1817 </xsl:template>
1818
1819 <xsl:template match = "m:apply[m:arg[1] | m:real[1] | m:imaginary[1]]">
1820   <m:mrow>
1821     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1822       <xsl:attribute name="m:xref">
1823         <xsl:value-of select="@id"/>
1824       </xsl:attribute>
1825     </xsl:if>
1826     <m:mo>
1827       <xsl:if test="m:arg">
1828 <!-- HELM: added -->        
1829         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1830           <xsl:attribute name="m:xref">
1831             <xsl:value-of select="m:arg/@id"/>
1832           </xsl:attribute>
1833         </xsl:if>
1834         <xsl:value-of select="'Arg'"/>
1835       </xsl:if>
1836       <xsl:if test="m:real">
1837 <!-- HELM: added -->        
1838         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1839           <xsl:attribute name="m:xref">
1840             <xsl:value-of select="m:real/@id"/>
1841           </xsl:attribute>
1842         </xsl:if>
1843         <xsl:value-of select="'Re'"/>
1844       </xsl:if>
1845       <xsl:if test="m:imaginary">
1846 <!-- HELM: added -->        
1847         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1848           <xsl:attribute name="m:xref">
1849             <xsl:value-of select="m:imaginary/@id"/>
1850           </xsl:attribute>
1851         </xsl:if>
1852         <xsl:value-of select="'Im'"/>
1853       </xsl:if>
1854     </m:mo>
1855     <m:mfenced separators="">
1856       <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1857     </m:mfenced>
1858   </m:mrow>
1859 </xsl:template>
1860
1861
1862 <!-- ***************** RELATIONS ***************** -->
1863
1864 <xsl:template match = "m:apply[m:neq | m:approx | m:tendsto | m:implies
1865                      | m:in | m:notin | m:notsubset | m:notprsubset
1866                      | m:subset | m:prsubset | m:eq | m:gt | m:lt
1867                      | m:geq | m:leq | m:equivalent]">
1868   <m:mrow>
1869     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1870       <xsl:attribute name="m:xref">
1871         <xsl:value-of select="@id"/>
1872       </xsl:attribute>
1873     </xsl:if>
1874     <xsl:if test="*[1]=m:neq or *[1]=m:approx or *[1]=m:tendsto or
1875                   *[1]=m:implies or *[1]=m:in or *[1]=m:notin or
1876                   *[1]=m:notsubset or *[1]=m:notprsubset">
1877       <xsl:apply-templates select = "*[2]" mode = "semantics"/>
1878       <m:mo>
1879         <xsl:if test="*[1]=m:neq">
1880 <!-- HELM: added -->        
1881         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1882           <xsl:attribute name="m:xref">
1883             <xsl:value-of select="m:neq/@id"/>
1884           </xsl:attribute>
1885         </xsl:if>
1886         &#x02260;
1887         </xsl:if>
1888         <xsl:if test="*[1]=m:approx">
1889 <!-- HELM: added -->        
1890         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1891           <xsl:attribute name="m:xref">
1892             <xsl:value-of select="m:approx/@id"/>
1893           </xsl:attribute>
1894         </xsl:if>
1895         &#x0224A;
1896         </xsl:if>
1897         <xsl:if test="*[1]=m:tendsto">
1898 <!-- HELM: added -->        
1899         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1900           <xsl:attribute name="m:xref">
1901             <xsl:value-of select="m:tendsto/@id"/>
1902           </xsl:attribute>
1903         </xsl:if>
1904         &#x02192;
1905         </xsl:if>
1906         <xsl:if test="*[1]=m:implies">
1907 <!-- HELM: added -->        
1908         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1909           <xsl:attribute name="m:xref">
1910             <xsl:value-of select="m:implies/@id"/>
1911           </xsl:attribute>
1912         </xsl:if>
1913         &#x021D2;
1914         </xsl:if>
1915         <xsl:if test="*[1]=m:in">
1916 <!-- HELM: added -->        
1917         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1918           <xsl:attribute name="m:xref">
1919             <xsl:value-of select="m:in/@id"/>
1920           </xsl:attribute>
1921         </xsl:if>
1922         &#x02208;
1923         </xsl:if>
1924         <xsl:if test="*[1]=m:notin">
1925 <!-- HELM: added -->        
1926         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1927           <xsl:attribute name="m:xref">
1928             <xsl:value-of select="m:notin/@id"/>
1929           </xsl:attribute>
1930         </xsl:if>
1931         &#x02209;
1932         </xsl:if>
1933         <xsl:if test="*[1]=m:notsubset">
1934 <!-- HELM: added -->        
1935         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1936           <xsl:attribute name="m:xref">
1937             <xsl:value-of select="m:notsubset/@id"/>
1938           </xsl:attribute>
1939         </xsl:if>
1940         &#x02284;
1941         </xsl:if>
1942         <xsl:if test="*[1]=m:notprsubset">
1943 <!-- HELM: added -->        
1944         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1945           <xsl:attribute name="m:xref">
1946             <xsl:value-of select="m:notprsubset/@id"/>
1947           </xsl:attribute>
1948         </xsl:if>
1949         &#x02288;
1950         </xsl:if>
1951       </m:mo>
1952       <xsl:apply-templates select = "*[3]" mode = "semantics"/>
1953       <xsl:if test="*[1]=m:tendsto and m:tendsto[1][@type='below']">
1954         <m:mo>
1955 <!-- HELM: added -->        
1956         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1957           <xsl:attribute name="m:xref">
1958             <xsl:value-of select="m:tendsto/@id"/>
1959           </xsl:attribute>
1960         </xsl:if>-</m:mo>
1961       </xsl:if>
1962       <xsl:if test="*[1]=m:tendsto and m:tendsto[1][@type='above']">
1963         <m:mo>
1964 <!-- HELM: added -->        
1965         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1966           <xsl:attribute name="m:xref">
1967             <xsl:value-of select="m:tendsto/@id"/>
1968           </xsl:attribute>
1969         </xsl:if>+</m:mo>
1970       </xsl:if>
1971     </xsl:if>
1972     <xsl:if test="*[1]=m:subset or *[1]=m:prsubset or *[1]=m:eq or *[1]=m:gt
1973                or *[1]=m:lt or *[1]=m:geq or *[1]=m:leq or *[1]=m:equivalent">
1974       <xsl:apply-templates select = "*[2]" mode="semantics"/>
1975       <xsl:for-each select = "*[position()>2]">
1976         <m:mo>
1977           <xsl:if test="../*[self::m:subset][1]">
1978 <!-- HELM: added -->        
1979         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1980           <xsl:attribute name="m:xref">
1981             <xsl:value-of select="../m:subset/@id"/>
1982           </xsl:attribute>
1983         </xsl:if>
1984         &#x02286;
1985           </xsl:if>
1986           <xsl:if test="../*[self::m:prsubset][1]">
1987 <!-- HELM: added -->        
1988         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1989           <xsl:attribute name="m:xref">
1990             <xsl:value-of select="../m:prsubset/@id"/>
1991           </xsl:attribute>
1992         </xsl:if>
1993         &#x02282;
1994           </xsl:if>
1995           <xsl:if test="../*[self::m:eq][1]">
1996 <!-- HELM: added -->        
1997         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
1998           <xsl:attribute name="m:xref">
1999             <xsl:value-of select="../m:eq/@id"/>
2000           </xsl:attribute>
2001         </xsl:if>
2002             <xsl:value-of select="'='"/>
2003           </xsl:if>
2004           <xsl:if test="../*[self::m:gt][1]">
2005 <!-- HELM: added -->        
2006         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2007           <xsl:attribute name="m:xref">
2008             <xsl:value-of select="../m:gt/@id"/>
2009           </xsl:attribute>
2010         </xsl:if>
2011             <xsl:value-of select="'&gt;'"/>
2012           </xsl:if>
2013           <xsl:if test="../*[self::m:lt][1]">
2014 <!-- HELM: added -->        
2015         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2016           <xsl:attribute name="m:xref">
2017             <xsl:value-of select="../m:lt/@id"/>
2018           </xsl:attribute>
2019         </xsl:if>
2020             <xsl:value-of select="'&lt;'"/>
2021           </xsl:if>
2022           <xsl:if test="../*[self::m:geq][1]">
2023 <!-- HELM: added -->        
2024         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2025           <xsl:attribute name="m:xref">
2026             <xsl:value-of select="../m:geq/@id"/>
2027           </xsl:attribute>
2028         </xsl:if>
2029         &#x02265;
2030           </xsl:if>
2031           <xsl:if test="../*[self::m:leq][1]">
2032 <!-- HELM: added -->        
2033         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2034           <xsl:attribute name="m:xref">
2035             <xsl:value-of select="../m:leq/@id"/>
2036           </xsl:attribute>
2037         </xsl:if>
2038         &#x02264;
2039           </xsl:if>
2040           <xsl:if test="../*[self::m:equivalent][1]">
2041 <!-- HELM: added -->        
2042         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2043           <xsl:attribute name="m:xref">
2044             <xsl:value-of select="../m:equivalent/@id"/>
2045           </xsl:attribute>
2046         </xsl:if>
2047         &#x02261;
2048           </xsl:if>
2049         </m:mo>
2050         <xsl:apply-templates select = "." mode="semantics"/>
2051       </xsl:for-each>
2052     </xsl:if>
2053   </m:mrow>
2054 </xsl:template>
2055
2056
2057 <!-- ***************** CALCULUS ***************** -->
2058
2059 <xsl:template match = "m:apply[*[1][self::m:ln]]">
2060   <m:mrow>
2061     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2062       <xsl:attribute name="m:xref">
2063         <xsl:value-of select="@id"/>
2064       </xsl:attribute>
2065     </xsl:if>
2066     <xsl:choose>
2067       <xsl:when test="parent::m:apply[m:power[1]]">
2068         <m:msup>
2069           <m:mo>
2070 <!-- HELM: added -->        
2071         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2072           <xsl:attribute name="m:xref">
2073             <xsl:value-of select="m:ln/@id"/>
2074           </xsl:attribute>
2075         </xsl:if>ln</m:mo>
2076           <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
2077         </m:msup>
2078       </xsl:when>
2079       <xsl:otherwise>
2080         <m:mo>
2081 <!-- HELM: added -->        
2082         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2083           <xsl:attribute name="m:xref">
2084             <xsl:value-of select="m:ln/@id"/>
2085           </xsl:attribute>
2086         </xsl:if>ln</m:mo>
2087       </xsl:otherwise>
2088     </xsl:choose>
2089     <m:mo>&#x02061;</m:mo>
2090     <xsl:apply-templates select = "*[2]" mode = "semantics">
2091       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
2092     </xsl:apply-templates>
2093   </m:mrow>
2094 </xsl:template>
2095
2096 <xsl:template match = "m:apply[m:log[1]]">
2097   <m:mrow>
2098     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2099       <xsl:attribute name="m:xref">
2100         <xsl:value-of select="@id"/>
2101       </xsl:attribute>
2102     </xsl:if>
2103     <xsl:choose>
2104       <xsl:when test="parent::m:apply[m:power[1]]">
2105         <xsl:if test="not(*[2]=m:logbase)">
2106           <m:msup>
2107             <m:mo>
2108 <!-- HELM: added -->        
2109         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2110           <xsl:attribute name="m:xref">
2111             <xsl:value-of select="m:log/@id"/>
2112           </xsl:attribute>
2113         </xsl:if>log</m:mo>
2114             <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
2115           </m:msup>
2116         </xsl:if>
2117         <xsl:if test="*[2]=m:logbase">
2118           <m:msubsup>
2119             <m:mo>
2120 <!-- HELM: added -->        
2121         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2122           <xsl:attribute name="m:xref">
2123             <xsl:value-of select="m:log/@id"/>
2124           </xsl:attribute>
2125         </xsl:if>log</m:mo>
2126             <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
2127             <xsl:apply-templates select = "m:logbase" mode = "semantics"/>
2128           </m:msubsup>
2129         </xsl:if>
2130       </xsl:when>
2131       <xsl:otherwise>
2132         <xsl:if test="not(*[2]=m:logbase)">
2133           <m:mo>log</m:mo>
2134         </xsl:if>
2135         <xsl:if test="*[2]=m:logbase">
2136           <m:msub>
2137             <m:mo>
2138 <!-- HELM: added -->        
2139         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2140           <xsl:attribute name="m:xref">
2141             <xsl:value-of select="m:log/@id"/>
2142           </xsl:attribute>
2143         </xsl:if>log</m:mo>
2144             <xsl:apply-templates select = "m:logbase" mode = "semantics"/>
2145           </m:msub>
2146         </xsl:if>
2147       </xsl:otherwise>
2148     </xsl:choose>
2149     <m:mo>&#x02061;</m:mo>
2150     <xsl:if test="*[2]=m:logbase">
2151       <xsl:apply-templates select = "*[3]" mode = "semantics">
2152         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
2153       </xsl:apply-templates>
2154     </xsl:if>
2155     <xsl:if test="not(*[2]=m:logbase)">
2156       <xsl:apply-templates select = "*[2]" mode = "semantics">
2157         <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
2158       </xsl:apply-templates>
2159     </xsl:if>
2160   </m:mrow>
2161 </xsl:template>
2162
2163 <xsl:template match = "m:apply[m:diff[1]]">
2164   <m:mrow>
2165     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2166       <xsl:attribute name="m:xref">
2167         <xsl:value-of select="@id"/>
2168       </xsl:attribute>
2169     </xsl:if>
2170     <xsl:if test="*[2]=m:bvar and m:bvar[*[2]=m:degree]">
2171       <m:mfrac>
2172 <!-- HELM: added -->        
2173         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2174           <xsl:attribute name="m:xref">
2175             <xsl:value-of select="m:diff/@id"/>
2176           </xsl:attribute>
2177         </xsl:if>
2178         <m:msup>
2179           <m:mo>d</m:mo>
2180           <xsl:apply-templates select = "m:bvar/m:degree" mode = "semantics"/>
2181         </m:msup>
2182         <m:mrow>
2183           <m:mo>d</m:mo>
2184           <m:msup>
2185             <xsl:apply-templates select = "m:bvar/*[1]" mode = "semantics"/>
2186             <xsl:apply-templates select = "m:bvar/m:degree" mode = "semantics"/>
2187           </m:msup>
2188         </m:mrow>
2189       </m:mfrac>
2190     </xsl:if>
2191     <xsl:if test="*[2]=m:bvar and not(m:bvar[*[2]=m:degree])">
2192       <m:mfrac>
2193 <!-- HELM: added -->        
2194         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2195           <xsl:attribute name="m:xref">
2196             <xsl:value-of select="m:diff/@id"/>
2197           </xsl:attribute>
2198         </xsl:if>
2199         <m:mo>d</m:mo>
2200         <m:mrow>
2201           <m:mo>d</m:mo>
2202           <xsl:apply-templates select = "m:bvar/*[1]" mode = "semantics"/>
2203         </m:mrow>
2204       </m:mfrac>
2205     </xsl:if>
2206     <xsl:apply-templates select = "*[3]" mode = "semantics"/>
2207   </m:mrow>
2208 </xsl:template>
2209
2210 <xsl:template match = "m:apply[m:partialdiff[1]]">
2211   <m:mrow>
2212     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2213       <xsl:attribute name="m:xref">
2214         <xsl:value-of select="@id"/>
2215       </xsl:attribute>
2216     </xsl:if>
2217     <xsl:for-each select = "m:bvar">
2218       <xsl:if test="*[last()]=m:degree">
2219         <m:mfrac>
2220 <!-- HELM: added -->        
2221         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2222           <xsl:attribute name="m:xref">
2223             <xsl:value-of select="m:partialdiff/@id"/>
2224           </xsl:attribute>
2225         </xsl:if>
2226           <m:msup>
2227              <m:mo>d</m:mo>
2228              <xsl:apply-templates select = "m:degree" mode = "semantics"/>
2229           </m:msup>
2230           <m:mrow>
2231             <m:mo>d</m:mo>
2232             <m:msup>
2233               <xsl:apply-templates select = "*[1]" mode = "semantics"/>
2234               <xsl:apply-templates select = "m:degree" mode = "semantics"/>
2235             </m:msup>
2236           </m:mrow>
2237         </m:mfrac>
2238       </xsl:if>
2239       <xsl:if test="not(*[last()]=m:degree)">
2240         <m:mfrac>
2241 <!-- HELM: added -->        
2242         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2243           <xsl:attribute name="m:xref">
2244             <xsl:value-of select="m:partialdiff/@id"/>
2245           </xsl:attribute>
2246         </xsl:if>
2247           <m:mo>d</m:mo>
2248           <m:mrow>
2249             <m:mo>d</m:mo>
2250             <xsl:apply-templates select = "*[1]" mode = "semantics"/>
2251           </m:mrow>
2252         </m:mfrac>
2253       </xsl:if>
2254     </xsl:for-each>
2255     <xsl:apply-templates select = "*[last()]" mode = "semantics"/>
2256   </m:mrow>
2257 </xsl:template>
2258
2259 <xsl:template match = "m:lowlimit | m:uplimit | m:bvar | m:degree |
2260                                                                m:logbase">
2261   <xsl:apply-templates select="*" mode = "semantics"/>
2262 </xsl:template>
2263
2264 <xsl:template match = "m:apply[m:divergence[1] | m:grad[1] | m:curl[1]]">
2265   <m:mrow>
2266     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2267       <xsl:attribute name="m:xref">
2268         <xsl:value-of select="@id"/>
2269       </xsl:attribute>
2270     </xsl:if>
2271     <m:mo>
2272       <xsl:if test="*[1]=m:divergence">
2273 <!-- HELM: added -->        
2274         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2275           <xsl:attribute name="m:xref">
2276             <xsl:value-of select="m:divergence/@id"/>
2277           </xsl:attribute>
2278         </xsl:if>
2279         <xsl:value-of select="'div'"/>
2280       </xsl:if>
2281       <xsl:if test="*[1]=m:grad">
2282 <!-- HELM: added -->        
2283         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2284           <xsl:attribute name="m:xref">
2285             <xsl:value-of select="m:grad/@id"/>
2286           </xsl:attribute>
2287         </xsl:if>
2288         <xsl:value-of select="'grad'"/>
2289       </xsl:if>
2290       <xsl:if test="*[1]=m:curl">
2291 <!-- HELM: added -->        
2292         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2293           <xsl:attribute name="m:xref">
2294             <xsl:value-of select="m:curl/@id"/>
2295           </xsl:attribute>
2296         </xsl:if>
2297         <xsl:value-of select="'curl'"/>
2298       </xsl:if>
2299     </m:mo>
2300     <xsl:choose>
2301       <xsl:when test="*[2]=m:ci">
2302         <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2303       </xsl:when>
2304       <xsl:otherwise>
2305         <m:mfenced separators="">
2306           <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2307         </m:mfenced>
2308       </xsl:otherwise>
2309     </xsl:choose>
2310   </m:mrow>
2311 </xsl:template>
2312
2313 <xsl:template match = "m:apply[m:laplacian[1]]">
2314   <m:mrow>
2315     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2316       <xsl:attribute name="m:xref">
2317         <xsl:value-of select="@id"/>
2318       </xsl:attribute>
2319     </xsl:if>
2320     <m:msup>
2321 <!-- HELM: added -->        
2322         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2323           <xsl:attribute name="m:xref">
2324             <xsl:value-of select="m:laplacian/@id"/>
2325           </xsl:attribute>
2326         </xsl:if>
2327       <m:mo>&#x00394;</m:mo>
2328       <m:mn>2</m:mn>
2329     </m:msup>
2330     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2331   </m:mrow>
2332 </xsl:template>
2333
2334
2335 <!-- ***************** SET THEORY ***************** -->
2336
2337 <xsl:template match = "m:set | m:list">
2338   <m:mfenced open="{{" close="}}" separators="">
2339     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2340       <xsl:attribute name="m:xref">
2341         <xsl:value-of select="@id"/>
2342       </xsl:attribute>
2343     </xsl:if>
2344     <xsl:if test="*[1]=m:bvar and *[2]=m:condition">
2345       <xsl:apply-templates select="m:bvar" mode = "semantics"/>
2346       <m:mo>|</m:mo>
2347       <xsl:apply-templates select="m:condition" mode = "semantics"/>
2348     </xsl:if>
2349     <xsl:if test="*[1]=m:condition and not(child::m:bvar)">
2350       <m:mfenced open="" close="" separators=",">
2351         <xsl:for-each select = "*[not(self::m:condition) and not(self::m:bvar)]">
2352           <xsl:apply-templates select = "." mode="semantics"/>
2353         </xsl:for-each>
2354       </m:mfenced>
2355       <m:mo>|</m:mo>
2356       <xsl:apply-templates select="m:condition" mode = "semantics"/>
2357     </xsl:if>
2358     <xsl:if test="not(child::m:bvar) and not(child::m:condition)">
2359       <m:mfenced open="" close="" separators=",">
2360         <xsl:for-each select = "*">
2361           <xsl:apply-templates select = "." mode="semantics"/>
2362         </xsl:for-each>
2363       </m:mfenced>
2364     </xsl:if>
2365   </m:mfenced>
2366 </xsl:template>
2367
2368 <xsl:template match = "m:apply[m:union[1]]">
2369   <xsl:param name="IN_PREC" select="$NO_PREC"/>
2370   <xsl:param name="PARAM" select="$NO_PARAM"/>
2371   <xsl:param name="PAREN" select="$PAR_NO"/>
2372   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2373   <xsl:choose>
2374     <xsl:when test="$IN_PREC &gt; $UNION_PREC or $IN_PREC=$UNION_PREC
2375                     and $PARAM=$PAR_SAME">
2376       <m:mfenced separators="">
2377         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2378           <xsl:attribute name="m:xref">
2379             <xsl:value-of select="@id"/>
2380           </xsl:attribute>
2381         </xsl:if>
2382         <xsl:apply-templates select="." mode="union">
2383           <xsl:with-param name="PARAM" select="$PARAM"/>
2384           <xsl:with-param name="PAREN" select="$PAREN"/>
2385           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2386         </xsl:apply-templates>
2387       </m:mfenced>
2388     </xsl:when>
2389     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
2390                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
2391                     and not($SEM_SW=$SEM_XREF_EXT)">
2392       <xsl:apply-templates select="." mode="union">
2393         <xsl:with-param name="PARAM" select="$PARAM"/>
2394         <xsl:with-param name="PAREN" select="$PAREN"/>
2395         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2396       </xsl:apply-templates>
2397     </xsl:when>
2398     <xsl:otherwise>
2399       <m:mrow>
2400         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2401           <xsl:attribute name="m:xref">
2402             <xsl:value-of select="@id"/>
2403           </xsl:attribute>
2404         </xsl:if>
2405         <xsl:apply-templates select="." mode="union">
2406           <xsl:with-param name="PARAM" select="$PARAM"/>
2407           <xsl:with-param name="PAREN" select="$PAREN"/>
2408           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2409         </xsl:apply-templates>
2410       </m:mrow>
2411     </xsl:otherwise>
2412   </xsl:choose>
2413 </xsl:template>
2414
2415 <xsl:template match = "m:apply[m:union[1]]" mode="union">
2416   <xsl:param name="PARAM" select="$NO_PARAM"/>
2417   <xsl:param name="PAREN" select="$PAR_NO"/>
2418   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2419   <xsl:apply-templates select = "*[2]" mode="semantics">
2420     <xsl:with-param name="IN_PREC" select="$UNION_PREC"/>
2421     <xsl:with-param name="PARAM" select="$PARAM"/>
2422     <xsl:with-param name="PAREN" select="$PAREN"/>
2423     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2424   </xsl:apply-templates>
2425   <xsl:for-each select = "*[position()>2]">
2426     <m:mo>
2427 <!-- HELM: added -->        
2428         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2429           <xsl:attribute name="m:xref">
2430             <xsl:value-of select="../m:union/@id"/>
2431           </xsl:attribute>
2432         </xsl:if>&#x022C3;</m:mo>
2433     <xsl:apply-templates select = "." mode="semantics">
2434       <xsl:with-param name="IN_PREC" select="$UNION_PREC"/>
2435       <xsl:with-param name="PAREN" select="$PAREN"/>
2436       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
2437     </xsl:apply-templates>
2438   </xsl:for-each>
2439 </xsl:template>
2440
2441 <xsl:template match = "m:apply[m:intersect[1]]">
2442   <xsl:param name="IN_PREC" select="$NO_PREC"/>
2443   <xsl:param name="PARAM" select="$NO_PARAM"/>
2444   <xsl:param name="PAREN" select="$PAR_NO"/>
2445   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2446   <xsl:choose>
2447     <xsl:when test="$IN_PREC &gt; $INTERSECT_PREC">
2448       <m:mfenced separators="">
2449         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2450           <xsl:attribute name="m:xref">
2451             <xsl:value-of select="@id"/>
2452           </xsl:attribute>
2453         </xsl:if>
2454         <xsl:apply-templates select="." mode="intersect">
2455           <xsl:with-param name="PARAM" select="$PARAM"/>
2456           <xsl:with-param name="PAREN" select="$PAREN"/>
2457           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2458         </xsl:apply-templates>
2459       </m:mfenced>
2460     </xsl:when>
2461     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
2462                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
2463                     and not($SEM_SW=$SEM_XREF_EXT)">
2464       <xsl:apply-templates select="." mode="intersect">
2465         <xsl:with-param name="PARAM" select="$PARAM"/>
2466         <xsl:with-param name="PAREN" select="$PAREN"/>
2467         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2468       </xsl:apply-templates>
2469     </xsl:when>
2470     <xsl:otherwise>
2471       <m:mrow>
2472         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2473           <xsl:attribute name="m:xref">
2474             <xsl:value-of select="@id"/>
2475           </xsl:attribute>
2476         </xsl:if>
2477         <xsl:apply-templates select="." mode="intersect">
2478           <xsl:with-param name="PARAM" select="$PARAM"/>
2479           <xsl:with-param name="PAREN" select="$PAREN"/>
2480           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2481         </xsl:apply-templates>
2482       </m:mrow>
2483     </xsl:otherwise>
2484   </xsl:choose>
2485 </xsl:template>
2486
2487 <xsl:template match = "m:apply[m:intersect[1]]" mode="intersect">
2488   <xsl:param name="PARAM" select="$NO_PARAM"/>
2489   <xsl:param name="PAREN" select="$PAR_NO"/>
2490   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2491   <xsl:apply-templates select = "*[2]" mode="semantics">
2492     <xsl:with-param name="IN_PREC" select="$INTERSECT_PREC"/>
2493     <xsl:with-param name="PARAM" select="$PARAM"/>
2494     <xsl:with-param name="PAREN" select="$PAREN"/>
2495     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2496   </xsl:apply-templates>
2497   <xsl:for-each select = "*[position()>2]">
2498     <m:mo>
2499 <!-- HELM: added -->        
2500         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2501           <xsl:attribute name="m:xref">
2502             <xsl:value-of select="../m:intersect/@id"/>
2503           </xsl:attribute>
2504         </xsl:if>&#x022C2;</m:mo>
2505     <xsl:apply-templates select = "." mode="semantics">
2506       <xsl:with-param name="IN_PREC" select="$INTERSECT_PREC"/>
2507       <xsl:with-param name="PAREN" select="$PAREN"/>
2508       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
2509     </xsl:apply-templates>
2510   </xsl:for-each>
2511 </xsl:template>
2512
2513 <xsl:template match = "m:apply[m:setdiff[1]]">
2514   <xsl:param name="IN_PREC" select="$NO_PREC"/>
2515   <xsl:param name="PARAM" select="$NO_PARAM"/>
2516   <xsl:param name="PAREN" select="$PAR_NO"/>
2517   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2518   <xsl:choose>
2519     <xsl:when test="$IN_PREC &gt; $SETDIFF_PREC or $IN_PREC=$SETDIFF_PREC
2520                     and $PARAM=$PAR_SAME">
2521       <m:mfenced separators="">
2522         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2523           <xsl:attribute name="m:xref">
2524             <xsl:value-of select="@id"/>
2525           </xsl:attribute>
2526         </xsl:if>
2527         <xsl:apply-templates select="." mode="setdiff">
2528           <xsl:with-param name="PARAM" select="$PARAM"/>
2529           <xsl:with-param name="PAREN" select="$PAREN"/>
2530           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2531         </xsl:apply-templates>
2532       </m:mfenced>
2533     </xsl:when>
2534     <xsl:when test="$IN_PREC &gt; $NO_PREC and $IN_PREC &lt; $FUNCTION_PREC
2535                     and not($SEM_SW=$SEM_ALL) and not($SEM_SW=$SEM_XREF)
2536                     and not($SEM_SW=$SEM_XREF_EXT)">
2537       <xsl:apply-templates select="." mode="setdiff">
2538         <xsl:with-param name="PARAM" select="$PARAM"/>
2539         <xsl:with-param name="PAREN" select="$PAREN"/>
2540         <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2541       </xsl:apply-templates>
2542     </xsl:when>
2543     <xsl:otherwise>
2544       <m:mrow>
2545         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2546           <xsl:attribute name="m:xref">
2547             <xsl:value-of select="@id"/>
2548           </xsl:attribute>
2549         </xsl:if>
2550         <xsl:apply-templates select="." mode="setdiff">
2551           <xsl:with-param name="PARAM" select="$PARAM"/>
2552           <xsl:with-param name="PAREN" select="$PAREN"/>
2553           <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2554         </xsl:apply-templates>
2555       </m:mrow>
2556     </xsl:otherwise>
2557   </xsl:choose>
2558 </xsl:template>
2559
2560 <xsl:template match = "m:apply[m:setdiff[1]]" mode="setdiff">
2561   <xsl:param name="PARAM" select="$NO_PARAM"/>
2562   <xsl:param name="PAREN" select="$PAR_NO"/>
2563   <xsl:param name="PAR_NO_IGNORE" select="$YES"/>
2564   <xsl:apply-templates select = "*[2]" mode = "semantics">
2565     <xsl:with-param name="IN_PREC" select="$SETDIFF_PREC"/>
2566     <xsl:with-param name="PARAM" select="$PARAM"/>
2567     <xsl:with-param name="PAREN" select="$PAREN"/>
2568     <xsl:with-param name="PAR_NO_IGNORE" select="$PAR_NO_IGNORE"/>
2569   </xsl:apply-templates>
2570   <m:mo>
2571 <!-- HELM: added -->        
2572         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2573           <xsl:attribute name="m:xref">
2574             <xsl:value-of select="m:setdiff/@id"/>
2575           </xsl:attribute>
2576         </xsl:if>\</m:mo>
2577   <xsl:apply-templates select = "*[3]" mode = "semantics">
2578     <xsl:with-param name="IN_PREC" select="$SETDIFF_PREC"/>
2579     <xsl:with-param name="PARAM" select="$PAR_SAME"/>
2580     <xsl:with-param name="PAREN" select="$PAREN"/>
2581     <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
2582   </xsl:apply-templates>
2583 </xsl:template>
2584
2585 <xsl:template match = "m:apply[m:card[1]]">
2586   <m:mfenced open="|" close="|" separators=",">
2587     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2588       <xsl:attribute name="m:xref">
2589         <xsl:value-of select="@id"/>
2590       </xsl:attribute>
2591     </xsl:if>
2592     <xsl:for-each select = "*[position()>1]">
2593       <xsl:apply-templates select = "." mode="semantics"/>
2594     </xsl:for-each>
2595   </m:mfenced>
2596 </xsl:template>
2597
2598
2599 <!-- ***************** SEQUENCES AND SERIES ***************** -->
2600
2601 <xsl:template match = "m:apply[m:sum[1] | m:product[1]]">
2602   <m:mrow>
2603     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2604       <xsl:attribute name="m:xref">
2605         <xsl:value-of select="@id"/>
2606       </xsl:attribute>
2607     </xsl:if>
2608     <xsl:choose>
2609       <xsl:when test="*[2]=m:bvar and m:lowlimit and m:uplimit">
2610         <m:munderover>
2611           <m:mo>
2612             <xsl:if test="*[1]=m:sum">
2613 <!-- HELM: added -->        
2614         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2615           <xsl:attribute name="m:xref">
2616             <xsl:value-of select="m:sum/@id"/>
2617           </xsl:attribute>
2618         </xsl:if>
2619         &#x02211;
2620             </xsl:if>
2621             <xsl:if test="*[1]=m:product">
2622 <!-- HELM: added -->        
2623         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2624           <xsl:attribute name="m:xref">
2625             <xsl:value-of select="m:product/@id"/>
2626           </xsl:attribute>
2627         </xsl:if>
2628         &#x0220F;
2629             </xsl:if>
2630           </m:mo>
2631           <m:mrow>
2632             <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2633             <m:mo>=</m:mo>
2634             <xsl:apply-templates select = "m:lowlimit" mode = "semantics"/>
2635           </m:mrow>
2636           <xsl:apply-templates select = "m:uplimit" mode = "semantics"/>
2637         </m:munderover>
2638         <xsl:apply-templates select = "*[5]" mode = "semantics"/>
2639       </xsl:when>
2640       <xsl:when test="*[2]=m:bvar and *[3]=m:condition">
2641         <m:munder>
2642           <m:mo>
2643             <xsl:if test="*[1]=m:sum">
2644 <!-- HELM: added -->        
2645         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2646           <xsl:attribute name="m:xref">
2647             <xsl:value-of select="m:sum/@id"/>
2648           </xsl:attribute>
2649         </xsl:if>
2650         &#x02211;
2651             </xsl:if>
2652             <xsl:if test="*[1]=m:product">
2653 <!-- HELM: added -->        
2654         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2655           <xsl:attribute name="m:xref">
2656             <xsl:value-of select="m:product/@id"/>
2657           </xsl:attribute>
2658         </xsl:if>
2659         &#x0220F;
2660             </xsl:if>
2661           </m:mo>
2662           <xsl:apply-templates select = "*[3]" mode = "semantics"/>
2663         </m:munder>
2664         <xsl:apply-templates select = "*[4]" mode = "semantics"/>
2665       </xsl:when>
2666     </xsl:choose>
2667   </m:mrow>
2668 </xsl:template>
2669
2670 <xsl:template match = "m:apply[m:limit[1]]">
2671   <m:mrow>
2672     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2673       <xsl:attribute name="m:xref">
2674         <xsl:value-of select="@id"/>
2675       </xsl:attribute>
2676     </xsl:if>
2677     <m:munder>
2678       <m:mo>
2679 <!-- HELM: added -->        
2680         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2681           <xsl:attribute name="m:xref">
2682             <xsl:value-of select="m:lim/@id"/>
2683           </xsl:attribute>
2684         </xsl:if>lim</m:mo>
2685       <m:mrow>
2686         <xsl:if test="*[2]=m:bvar and *[3]=m:lowlimit">
2687             <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2688             <m:mo>&#x02192;</m:mo>
2689             <xsl:apply-templates select = "*[3]" mode = "semantics"/>
2690         </xsl:if>
2691         <xsl:if test="*[2]=m:bvar and *[3]=m:condition">
2692           <xsl:apply-templates select = "*[3]" mode = "semantics"/>
2693         </xsl:if>
2694       </m:mrow>
2695     </m:munder>
2696     <xsl:apply-templates select = "*[4]" mode = "semantics"/>
2697   </m:mrow>
2698 </xsl:template>
2699
2700
2701 <!-- ***************** TRIGONOMETRY ***************** -->
2702
2703 <xsl:template match = "m:apply[*[1][self::m:sin | self::m:cos |
2704                        self::m:tan | self::m:sec | self::m:csc |
2705                        self::m:cot | self::m:sinh | self::m:cosh |
2706                        self::m:tanh | self::m:sech | self::m:csch |
2707                        self::m:coth | self::m:arcsin | self::m:arccos |
2708                        self::m:arctan]]">
2709   <m:mrow>
2710     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2711       <xsl:attribute name="m:xref">
2712         <xsl:value-of select="@id"/>
2713       </xsl:attribute>
2714     </xsl:if>
2715     <xsl:if test="not(parent::m:apply[m:power[1]])">
2716       <xsl:apply-templates select = "*[1]" mode = "trigonometry"/>
2717     </xsl:if>
2718     <xsl:if test="parent::m:apply[m:power[1]]">
2719       <m:msup>
2720         <xsl:apply-templates select = "*[1]" mode = "trigonometry"/>
2721         <xsl:apply-templates select = "../*[3]" mode = "semantics"/>
2722       </m:msup>
2723     </xsl:if>
2724     <m:mo>&#x02061;</m:mo>
2725     <xsl:apply-templates select = "*[2]" mode = "semantics">
2726       <xsl:with-param name="IN_PREC" select="$FUNCTION_PREC"/>
2727       <xsl:with-param name="PAR_NO_IGNORE" select="$NO"/>
2728     </xsl:apply-templates>
2729   </m:mrow>
2730 </xsl:template>
2731
2732 <xsl:template match = "*" mode="trigonometry">
2733   <m:mo>
2734     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2735       <xsl:attribute name="m:xref">
2736         <xsl:value-of select="@id"/>
2737       </xsl:attribute>
2738     </xsl:if>
2739     <xsl:choose>
2740       <xsl:when test="self::m:sin">
2741         <xsl:value-of select="'sin'"/>
2742       </xsl:when>
2743       <xsl:when test="self::m:cos">
2744         <xsl:value-of select="'cos'"/>
2745       </xsl:when>
2746       <xsl:when test="self::m:tan">
2747         <xsl:value-of select="'tan'"/>
2748       </xsl:when>
2749       <xsl:when test="self::m:sec">
2750         <xsl:value-of select="'sec'"/>
2751       </xsl:when>
2752       <xsl:when test="self::m:csc">
2753         <xsl:value-of select="'csc'"/>
2754       </xsl:when>
2755       <xsl:when test="self::m:cot">
2756         <xsl:value-of select="'cot'"/>
2757       </xsl:when>
2758       <xsl:when test="self::m:sinh">
2759         <xsl:value-of select="'sinh'"/>
2760       </xsl:when>
2761       <xsl:when test="self::m:cosh">
2762         <xsl:value-of select="'cosh'"/>
2763       </xsl:when>
2764       <xsl:when test="self::m:tanh">
2765         <xsl:value-of select="'tanh'"/>
2766       </xsl:when>
2767       <xsl:when test="self::m:sech">
2768         <xsl:value-of select="'sech'"/>
2769       </xsl:when>
2770       <xsl:when test="self::m:csch">
2771         <xsl:value-of select="'csch'"/>
2772       </xsl:when>
2773       <xsl:when test="self::m:coth">
2774         <xsl:value-of select="'coth'"/>
2775       </xsl:when>
2776       <xsl:when test="self::m:arcsin">
2777         <xsl:value-of select="'arcsin'"/>
2778       </xsl:when>
2779       <xsl:when test="self::m:arccos">
2780         <xsl:value-of select="'arccos'"/>
2781       </xsl:when>
2782       <xsl:when test="self::m:arctan">
2783         <xsl:value-of select="'arctan'"/>
2784       </xsl:when>
2785     </xsl:choose>
2786   </m:mo>
2787 </xsl:template>
2788
2789
2790 <!-- ***************** STATISTICS ***************** -->
2791
2792 <xsl:template match = "m:apply[m:mean[1]]">
2793   <m:mfenced open="&lt;" close="&gt;" separators=",">
2794     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2795       <xsl:attribute name="m:xref">
2796         <xsl:value-of select="@id"/>
2797       </xsl:attribute>
2798     </xsl:if>
2799     <xsl:for-each select = "*[position()>1]">
2800       <xsl:apply-templates select = "." mode="semantics"/>
2801     </xsl:for-each>
2802   </m:mfenced>
2803 </xsl:template>
2804
2805 <xsl:template match = "m:apply[m:sdev[1]]">
2806   <m:mrow>
2807     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2808       <xsl:attribute name="m:xref">
2809         <xsl:value-of select="@id"/>
2810       </xsl:attribute>
2811     </xsl:if>
2812     <m:mo>
2813 <!-- HELM: added -->        
2814         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2815           <xsl:attribute name="m:xref">
2816             <xsl:value-of select="m:sdev/@id"/>
2817           </xsl:attribute>
2818         </xsl:if>&#x003C3;</m:mo>
2819     <m:mfenced separators=",">
2820       <xsl:for-each select = "*[position()>1]">
2821         <xsl:apply-templates select = "." mode="semantics"/>
2822       </xsl:for-each>
2823     </m:mfenced>
2824   </m:mrow>
2825 </xsl:template>
2826
2827 <xsl:template match = "m:apply[m:variance[1]]">
2828   <m:mrow>
2829     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2830       <xsl:attribute name="m:xref">
2831         <xsl:value-of select="@id"/>
2832       </xsl:attribute>
2833     </xsl:if>
2834     <m:mo>
2835 <!-- HELM: added -->        
2836         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2837           <xsl:attribute name="m:xref">
2838             <xsl:value-of select="m:variance/@id"/>
2839           </xsl:attribute>
2840         </xsl:if>&#x003C3;</m:mo>
2841     <m:msup>
2842       <m:mfenced separators=",">
2843         <xsl:for-each select = "*[position()>1]">
2844           <xsl:apply-templates select = "." mode="semantics"/>
2845         </xsl:for-each>
2846       </m:mfenced>
2847       <m:mn>2</m:mn>
2848     </m:msup>
2849   </m:mrow>
2850 </xsl:template>
2851
2852 <xsl:template match = "m:apply[m:median[1]]">
2853   <m:mrow>
2854     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2855       <xsl:attribute name="m:xref">
2856         <xsl:value-of select="@id"/>
2857       </xsl:attribute>
2858     </xsl:if>
2859     <m:mo>
2860 <!-- HELM: added -->        
2861         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2862           <xsl:attribute name="m:xref">
2863             <xsl:value-of select="m:median/@id"/>
2864           </xsl:attribute>
2865         </xsl:if>median</m:mo>
2866     <m:mfenced separators=",">
2867       <xsl:for-each select = "*[position()>1]">
2868         <xsl:apply-templates select = "." mode="semantics"/>
2869       </xsl:for-each>
2870     </m:mfenced>
2871   </m:mrow>
2872 </xsl:template>
2873
2874 <xsl:template match = "m:apply[m:mode[1]]">
2875   <m:mrow>
2876     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2877       <xsl:attribute name="m:xref">
2878         <xsl:value-of select="@id"/>
2879       </xsl:attribute>
2880     </xsl:if>
2881     <m:mo>
2882 <!-- HELM: added -->        
2883         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2884           <xsl:attribute name="m:xref">
2885             <xsl:value-of select="m:mode/@id"/>
2886           </xsl:attribute>
2887         </xsl:if>mode</m:mo>
2888     <m:mfenced separators=",">
2889       <xsl:for-each select = "*[position()>1]">
2890         <xsl:apply-templates select = "." mode="semantics"/>
2891       </xsl:for-each>
2892     </m:mfenced>
2893   </m:mrow>
2894 </xsl:template>
2895
2896 <xsl:template match = "m:apply[m:moment[1]]">
2897   <m:mfenced open="&lt;" close="&gt;" separators="">
2898     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2899       <xsl:attribute name="m:xref">
2900         <xsl:value-of select="@id"/>
2901       </xsl:attribute>
2902     </xsl:if>
2903     <xsl:if test="*[2]=m:degree">
2904       <m:msup>
2905         <xsl:apply-templates select="*[3]" mode = "semantics"/>
2906         <xsl:apply-templates select="*[2]" mode = "semantics"/>
2907       </m:msup>
2908     </xsl:if>
2909     <xsl:if test="not(*[2]=m:degree)">
2910       <xsl:for-each select = "*[position()>1]">
2911         <xsl:apply-templates select = "." mode="semantics"/>
2912       </xsl:for-each>
2913     </xsl:if>
2914   </m:mfenced>
2915 </xsl:template>
2916
2917
2918 <!-- ***************** LINEAR ALGEBRA ***************** -->
2919
2920 <xsl:template match="m:vector">
2921   <m:mfenced separators="">
2922     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2923       <xsl:attribute name="m:xref">
2924         <xsl:value-of select="@id"/>
2925       </xsl:attribute>
2926     </xsl:if>
2927     <m:mtable>
2928       <xsl:for-each select="*">
2929         <m:mtd>
2930           <xsl:apply-templates select="." mode = "semantics"/>
2931         </m:mtd>
2932       </xsl:for-each>
2933     </m:mtable>
2934   </m:mfenced>
2935 </xsl:template>
2936
2937 <xsl:template match = "m:matrix">
2938   <m:mfenced separators="">
2939     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2940       <xsl:attribute name="m:xref">
2941         <xsl:value-of select="@id"/>
2942       </xsl:attribute>
2943     </xsl:if>
2944     <m:mtable>
2945       <xsl:apply-templates select="*" mode = "semantics"/>
2946     </m:mtable>
2947   </m:mfenced>
2948 </xsl:template>
2949
2950 <xsl:template match = "m:matrixrow">
2951   <m:mtr>
2952     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2953       <xsl:attribute name="m:xref">
2954         <xsl:value-of select="@id"/>
2955       </xsl:attribute>
2956     </xsl:if>
2957     <xsl:for-each select="*">
2958       <m:mtd>
2959         <xsl:apply-templates select="." mode = "semantics"/>
2960       </m:mtd>
2961     </xsl:for-each>
2962   </m:mtr>
2963 </xsl:template>
2964
2965 <xsl:template match = "m:apply[m:determinant[1]]">
2966   <m:mrow>
2967     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2968       <xsl:attribute name="m:xref">
2969         <xsl:value-of select="@id"/>
2970       </xsl:attribute>
2971     </xsl:if>
2972     <m:mo>
2973 <!-- HELM: added -->        
2974         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2975           <xsl:attribute name="m:xref">
2976             <xsl:value-of select="m:determinant/@id"/>
2977           </xsl:attribute>
2978         </xsl:if>det</m:mo>
2979     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2980   </m:mrow>
2981 </xsl:template>
2982
2983 <xsl:template match = "m:apply[m:transpose[1]]">
2984   <m:msup>
2985     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2986       <xsl:attribute name="m:xref">
2987         <xsl:value-of select="@id"/>
2988       </xsl:attribute>
2989     </xsl:if>
2990     <xsl:apply-templates select = "*[2]" mode = "semantics"/>
2991     <m:mo>
2992 <!-- HELM: added -->        
2993         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
2994           <xsl:attribute name="m:xref">
2995             <xsl:value-of select="m:transpose/@id"/>
2996           </xsl:attribute>
2997         </xsl:if>T</m:mo>
2998   </m:msup>
2999 </xsl:template>
3000
3001 <xsl:template match = "m:apply[m:selector[1]]">
3002   <xsl:if test="*[2]=m:matrix and *[3]=m:cn">
3003       <xsl:variable name="m" select = "*[3]"/>
3004       <xsl:choose>
3005         <xsl:when test="*[4]=m:cn">
3006           <xsl:variable name="n" select = "*[4]"/>
3007           <xsl:copy-of select = "m:matrix/*[position()=$m]/*[position()=$n]"/>
3008         </xsl:when>
3009         <xsl:otherwise>
3010           <xsl:copy-of select = "m:matrix/*[position()=$m]"/>
3011         </xsl:otherwise>
3012       </xsl:choose>
3013   </xsl:if>
3014   <xsl:if test="(*[2]=m:vector or *[2]=m:list) and *[3]=m:cn">
3015     <xsl:variable name="m" select = "*[3]"/>
3016     <xsl:copy-of select = "*[2]/*[position()=$m]"/>
3017   </xsl:if>
3018 </xsl:template>
3019
3020 <xsl:template match = "m:apply[m:vectorproduct[1] |
3021                                  m:scalarproduct[1] | m:outerproduct[1]]">
3022   <m:mrow>
3023     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
3024       <xsl:attribute name="m:xref">
3025         <xsl:value-of select="@id"/>
3026       </xsl:attribute>
3027     </xsl:if>
3028     <xsl:apply-templates select="*[2]" mode = "semantics"/>
3029     <m:mo>
3030       <xsl:if test="m:vectorproduct[1]">
3031 <!-- HELM: added -->        
3032         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
3033           <xsl:attribute name="m:xref">
3034             <xsl:value-of select="m:vectorproduct/@id"/>
3035           </xsl:attribute>
3036         </xsl:if>
3037         &#x02A2F;
3038       </xsl:if>
3039       <xsl:if test="m:scalarproduct[1] | m:outerproduct[1]">
3040 <!-- HELM: added -->        
3041         <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
3042           <xsl:attribute name="m:xref">
3043             <xsl:value-of select="*[1]/@id"/>
3044           </xsl:attribute>
3045         </xsl:if>
3046         <xsl:value-of select="'.'"/>
3047       </xsl:if>
3048     </m:mo>
3049     <xsl:apply-templates select="*[3]" mode = "semantics"/>
3050   </m:mrow>
3051 </xsl:template>
3052
3053 </xsl:stylesheet>