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