]> matita.cs.unibo.it Git - helm.git/blob - helm/style/content.xsl
forall csymbol added
[helm.git] / helm / style / content.xsl
1 <?xml version="1.0"?>
2
3 <!--******************************************************************--> 
4 <!-- XSLT version 0.1 of CIC objects to MathML content:               -->
5 <!-- First draft: February 14 2000, Andrea Asperti, Irene Schena      -->
6 <!-- Revised: March 3 2000, Irene Schena                              -->
7 <!-- Revised: March 10 2000, Irene Schena                             -->
8 <!-- Revised: March 15 2000, Claudio Sacerdoti Coen, Irene Schena     -->
9 <!--******************************************************************-->
10
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">
14
15 <xsl:include href="params.xsl"/>
16
17 <!--<xsl:output
18            method="xml" 
19            version="1.0" 
20            encoding="ISO-8859-1" 
21            omit-xml-declaration="no"
22            standalone="no" 
23            doctype-public="http://www.w3.org/TR/REC-MathML" 
24            indent="yes"
25            media-type="text/mathml" /> -->
26
27 <!-- DA FARE: 
28 1)risolvere nella fase di pre-processing le uri relative delle var, settando 
29 l'attributo
30 definitionURL dell'oggetto corrispondente (alcuni punteranno a nulla! -quelli 
31 che non hanno il file di definizione corrispondente-); [le uri assolute hanno
32 la forma cic:/.../ in definitionURL e questo schema di uri verra' risolto da
33 Amaya o da chi di dovere in /really_very_local/helm/PARSER/example/.../]
34 -->
35
36 <!--******************************************************************-->
37 <!-- Variable containing the absolute path of the CIC file            -->
38 <!--******************************************************************-->
39
40 <xsl:variable name="absPath">http://localhost:8081/getciconly?uri=</xsl:variable>
41
42 <!-- CIC TERMS -->
43
44 <xsl:template match="LAMBDA" mode="pure">
45     <m:lambda helm:xref="{@id}">
46      <m:bvar>
47       <m:ci>
48        <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="target/@binder"/></xsl:with-param></xsl:call-template>
49       </m:ci>
50       <m:type>
51        <xsl:apply-templates select="source/*[1]" mode="noannot"/>
52       </m:type>
53      </m:bvar>
54      <xsl:apply-templates select="target/*[1]" mode="noannot"/>
55     </m:lambda>
56 </xsl:template>
57
58 <xsl:template match="PROD" mode="pure">
59     <m:apply helm:xref="{@id}">
60      <xsl:choose>
61      <xsl:when test="string(target/@binder)= &quot;&quot;">
62       <m:csymbol>arrow</m:csymbol>
63       <xsl:apply-templates select="source/*[1]" mode="noannot"/>
64      </xsl:when>
65      <xsl:otherwise>
66       <xsl:choose>
67        <xsl:when test="@type = 'Prop'">
68         <m:csymbol>forall</m:csymbol>
69        </xsl:when>
70        <xsl:otherwise>
71         <m:csymbol>prod</m:csymbol>
72        </xsl:otherwise>
73       </xsl:choose>
74        <m:bvar>
75         <m:ci>
76          <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="target/@binder"/></xsl:with-param></xsl:call-template>
77         </m:ci>
78         <m:type>
79          <xsl:apply-templates select="source/*[1]" mode="noannot"/>
80         </m:type>
81        </m:bvar>
82      </xsl:otherwise>
83      </xsl:choose>
84      <xsl:apply-templates select="target/*[1]" mode="noannot"/>
85     </m:apply>
86 </xsl:template>
87
88 <xsl:template match="CAST" mode="pure">
89     <m:apply helm:xref="{@id}">
90      <m:csymbol>cast</m:csymbol>
91      <xsl:apply-templates mode="noannot" select="*/*"/>
92     </m:apply>
93 </xsl:template>
94
95 <xsl:template match="REL" mode="pure">
96     <m:ci helm:xref="{@id}">
97      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="@binder"/></xsl:with-param></xsl:call-template>
98     </m:ci>
99 </xsl:template>
100
101 <xsl:template match="SORT" mode="pure">
102     <m:apply helm:xref="{@id}">
103      <m:csymbol>
104       <xsl:value-of select="@value"/>
105      </m:csymbol>
106     </m:apply>
107 </xsl:template>
108
109 <xsl:template match="APPLY" mode="pure">
110    <xsl:choose>
111     <!-- <xsl:when test="//InnerTypes and boolean(key('typeid',*/@id))"> -->
112     <!-- start looking for subproofs -->
113     <xsl:when test="((*/@id) = (//InnerTypes/TYPE/@of))"> 
114      <m:apply helm:xref="{@id}">
115       <m:csymbol>letin</m:csymbol>
116       <!-- <xsl:for-each select="*[boolean(key('typeid',@id))]"> -->
117       <!-- first process all subproofs (let-in) -->
118       <xsl:for-each select="*[@id = (//InnerTypes/TYPE/@of)]">
119        <m:apply>
120         <m:csymbol>let</m:csymbol>
121         <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>
122         <xsl:apply-templates mode="noannot" select="."/>
123        </m:apply>
124       </xsl:for-each>
125       <!-- now re-process the application in mode appflat -->
126       <xsl:apply-templates mode="appflat" select="."/> 
127      </m:apply>
128     </xsl:when>
129     <xsl:otherwise>
130      <xsl:apply-templates mode="appflat" select="."/>
131     </xsl:otherwise>
132    </xsl:choose>
133 </xsl:template>
134
135 <xsl:template match="APPLY" mode="appflat">
136       <m:apply helm:xref="{@id}">
137        <m:csymbol>app</m:csymbol>
138        <!-- mode flat looks for siblings: call with the first child -->
139        <xsl:apply-templates mode="flat" select="*[1]"/>
140       </m:apply>
141 </xsl:template>
142
143 <xsl:template match="*" mode="flat">
144  <xsl:param name="n" select="1"/>
145  <xsl:choose>
146   <xsl:when test="@id">
147    <xsl:variable name="id" select="@id"/>
148    <xsl:choose>
149     <!-- <xsl:when test="key('typeid',@id)"> -->
150     <xsl:when test="//InnerTypes/TYPE[@of=$id]">
151      <m:ci>
152       <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>
153      </m:ci>
154      <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
155       <xsl:with-param name="n" select="$n+1"/>
156      </xsl:apply-templates>
157     </xsl:when>
158     <xsl:otherwise>
159      <xsl:apply-templates mode="pure" select="."/>
160      <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
161       <xsl:with-param name="n" select="$n"/>
162      </xsl:apply-templates>
163     </xsl:otherwise>
164    </xsl:choose>
165   </xsl:when>
166   <xsl:otherwise>
167    <xsl:apply-templates mode="pure" select="."/>
168    <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
169     <xsl:with-param name="n" select="$n"/>
170    </xsl:apply-templates>
171   </xsl:otherwise>
172  </xsl:choose>
173 </xsl:template>
174
175 <xsl:template match="VAR" mode="pure">
176     <m:ci helm:xref="{@id}">
177      <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>
178     </m:ci>
179 </xsl:template>
180
181 <xsl:template match="META" mode="pure">
182     <m:ci helm:xref="{@id}">
183      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="@no"/></xsl:with-param></xsl:call-template>
184     </m:ci>
185 </xsl:template>
186
187 <xsl:template match="CONST" mode="pure">
188     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
189      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:call-template name="name_of_uri">
190       <xsl:with-param name="uri" select="@uri"/>
191      </xsl:call-template></xsl:with-param></xsl:call-template>
192      <!-- <xsl:value-of select="document(concat(string($absPath),@uri))/*/@name"/> -->
193     </m:ci>
194 </xsl:template>
195
196 <xsl:template match="MUTIND" mode="pure">
197     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
198      <xsl:variable name="index"><xsl:value-of select="@noType"/></xsl:variable>
199      <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>
200     </m:ci>
201 </xsl:template>
202
203 <xsl:template match="MUTCONSTRUCT" mode="pure">
204     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
205      <xsl:variable name="Tindex"><xsl:value-of select="@noType"/></xsl:variable>
206      <xsl:variable name="Cindex"><xsl:value-of select="@noConstr"/></xsl:variable>
207      <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>
208     </m:ci>
209 </xsl:template>
210
211 <xsl:template match="MUTCASE" mode="pure">
212     <xsl:variable name="Tindex"><xsl:value-of select="@noType"/></xsl:variable>
213     <xsl:variable name="Turi"><xsl:value-of select="@uriType"/></xsl:variable>
214     <m:apply helm:xref="{@id}">
215      <m:csymbol>mutcase</m:csymbol>
216      <xsl:apply-templates select="patternsType/*[1]" mode="noannot"/>
217      <xsl:apply-templates select="inductiveTerm/*[1]" mode="noannot"/>
218      <xsl:variable name="nop"><xsl:value-of select="document(concat(string($absPath),$Turi))/InductiveDefinition/@noParams"/></xsl:variable>
219      <xsl:for-each select="pattern">
220       <xsl:variable name="pos" select="position()"/>
221       <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>
222       <xsl:choose>
223       <xsl:when test="$nopar = 0">
224        <m:ci>
225         <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>
226        </m:ci>
227       </xsl:when>
228       <xsl:otherwise>
229        <m:apply>
230         <m:csymbol>app</m:csymbol>
231         <m:ci>
232          <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>
233         </m:ci>
234         <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>
235         </m:apply>
236        </xsl:otherwise>
237        </xsl:choose>
238       <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>
239      </xsl:for-each> 
240     </m:apply>
241 </xsl:template>
242
243 <xsl:template match="FIX" mode="pure">
244     <m:apply helm:xref="{@id}">
245      <xsl:variable name="findex"><xsl:value-of select="@noFun"/></xsl:variable>
246      <m:csymbol>fix</m:csymbol>
247      <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>
248      <xsl:apply-templates mode="pure" select="*"/>
249     </m:apply>
250 </xsl:template>
251
252 <xsl:template match="COFIX" mode="pure">
253    <m:apply helm:xref="{@id}">
254      <xsl:variable name="findex"><xsl:value-of select="@noFun"/></xsl:variable>
255      <m:csymbol>cofix</m:csymbol>
256      <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>
257      <xsl:apply-templates mode="pure" select="*"/>
258     </m:apply>
259 </xsl:template>
260
261 <!-- ELEMENTS OF CIC TERMS -->
262
263 <xsl:template match="FixFunction" mode="pure">
264     <m:bvar>
265      <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>
266      <m:type><xsl:apply-templates select="type/*[1]" mode="noannot"/></m:type>
267     </m:bvar> 
268     <xsl:apply-templates select="body/*[1]" mode="noannot"/>
269 </xsl:template>
270
271 <xsl:template match="CofixFunction" mode="pure">
272     <m:bvar>
273      <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>
274      <m:type><xsl:apply-templates select="type/*[1]" mode="noannot"/></m:type>
275     </m:bvar> 
276     <xsl:apply-templates select="body/*[1]" mode="noannot"/>
277 </xsl:template>
278
279 </xsl:stylesheet>
280
281
282
283
284