3 <!--***********************************************************************-->
4 <!-- Extension to the XSLT version 0.07 of MathML content to presentation: -->
5 <!-- First draft: February 19 2000, Andrea Asperti, Irene Schena -->
6 <!-- Revised: March 3 2000, Irene Schena -->
7 <!-- Revised: March 15 2000, Claudio Sacerdoti Coen, Irene Schena -->
8 <!-- Revised: March 21 2000, Irene Schena -->
9 <!--***********************************************************************-->
11 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
12 xmlns:m="http://www.w3.org/1998/Math/MathML"
13 xmlns:helm="http://www.cs.unibo.it/helm">
15 <xsl:import href="mml2mmlv1_0.xsl"/>
17 <!--***********************************************************************-->
18 <!-- Parameter affecting line-breaking -->
19 <!--***********************************************************************-->
21 <xsl:variable name="framewidth" select="15"/>
23 <!--***********************************************************************-->
24 <!-- Gli oggetti sono stampati come mtext all'interno di una marca toplevel-->
25 <!-- math ma al di fuori di semantics. Ora vi sono tanti semantics quanti -->
26 <!-- sono i termini: la presentation per un termine e' generata come primo -->
27 <!-- figlio di un semantics e l'originario content viene inserito nel -->
28 <!-- nel secondo figlio di semantics, annotation-xml -->
29 <!--***********************************************************************-->
31 <!--**********************-->
33 <!--**********************-->
35 <xsl:template match="/">
36 <xsl:processing-instruction name="cocoon-format">type="text/xhtml"</xsl:processing-instruction>
37 <xsl:apply-templates select="*"/>
42 <xsl:template match="Definition">
44 <m:mtable align="baseline 1" equalrows="false" columnalign="left" helm:xref="{@helm:xref}">
48 <m:mtext>DEFINITION <xsl:value-of select="@name"/>(<xsl:if test="string(./Params) != """><xsl:value-of select="Params"/></xsl:if>) OF TYPE</m:mtext>
55 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
56 <xsl:apply-templates select="type/*[1]"/>
70 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
71 <xsl:apply-templates select="body/*[1]"/>
81 <xsl:template match="Axiom">
83 <m:mtable align="baseline 1" equalrows="false" columnalign="left" helm:xref="{@helm:xref}">
87 <m:mtext>AXIOM <xsl:value-of select="@name"/>(<xsl:if test="string(./Params) != """><xsl:value-of select="Params"/></xsl:if>) OF TYPE</m:mtext>
94 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
95 <xsl:apply-templates select="type/*[1]"/>
103 <!-- UNFINISHED PROOF -->
105 <xsl:template match="CurrentProof">
107 <m:mtable align="baseline 1" equalrows="false" columnalign="left" helm:xref="{@helm:xref}">
111 <m:mtext>UNFINISHED PROOF <xsl:value-of select="@name"/>(<xsl:if test="string(./Params) != """><xsl:value-of select="Params"/></xsl:if>)</m:mtext>
118 <m:mtext>THESIS:</m:mtext>
125 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
126 <xsl:apply-templates select="type/*[1]"/>
133 <m:mtext>CONJECTURES:</m:mtext>
137 <xsl:for-each select="Conjecture">
141 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
142 <m:mtext><xsl:value-of select="./@no"/>:</m:mtext>
143 <xsl:apply-templates select="./*[1]"/>
151 <m:mtext>CORRESPONDING PROOF:</m:mtext>
158 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
159 <xsl:apply-templates select="body/*[1]"/>
167 <!-- MUTUAL INDUCTIVE DEFINITION -->
169 <xsl:template match="InductiveDefinition">
171 <m:mtable align="baseline 1" equalrows="false" columnalign="left" helm:xref="{@helm:xref}">
172 <xsl:for-each select="InductiveType">
177 <xsl:when test="position() = 1">
179 <xsl:when test="string(./@inductive) = "true"">
180 <m:mtext>INDUCTIVE DEFINITION</m:mtext>
183 <m:mtext>COINDUCTIVE DEFINITION</m:mtext>
188 <m:mtext>AND</m:mtext>
191 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
192 <m:mtext><xsl:value-of select="./@name"/>(<xsl:if test="string(../Params) != """><xsl:value-of select="../Params"/></xsl:if>)</m:mtext>
199 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
202 <xsl:when test="string(../Param) != """>
203 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
204 <xsl:for-each select="../Param">
208 <m:mi><xsl:value-of select="./@name"/></m:mi>
210 <xsl:apply-templates select="*"/>
234 <m:mtext>OF ARITY</m:mtext>
241 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
242 <xsl:apply-templates select="./arity/*[1]"/>
249 <m:mtext>BUILT FROM</m:mtext>
253 <xsl:for-each select="./Constructor">
258 <xsl:when test="position() = 1">
259 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
263 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
266 <m:mtext><xsl:value-of select="./@name"/> OF</m:mtext>
267 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
268 <xsl:apply-templates select="./*[1]"/>
280 <xsl:template match="Variable">
282 <m:mtable align="baseline 1" equalrows="false" columnalign="left" helm:xref="{@helm:xref}">
286 <m:mtext>VARIABLE <xsl:value-of select="@name"/> OF TYPE</m:mtext>
293 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
294 <xsl:apply-templates select="type/*[1]"/>
302 <!--**********************-->
304 <!--**********************-->
306 <xsl:template match="m:bvar">
308 <xsl:when test="m:type">
309 <xsl:variable name="charlength">
310 <xsl:apply-templates select="m:ci" mode="charcount"/>
313 <xsl:when test="$charlength >= $framewidth">
314 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
317 <xsl:apply-templates select="m:ci"/>
323 <xsl:apply-templates select="m:type"/>
329 <xsl:apply-templates select="m:ci"/>
331 <xsl:apply-templates select="m:type"/>
336 <xsl:apply-templates select="m:ci"/>
344 <xsl:template match="m:apply[m:csymbol]">
345 <xsl:variable name="name"><xsl:value-of select="m:csymbol"/></xsl:variable>
346 <xsl:variable name="charlength"><xsl:apply-templates select="m:csymbol" mode="charcount"/></xsl:variable>
348 <xsl:if test="@helm:xref">
349 <xsl:attribute name="helm:xref"><xsl:value-of select="@helm:xref"/></xsl:attribute>
352 <xsl:when test="$name='prod'">
354 <xsl:when test="$charlength >= $framewidth">
355 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
358 <m:mo color="Blue">Π</m:mo>
359 <xsl:apply-templates select="m:bvar"/>
366 <xsl:apply-templates select="*[position()=3]"/>
373 <m:mo color="Blue">Π</m:mo>
374 <xsl:apply-templates select="m:bvar/m:ci"/>
376 <xsl:apply-templates select="m:bvar/m:type"/>
378 <xsl:apply-templates select="*[position()=3]"/>
382 <xsl:when test="$name='arrow'">
384 <xsl:when test="$charlength >= $framewidth">
385 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
389 <m:mo stretchy="false">(</m:mo>
390 <xsl:apply-templates select="*[position()=2]"/>
397 <m:mo color="Blue">→</m:mo>
398 <xsl:apply-templates select="*[position()=3]"/>
405 <m:mo stretchy="false">)</m:mo>
412 <m:mo stretchy="false">(</m:mo>
413 <xsl:apply-templates select="*[position()=2]"/>
414 <m:mo color="Blue">→</m:mo>
415 <xsl:apply-templates select="*[position()=3]"/>
416 <m:mo stretchy="false">)</m:mo>
420 <xsl:when test="$name='app'">
422 <xsl:when test="$charlength >= $framewidth">
423 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
427 <m:mo stretchy="false">(</m:mo>
428 <xsl:apply-templates select="*[position()=2]"/>
432 <xsl:for-each select="*[position()>2]">
436 <m:mphantom><m:mtext>(</m:mtext></m:mphantom>
437 <xsl:apply-templates select="."/>
445 <m:mo stretchy="false">)</m:mo>
452 <m:mo stretchy="false">(</m:mo>
453 <xsl:apply-templates select="*[position()=2]"/>
454 <xsl:for-each select="*[position()>2]">
455 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
456 <xsl:apply-templates select="."/>
458 <m:mo stretchy="false">)</m:mo>
462 <xsl:when test="$name='cast'">
464 <xsl:when test="$charlength >= $framewidth">
465 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
469 <m:mo stretchy="false">(</m:mo>
470 <xsl:apply-templates select="*[position()=2]"/>
477 <m:mo color="#b03060">:></m:mo>
478 <xsl:apply-templates select="*[position()=3]"/>
485 <m:mo stretchy="false">)</m:mo>
492 <m:mo stretchy="false">(</m:mo>
493 <xsl:apply-templates select="*[position()=2]"/>
494 <m:mo color="#b03060">:></m:mo>
495 <xsl:apply-templates select="*[position()=3]"/>
496 <m:mo stretchy="false">)</m:mo>
500 <xsl:when test="$name='Prop'">
503 <xsl:when test="$name='Set'">
506 <xsl:when test="$name='Type'">
509 <xsl:when test="$name='mutcase'">
511 <xsl:when test="$charlength >= $framewidth">
512 <xsl:variable name="charlength"><xsl:apply-templates select="*[position()=2]" mode="charcount"><xsl:with-param name="nosibling" select="1"/></xsl:apply-templates></xsl:variable>
513 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
518 <xsl:apply-templates select="*[position()=2]"/>
519 <xsl:if test="$framewidth > $charlength">
522 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
523 <xsl:apply-templates select="*[position()=3]"/>
528 <xsl:if test="$charlength >= $framewidth">
534 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
535 <xsl:apply-templates select="*[position()=3]"/>
547 <xsl:for-each select="*[position() mod 2 = 0 and position()>3]">
548 <xsl:variable name="charlength"><xsl:apply-templates select="." mode="charcount"><xsl:with-param name="nosibling" select="1"/></xsl:apply-templates></xsl:variable>
553 <xsl:when test="position() = 1">
554 <m:mphantom><m:mtext>|</m:mtext></m:mphantom>
557 <m:mo stretchy="false">|</m:mo>
560 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
561 <xsl:apply-templates select="."/>
562 <xsl:if test="$framewidth > $charlength">
563 <m:mo color="Green">⇒</m:mo>
564 <xsl:apply-templates select="following-sibling::*[position()= 1]"/>
569 <xsl:if test="$charlength >= $framewidth">
573 <m:mphantom><m:mtext>|_</m:mtext></m:mphantom>
574 <m:mo color="Green">⇒</m:mo>
575 <xsl:apply-templates select="following-sibling::*[position()= 1]"/>
591 <m:mo><</m:mo><xsl:apply-templates select="*[position()=2]"/><m:mo>></m:mo>
593 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
594 <xsl:apply-templates select="*[position()=3]"/>
595 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
597 <xsl:for-each select="*[position() mod 2 = 0 and position()>3]">
599 <xsl:when test="position() != 1">
600 <m:mo stretchy="false">|</m:mo>
603 <xsl:apply-templates select="."/>
604 <m:mo color="Green">⇒</m:mo>
605 <xsl:apply-templates select="following-sibling::*[position()= 1]"/>
607 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
612 <xsl:when test="$name='fix'">
614 <xsl:when test="$charlength >= $framewidth">
615 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
620 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
621 <m:mi><xsl:value-of select="m:ci"/></m:mi>
622 <m:mo stretchy="false">{</m:mo>
629 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
630 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
631 <xsl:for-each select="m:bvar">
632 <xsl:variable name="charlength"><xsl:apply-templates select="m:type" mode="charcount"><xsl:with-param name="nosibling" select="1"/></xsl:apply-templates></xsl:variable>
636 <m:mi><xsl:value-of select="m:ci"/></m:mi>
638 <xsl:if test="$framewidth > $charlength">
639 <xsl:apply-templates select="m:type"/>
644 <xsl:if test="$charlength >= $framewidth">
648 <m:mphantom><m:mtext>:=</m:mtext></m:mphantom>
649 <xsl:apply-templates select="m:type"/>
658 <xsl:apply-templates select="following-sibling::*[position()=1]"/>
670 <m:mo stretchy="false">}</m:mo>
678 <m:mi><xsl:value-of select="m:ci"/></m:mi>
679 <m:mo stretchy="false">{</m:mo>
680 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
681 <xsl:for-each select="m:bvar">
685 <m:mi><xsl:value-of select="m:ci"/></m:mi>
687 <xsl:apply-templates select="m:type"/>
689 <xsl:apply-templates select="following-sibling::*[position() = 1]"/>
690 <xsl:if test="position()=last()">
691 <m:mo stretchy="false">}</m:mo>
701 <xsl:when test="$name='cofix'">
703 <xsl:when test="$charlength >= $framewidth">
704 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
709 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
710 <m:mi><xsl:value-of select="m:ci"/></m:mi>
711 <m:mo stretchy="false">{</m:mo>
718 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
719 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
720 <xsl:for-each select="m:bvar">
721 <xsl:variable name="charlength"><xsl:apply-templates select="m:type" mode="charcount"><xsl:with-param name="nosibling" select="1"/></xsl:apply-templates></xsl:variable>
725 <m:mi><xsl:value-of select="m:ci"/></m:mi>
727 <xsl:if test="$framewidth > $charlength">
728 <xsl:apply-templates select="m:type"/>
733 <xsl:if test="$charlength >= $framewidth">
737 <m:mphantom><m:mtext>:=</m:mtext></m:mphantom>
738 <xsl:apply-templates select="m:type"/>
747 <xsl:apply-templates select="following-sibling::*[position() = 1]"/>
759 <m:mo stretchy="false">}</m:mo>
767 <m:mi><xsl:value-of select="m:ci"/></m:mi>
768 <m:mo stretchy="false">{</m:mo>
769 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
770 <xsl:for-each select="m:bvar">
774 <m:mi><xsl:value-of select="m:ci"/></m:mi>
776 <xsl:apply-templates select="m:type"/>
778 <xsl:apply-templates select="following-sibling::*[position() = 1]"/>
779 <xsl:if test="position()=last()">
780 <m:mo stretchy="false">}</m:mo>
796 <xsl:template match="m:lambda">
797 <xsl:variable name="charlength"><xsl:apply-templates select="*[position()=1]" mode="charcount"/></xsl:variable>
798 <m:mrow helm:xref="{@helm:xref}">
800 <xsl:when test="$charlength >= $framewidth">
801 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
804 <m:mo color="Blue">λ</m:mo>
805 <xsl:apply-templates select="m:bvar"/>
812 <xsl:apply-templates select="*[position()=2]"/>
819 <m:mo color="Red">λ</m:mo>
820 <xsl:apply-templates select="m:bvar/m:ci"/>
822 <xsl:apply-templates select="m:bvar/m:type"/>
824 <xsl:apply-templates select="*[position()=2]"/>
830 <!-- *********************************** -->
831 <!-- BASE SET OF MATHML CONTENT ELEMENTS -->
832 <!-- *********************************** -->
836 <xsl:template match = "m:apply[m:and[1]|m:or[1]
837 |m:geq[1]|m:leq[1]|m:gt[1]|m:lt[1]|m:eq[1]
838 |m:intesect[1]|m:union[1]|m:subset[1]|m:prsubset]">
839 <xsl:variable name="symbol">
841 <xsl:when test="m:and[1]">
842 <xsl:value-of select="'wedge'"/>
844 <xsl:when test="m:or[1]">
845 <xsl:value-of select="'vee'"/>
847 <xsl:when test="m:geq[1]">
848 <xsl:value-of select="'geq'"/>
850 <xsl:when test="m:leq[1]">
851 <xsl:value-of select="'leq'"/>
853 <xsl:when test="m:gt[1]">
854 <xsl:value-of select="'gt'"/>
856 <xsl:when test="m:lt[1]">
857 <xsl:value-of select="'lt'"/>
859 <xsl:when test="m:eq[1]">
860 <xsl:value-of select="'eq'"/>
862 <xsl:when test="m:subset[1]">
863 <xsl:value-of select="'SubsetEqual'"/>
865 <xsl:when test="m:prsubset[1]">
866 <xsl:value-of select="'subset'"/>
868 <xsl:when test="m:intersect[1]">
869 <xsl:value-of select="'Intersection'"/>
871 <xsl:when test="m:union[1]">
872 <xsl:value-of select="'Union'"/>
876 <xsl:variable name="charlength">
877 <xsl:apply-templates select="*[1]" mode="charcount"/>
880 <xsl:when test="$charlength >= $framewidth">
881 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
884 <m:mo stretchy="false">(</m:mo>
885 <xsl:apply-templates select="*[position()=2]"/>
888 <xsl:for-each select = "*[position()>2]">
892 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
894 <m:mchar name="{$symbol}"/>
896 <xsl:apply-templates select="."/>
903 <m:mo stretchy="false">)</m:mo>
914 <xsl:template match = "m:set">
915 <xsl:variable name="charlength">
916 <xsl:apply-templates select="." mode="charcount"/>
919 <xsl:when test="$charlength >= $framewidth">
921 <xsl:when test="name(*[1]) = 'm:bvar'">
922 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
925 <m:mo stretchy="false">{</m:mo>
926 <xsl:apply-templates select="m:bvar"/>
931 <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
933 <xsl:apply-templates select="m:condition"/>
938 <m:mo stretchy="false">}</m:mo>
944 <m:mtable align="baseline 1" equalrows="false" columnalign="left">
947 <m:mo stretchy="false">{</m:mo>
948 <xsl:apply-templates select="*[1]"/>
949 <xsl:if test="count(child::*) != 1">
954 <xsl:for-each select = "*[position()>1]">
957 <m:mphantom><m:mtext>_</m:mtext></m:mphantom>
958 <xsl:apply-templates select="."/>
959 <xsl:if test="position() != last()">
967 <m:mo stretchy="false">}</m:mo>
980 <!--**********************-->
982 <!--**********************-->
984 <xsl:template match="m:and|m:or|m:not|m:exists|m:eq|m:lt|m:leq|m:gt|m:geq
985 |m:in|m:notin|m:intersect|m:union|m:subset|m:prsubset|m:card|m:setdiff" mode="charcount">
986 <xsl:param name="incurrent_length" select="0"/>
988 <xsl:when test="$framewidth > ($incurrent_length + 3 + string-length())">
989 <xsl:variable name="siblength">
990 <xsl:apply-templates select="following-sibling::*[position()=1]" mode="charcount">
991 <xsl:with-param name="incurrent_length" select="$incurrent_length + string-length()"/>
992 </xsl:apply-templates>
995 <xsl:when test="string($siblength) = """>
996 <xsl:value-of select="$incurrent_length + 3 + string-length()"/>
999 <xsl:value-of select="number($siblength)"/>
1004 <xsl:value-of select="$incurrent_length + 3 + string-length()"/>
1009 <xsl:template match="m:ci|m:csymbol" mode="charcount">
1010 <xsl:param name="incurrent_length" select="0"/>
1011 <xsl:param name="nosibling" select="0"/>
1013 <xsl:when test="$framewidth > ($incurrent_length + string-length()) and ($nosibling = 0)">
1014 <xsl:variable name="siblength"><xsl:apply-templates select="following-sibling::*[position()=1]" mode="charcount"><xsl:with-param name="incurrent_length" select="$incurrent_length + string-length()"/></xsl:apply-templates></xsl:variable>
1016 <xsl:when test="string($siblength) = """>
1017 <xsl:value-of select="$incurrent_length + string-length()"/>
1020 <xsl:value-of select="number($siblength)"/>
1025 <xsl:value-of select="$incurrent_length + string-length()"/>
1030 <xsl:template match="*" mode="charcount">
1031 <xsl:param name="incurrent_length" select="0"/>
1032 <xsl:param name="nosibling" select="0"/>
1033 <xsl:variable name="childlength"><xsl:apply-templates select="*[position()=1]" mode="charcount"><xsl:with-param name="incurrent_length" select="$incurrent_length"/><xsl:with-param name="nosibling" select="0"/></xsl:apply-templates></xsl:variable>
1035 <xsl:when test="$framewidth > number($childlength) and ($nosibling = 0)">
1036 <xsl:variable name="siblength"><xsl:apply-templates select="following-sibling::*[position()=1]" mode="charcount"><xsl:with-param name="incurrent_length" select="$childlength"/></xsl:apply-templates></xsl:variable>
1038 <xsl:when test="string($siblength) = """>
1039 <xsl:value-of select="number($childlength)"/>
1042 <xsl:value-of select="number($siblength)"/>
1047 <xsl:value-of select="number($childlength)"/>