]> matita.cs.unibo.it Git - helm.git/blob - helm/style/content.xsl
Modified Files:
[helm.git] / helm / style / content.xsl
1 <?xml version="1.0"?>
2
3 <!-- Copyright (C) 2000, HELM Team                                     -->
4 <!--                                                                   -->
5 <!-- This file is part of HELM, an Hypertextual, Electronic            -->
6 <!-- Library of Mathematics, developed at the Computer Science         -->
7 <!-- Department, University of Bologna, Italy.                         -->
8 <!--                                                                   -->
9 <!-- HELM is free software; you can redistribute it and/or             -->
10 <!-- modify it under the terms of the GNU General Public License       -->
11 <!-- as published by the Free Software Foundation; either version 2    -->
12 <!-- of the License, or (at your option) any later version.            -->
13 <!--                                                                   -->
14 <!-- HELM is distributed in the hope that it will be useful,           -->
15 <!-- but WITHOUT ANY WARRANTY; without even the implied warranty of    -->
16 <!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     -->
17 <!-- GNU General Public License for more details.                      -->
18 <!--                                                                   -->
19 <!-- You should have received a copy of the GNU General Public License -->
20 <!-- along with HELM; if not, write to the Free Software               -->
21 <!-- Foundation, Inc., 59 Temple Place - Suite 330, Boston,            -->
22 <!-- MA  02111-1307, USA.                                              -->
23 <!--                                                                   -->
24 <!-- For details, see the HELM World-Wide-Web page,                    -->
25 <!-- http://cs.unibo.it/helm/.                                         -->
26
27 <!--******************************************************************--> 
28 <!-- XSLT version 0.1 of CIC objects to MathML content:               -->
29 <!-- First draft: February 14 2000, Andrea Asperti, Irene Schena      -->
30 <!-- Revised: March 3 2000, Irene Schena                              -->
31 <!-- Revised: March 10 2000, Irene Schena                             -->
32 <!-- Revised: March 15 2000, Claudio Sacerdoti Coen, Irene Schena     -->
33 <!--******************************************************************-->
34
35 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
36                               xmlns:m="http://www.w3.org/1998/Math/MathML"
37                               xmlns:helm="http://www.cs.unibo.it/helm">
38
39 <xsl:include href="params.xsl"/>
40
41 <!--<xsl:output
42            method="xml" 
43            version="1.0" 
44            encoding="ISO-8859-1" 
45            omit-xml-declaration="no"
46            standalone="no" 
47            doctype-public="http://www.w3.org/TR/REC-MathML" 
48            indent="yes"
49            media-type="text/mathml" /> -->
50
51 <!-- DA FARE: 
52 1)risolvere nella fase di pre-processing le uri relative delle var, settando 
53 l'attributo
54 definitionURL dell'oggetto corrispondente (alcuni punteranno a nulla! -quelli 
55 che non hanno il file di definizione corrispondente-); [le uri assolute hanno
56 la forma cic:/.../ in definitionURL e questo schema di uri verra' risolto da
57 Amaya o da chi di dovere in /really_very_local/helm/PARSER/example/.../]
58 -->
59
60
61 <!-- CIC TERMS -->
62
63 <xsl:template match="LAMBDA" mode="pure">
64     <m:lambda helm:xref="{@id}">
65      <m:bvar>
66       <m:ci>
67        <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="target/@binder"/></xsl:with-param></xsl:call-template>
68       </m:ci>
69       <m:type>
70        <xsl:apply-templates select="source/*[1]" mode="noannot"/>
71       </m:type>
72      </m:bvar>
73      <xsl:apply-templates select="target/*[1]" mode="noannot"/>
74     </m:lambda>
75 </xsl:template>
76
77 <xsl:template match="LETIN" mode="pure">
78     <m:apply helm:xref="{@id}">
79      <m:csymbol>let_in</m:csymbol>
80      <m:bvar>
81       <m:ci>
82        <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="letintarget/@binder"/></xsl:with-param></xsl:call-template>
83       </m:ci>
84      </m:bvar>
85      <xsl:apply-templates select="*[1]" mode="noannot"/>
86      <xsl:apply-templates select="letintarget/*[1]" mode="noannot"/>
87     </m:apply>
88 </xsl:template>
89
90 <xsl:template match="PROD" mode="pure">
91     <m:apply helm:xref="{@id}">
92      <xsl:choose>
93      <xsl:when test="string(target/@binder)= &quot;&quot;">
94       <m:csymbol>arrow</m:csymbol>
95       <xsl:apply-templates select="source/*[1]" mode="noannot"/>
96      </xsl:when>
97      <xsl:otherwise>
98       <xsl:choose>
99        <xsl:when test="@type = 'Prop'">
100         <m:csymbol>forall</m:csymbol>
101        </xsl:when>
102        <xsl:otherwise>
103         <m:csymbol>prod</m:csymbol>
104        </xsl:otherwise>
105       </xsl:choose>
106        <m:bvar>
107         <m:ci>
108          <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="target/@binder"/></xsl:with-param></xsl:call-template>
109         </m:ci>
110         <m:type>
111          <xsl:apply-templates select="source/*[1]" mode="noannot"/>
112         </m:type>
113        </m:bvar>
114      </xsl:otherwise>
115      </xsl:choose>
116      <xsl:apply-templates select="target/*[1]" mode="noannot"/>
117     </m:apply>
118 </xsl:template>
119
120 <xsl:template match="CAST" mode="pure">
121     <m:apply helm:xref="{@id}">
122      <m:csymbol>cast</m:csymbol>
123      <xsl:apply-templates mode="noannot" select="*/*"/>
124     </m:apply>
125 </xsl:template>
126
127 <xsl:template match="REL" mode="pure">
128     <m:ci helm:xref="{@id}">
129      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="@binder"/></xsl:with-param></xsl:call-template>
130     </m:ci>
131 </xsl:template>
132
133 <xsl:template match="SORT" mode="pure">
134     <m:apply helm:xref="{@id}">
135      <m:csymbol>
136       <xsl:value-of select="@value"/>
137      </m:csymbol>
138     </m:apply>
139 </xsl:template>
140
141 <xsl:template match="APPLY" mode="pure">
142    <xsl:choose>
143     <!-- <xsl:when test="//InnerTypes and boolean(key('typeid',*/@id))"> -->
144     <!-- start looking for subproofs -->
145     <!-- <xsl:when test="((*/@id) = (//InnerTypes/TYPE/@of))"> -->
146     <xsl:when test="//InnerTypes and count(*[@sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX')]) > 0">
147      <m:apply helm:xref="{@id}">
148       <m:csymbol>letin</m:csymbol>
149       <!-- <xsl:for-each select="*[boolean(key('typeid',@id))]"> -->
150       <!-- first process all subproofs (let-in) -->
151       <xsl:for-each select="*[@sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX')]">
152        <m:apply>
153         <m:csymbol>let</m:csymbol>
154         <m:ci><xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="concat('h',position())"/></xsl:with-param></xsl:call-template></m:ci>
155         <xsl:apply-templates mode="noannot" select="."/>
156        </m:apply>
157       </xsl:for-each>
158       <!-- now re-process the application in mode appflat -->
159       <xsl:apply-templates mode="appflat" select="."/> 
160      </m:apply>
161     </xsl:when>
162     <xsl:otherwise>
163      <xsl:apply-templates mode="appflat" select="."/>
164     </xsl:otherwise>
165    </xsl:choose>
166 </xsl:template>
167
168 <xsl:template match="APPLY" mode="appflat">
169       <m:apply helm:xref="{@id}">
170        <m:csymbol>app</m:csymbol>
171        <!-- mode flat looks for siblings: call with the first child -->
172        <xsl:apply-templates mode="flat" select="*[1]"/>
173       </m:apply>
174 </xsl:template>
175
176 <xsl:template match="*" mode="flat">
177  <xsl:param name="n" select="1"/>
178  <xsl:variable name="id" select="@id"/>
179  <xsl:choose>
180   <!-- <xsl:when test="key('typeid',@id)"> -->
181   <!-- <xsl:when test="//InnerTypes/TYPE[@of=$id]"> -->
182   <xsl:when test="//InnerTypes and @sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX')">
183    <m:ci>
184     <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="concat('h',$n)"/></xsl:with-param></xsl:call-template>
185    </m:ci>
186    <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
187     <xsl:with-param name="n" select="$n+1"/>
188    </xsl:apply-templates>
189   </xsl:when>
190   <xsl:otherwise>
191    <xsl:apply-templates mode="pure" select="."/>
192    <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
193     <xsl:with-param name="n" select="$n"/>
194    </xsl:apply-templates>
195   </xsl:otherwise>
196  </xsl:choose>
197 </xsl:template>
198
199 <xsl:template match="VAR" mode="pure">
200     <m:ci helm:xref="{@id}">
201      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="substring-after(@relUri,&quot;,&quot;)"/></xsl:with-param></xsl:call-template>
202     </m:ci>
203 </xsl:template>
204
205 <xsl:template match="META" mode="pure">
206     <m:ci helm:xref="{@id}">
207      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="@no"/></xsl:with-param></xsl:call-template>
208     </m:ci>
209 </xsl:template>
210
211 <xsl:template match="CONST" mode="pure">
212     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
213      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:call-template name="name_of_uri">
214       <xsl:with-param name="uri" select="@uri"/>
215      </xsl:call-template></xsl:with-param></xsl:call-template>
216      <!-- <xsl:value-of select="document(concat(string($absPath),@uri))/*/@name"/> -->
217     </m:ci>
218 </xsl:template>
219
220 <xsl:template match="MUTIND" mode="pure">
221     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
222      <xsl:variable name="index"><xsl:value-of select="@noType"/></xsl:variable>
223      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="document(concat(string($absPath),@uri))/InductiveDefinition/InductiveType[position()=number($index)+1]/@name"/></xsl:with-param></xsl:call-template>
224     </m:ci>
225 </xsl:template>
226
227 <xsl:template match="MUTCONSTRUCT" mode="pure">
228     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
229      <xsl:variable name="Tindex"><xsl:value-of select="@noType"/></xsl:variable>
230      <xsl:variable name="Cindex"><xsl:value-of select="@noConstr"/></xsl:variable>
231      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="document(concat(string($absPath),@uri))/InductiveDefinition/InductiveType[position()=number($Tindex)+1]/Constructor[position()=number($Cindex)]/@name"/></xsl:with-param></xsl:call-template>
232     </m:ci>
233 </xsl:template>
234
235 <xsl:template match="MUTCASE" mode="pure">
236     <xsl:variable name="Tindex"><xsl:value-of select="@noType"/></xsl:variable>
237     <xsl:variable name="Turi"><xsl:value-of select="@uriType"/></xsl:variable>
238     <m:apply helm:xref="{@id}">
239      <m:csymbol>mutcase</m:csymbol>
240      <xsl:apply-templates select="patternsType/*[1]" mode="noannot"/>
241      <xsl:apply-templates select="inductiveTerm/*[1]" mode="noannot"/>
242      <xsl:variable name="nop"><xsl:value-of select="document(concat(string($absPath),$Turi))/InductiveDefinition/@noParams"/></xsl:variable>
243      <xsl:for-each select="pattern">
244       <xsl:variable name="pos" select="position()"/>
245       <xsl:variable name="nopar"><xsl:apply-templates select="document(concat(string($absPath),$Turi))/InductiveDefinition/InductiveType[position()=number($Tindex)+1]/Constructor[position()=number($pos)]/*[1]" mode="counting"><xsl:with-param name="noparams" select="$nop"/></xsl:apply-templates></xsl:variable>
246       <xsl:choose>
247       <xsl:when test="$nopar = 0">
248        <m:ci>
249         <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="document(concat(string($absPath),$Turi))/InductiveDefinition/InductiveType[position()=number($Tindex)+1]/Constructor[position()=number($pos)]/@name"/></xsl:with-param></xsl:call-template>
250        </m:ci>
251       </xsl:when>
252       <xsl:otherwise>
253        <m:apply>
254         <m:csymbol>app</m:csymbol>
255         <m:ci>
256          <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="document(concat(string($absPath),$Turi))/InductiveDefinition/InductiveType[position()=number($Tindex)+1]/Constructor[position()=number($pos)]/@name"/></xsl:with-param></xsl:call-template>
257         </m:ci>
258         <xsl:apply-templates select="./*[1]" mode="abstparams"><xsl:with-param name="noparams" select="$nopar"/><xsl:with-param name="binder">LAMBDA</xsl:with-param></xsl:apply-templates>
259         </m:apply>
260        </xsl:otherwise>
261        </xsl:choose>
262       <xsl:apply-templates select="./*[1]" mode="abstparams"><xsl:with-param name="noparams" select="$nopar"/><xsl:with-param name="target" select="1"/><xsl:with-param name="binder">LAMBDA</xsl:with-param></xsl:apply-templates>
263      </xsl:for-each> 
264     </m:apply>
265 </xsl:template>
266
267 <xsl:template match="FIX" mode="pure">
268     <m:apply helm:xref="{@id}">
269      <xsl:variable name="findex"><xsl:value-of select="@noFun"/></xsl:variable>
270      <m:csymbol>fix</m:csymbol>
271      <m:ci><xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="FixFunction[position()=number($findex)+1]/@name"/></xsl:with-param></xsl:call-template></m:ci>
272      <xsl:apply-templates mode="pure" select="*"/>
273     </m:apply>
274 </xsl:template>
275
276 <xsl:template match="COFIX" mode="pure">
277    <m:apply helm:xref="{@id}">
278      <xsl:variable name="findex"><xsl:value-of select="@noFun"/></xsl:variable>
279      <m:csymbol>cofix</m:csymbol>
280      <m:ci><xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="CofixFunction[position()=number($findex)+1]/@name"/></xsl:with-param></xsl:call-template></m:ci>
281      <xsl:apply-templates mode="pure" select="*"/>
282     </m:apply>
283 </xsl:template>
284
285 <!-- ELEMENTS OF CIC TERMS -->
286
287 <xsl:template match="FixFunction" mode="pure">
288     <m:bvar>
289      <m:ci><xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="@name"/></xsl:with-param></xsl:call-template></m:ci>
290      <m:type><xsl:apply-templates select="type/*[1]" mode="noannot"/></m:type>
291     </m:bvar> 
292     <xsl:apply-templates select="body/*[1]" mode="noannot"/>
293 </xsl:template>
294
295 <xsl:template match="CofixFunction" mode="pure">
296     <m:bvar>
297      <m:ci><xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="@name"/></xsl:with-param></xsl:call-template></m:ci>
298      <m:type><xsl:apply-templates select="type/*[1]" mode="noannot"/></m:type>
299     </m:bvar> 
300     <xsl:apply-templates select="body/*[1]" mode="noannot"/>
301 </xsl:template>
302
303 </xsl:stylesheet>
304
305
306
307
308