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