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