]> matita.cs.unibo.it Git - helm.git/blob - helm/style/content.xsl
7d211d2f7e7c1758efb3d2d3a3d902db04bd76a2
[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/get?url=</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       <!--<m:msqrt>
49        <m:mi>-->
50         <xsl:value-of select="target/@binder"/>
51       <!-- </m:mi>
52        </m:msqrt>-->
53       </m:ci>
54       <m:type>
55        <xsl:apply-templates select="source/*[1]" mode="noannot"/>
56       </m:type>
57      </m:bvar>
58      <xsl:apply-templates select="target/*[1]" mode="noannot"/>
59     </m:lambda>
60 </xsl:template>
61
62 <xsl:template match="PROD" mode="pure">
63     <m:apply helm:xref="{@id}">
64      <xsl:choose>
65      <xsl:when test="string(target/@binder)= &quot;&quot;">
66       <m:csymbol>arrow</m:csymbol>
67       <xsl:apply-templates select="source/*[1]" mode="noannot"/>
68      </xsl:when>
69      <xsl:otherwise>
70       <m:csymbol>prod</m:csymbol>
71        <m:bvar>
72         <m:ci>
73          <xsl:value-of select="target/@binder"/>
74         </m:ci>
75         <m:type>
76          <xsl:apply-templates select="source/*[1]" mode="noannot"/>
77         </m:type>
78        </m:bvar>
79      </xsl:otherwise>
80      </xsl:choose>
81      <xsl:apply-templates select="target/*[1]" mode="noannot"/>
82     </m:apply>
83 </xsl:template>
84
85 <xsl:template match="CAST" mode="pure">
86     <m:apply helm:xref="{@id}">
87      <m:csymbol>cast</m:csymbol>
88      <xsl:apply-templates mode="noannot" select="*/*"/>
89     </m:apply>
90 </xsl:template>
91
92 <xsl:template match="REL" mode="pure">
93     <m:ci helm:xref="{@id}">
94      <xsl:value-of select="@binder"/>
95     </m:ci>
96 </xsl:template>
97
98 <xsl:template match="SORT" mode="pure">
99     <m:apply helm:xref="{@id}">
100      <m:csymbol>
101       <xsl:value-of select="@value"/>
102      </m:csymbol>
103     </m:apply>
104 </xsl:template>
105
106 <xsl:template match="APPLY" mode="pure">
107    <xsl:choose>
108     <!-- <xsl:when test="//ALLTYPES and boolean(key('typeid',*/@id))"> -->
109     <!-- start looking for subproofs -->
110     <xsl:when test="((*/@id) = (//ALLTYPES/TYPE/@id))"> 
111      <m:apply helm:xref="{@id}">
112       <m:csymbol>letin</m:csymbol>
113       <!-- <xsl:for-each select="*[boolean(key('typeid',@id))]"> -->
114       <!-- first process all subproofs (let-in) -->
115       <xsl:for-each select="*[@id = (//ALLTYPES/TYPE/@id)]">
116        <m:apply>
117         <m:csymbol>let</m:csymbol>
118         <m:ci><xsl:value-of select="concat('h',position())"/></m:ci>
119         <xsl:apply-templates mode="noannot" select="."/>
120        </m:apply>
121       </xsl:for-each>
122       <!-- now re-process the application in mode appflat -->
123       <xsl:apply-templates mode="appflat" select="."/> 
124      </m:apply>
125     </xsl:when>
126     <xsl:otherwise>
127      <xsl:apply-templates mode="appflat" select="."/>
128     </xsl:otherwise>
129    </xsl:choose>
130 </xsl:template>
131
132 <xsl:template match="APPLY" mode="appflat">
133       <m:apply helm:xref="{@id}">
134        <m:csymbol>app</m:csymbol>
135        <!-- mode flat looks for siblings: call with the first child -->
136        <xsl:apply-templates mode="flat" select="*[1]"/>
137       </m:apply>
138 </xsl:template>
139
140 <xsl:template match="*" mode="flat">
141  <xsl:param name="n" select="1"/>
142  <xsl:choose>
143   <xsl:when test="@id">
144    <xsl:variable name="id" select="@id"/>
145    <xsl:choose>
146     <!-- <xsl:when test="key('typeid',@id)"> -->
147     <xsl:when test="//ALLTYPES/TYPE[@id=$id]">
148      <m:ci>
149       <xsl:value-of select="concat('h',$n)"/>
150      </m:ci>
151      <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
152       <xsl:with-param name="n" select="$n+1"/>
153      </xsl:apply-templates>
154     </xsl:when>
155     <xsl:otherwise>
156      <xsl:apply-templates mode="pure" select="."/>
157      <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
158       <xsl:with-param name="n" select="$n"/>
159      </xsl:apply-templates>
160     </xsl:otherwise>
161    </xsl:choose>
162   </xsl:when>
163   <xsl:otherwise>
164    <xsl:apply-templates mode="pure" select="."/>
165    <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
166     <xsl:with-param name="n" select="$n"/>
167    </xsl:apply-templates>
168   </xsl:otherwise>
169  </xsl:choose>
170 </xsl:template>
171
172 <xsl:template match="VAR" mode="pure">
173     <m:ci helm:xref="{@id}">
174      <xsl:value-of select="substring-after(@relUri,&quot;,&quot;)"/>
175     </m:ci>
176 </xsl:template>
177
178 <xsl:template match="META" mode="pure">
179     <m:ci helm:xref="{@id}">
180      <xsl:value-of select="@no"/>
181     </m:ci>
182 </xsl:template>
183
184 <xsl:template match="CONST" mode="pure">
185     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
186      <xsl:call-template name="name_of_uri">
187       <xsl:with-param name="uri" select="@uri"/>
188      </xsl:call-template>
189      <!-- <xsl:value-of select="document(concat(string($absPath),@uri))/*/@name"/> -->
190     </m:ci>
191 </xsl:template>
192
193 <xsl:template match="MUTIND" mode="pure">
194     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
195      <xsl:variable name="index"><xsl:value-of select="@noType"/></xsl:variable>
196      <xsl:value-of select="document(concat(string($absPath),@uri))/InductiveDefinition/InductiveType[position()=number($index)+1]/@name"/>
197     </m:ci>
198 </xsl:template>
199
200 <xsl:template match="MUTCONSTRUCT" mode="pure">
201     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
202      <xsl:variable name="Tindex"><xsl:value-of select="@noType"/></xsl:variable>
203      <xsl:variable name="Cindex"><xsl:value-of select="@noConstr"/></xsl:variable>
204      <xsl:value-of select="document(concat(string($absPath),@uri))/InductiveDefinition/InductiveType[position()=number($Tindex)+1]/Constructor[position()=number($Cindex)]/@name"/>
205     </m:ci>
206 </xsl:template>
207
208 <xsl:template match="MUTCASE" mode="pure">
209     <xsl:variable name="Tindex"><xsl:value-of select="@noType"/></xsl:variable>
210     <xsl:variable name="Turi"><xsl:value-of select="@uriType"/></xsl:variable>
211     <m:apply helm:xref="{@id}">
212      <m:csymbol>mutcase</m:csymbol>
213      <xsl:apply-templates select="patternsType/*[1]" mode="noannot"/>
214      <xsl:apply-templates select="inductiveTerm/*[1]" mode="noannot"/>
215      <xsl:variable name="nop"><xsl:value-of select="document(concat(string($absPath),$Turi))/InductiveDefinition/@noParams"/></xsl:variable>
216      <xsl:for-each select="pattern">
217       <xsl:variable name="pos" select="position()"/>
218       <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>
219       <xsl:choose>
220       <xsl:when test="$nopar = 0">
221        <m:ci>
222         <xsl:value-of select="document(concat(string($absPath),$Turi))/InductiveDefinition/InductiveType[position()=number($Tindex)+1]/Constructor[position()=number($pos)]/@name"/>
223        </m:ci>
224       </xsl:when>
225       <xsl:otherwise>
226        <m:apply>
227         <m:csymbol>app</m:csymbol>
228         <m:ci>
229          <xsl:value-of select="document(concat(string($absPath),$Turi))/InductiveDefinition/InductiveType[position()=number($Tindex)+1]/Constructor[position()=number($pos)]/@name"/>
230         </m:ci>
231         <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>
232         </m:apply>
233        </xsl:otherwise>
234        </xsl:choose>
235       <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>
236      </xsl:for-each> 
237     </m:apply>
238 </xsl:template>
239
240 <xsl:template match="FIX" mode="pure">
241     <m:apply helm:xref="{@id}">
242      <xsl:variable name="findex"><xsl:value-of select="@noFun"/></xsl:variable>
243      <m:csymbol>fix</m:csymbol>
244      <m:ci><xsl:value-of select="FixFunction[position()=number($findex)+1]/@name"/></m:ci>
245      <xsl:apply-templates mode="pure" select="*"/>
246     </m:apply>
247 </xsl:template>
248
249 <xsl:template match="COFIX" mode="pure">
250    <m:apply helm:xref="{@id}">
251      <xsl:variable name="findex"><xsl:value-of select="@noFun"/></xsl:variable>
252      <m:csymbol>cofix</m:csymbol>
253      <m:ci><xsl:value-of select="CofixFunction[position()=number($findex)+1]/@name"/></m:ci>
254      <xsl:apply-templates mode="pure" select="*"/>
255     </m:apply>
256 </xsl:template>
257
258 <!-- ELEMENTS OF CIC TERMS -->
259
260 <xsl:template match="FixFunction" mode="pure">
261     <m:bvar>
262      <m:ci><xsl:value-of select="@name"/></m:ci>
263      <m:type><xsl:apply-templates select="type/*[1]" mode="noannot"/></m:type>
264     </m:bvar> 
265     <xsl:apply-templates select="body/*[1]" mode="noannot"/>
266 </xsl:template>
267
268 <xsl:template match="CofixFunction" mode="pure">
269     <m:bvar>
270      <m:ci><xsl:value-of select="@name"/></m:ci>
271      <m:type><xsl:apply-templates select="type/*[1]" mode="noannot"/></m:type>
272     </m:bvar> 
273     <xsl:apply-templates select="body/*[1]" mode="noannot"/>
274 </xsl:template>
275
276 </xsl:stylesheet>