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