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