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