]> matita.cs.unibo.it Git - helm.git/blob - helm/style/content.xsl
Modified Files:
[helm.git] / helm / style / content.xsl
1 <?xml version="1.0"?>
2
3 <!-- Copyright (C) 2000, HELM Team                                     -->
4 <!--                                                                   -->
5 <!-- This file is part of HELM, an Hypertextual, Electronic            -->
6 <!-- Library of Mathematics, developed at the Computer Science         -->
7 <!-- Department, University of Bologna, Italy.                         -->
8 <!--                                                                   -->
9 <!-- HELM is free software; you can redistribute it and/or             -->
10 <!-- modify it under the terms of the GNU General Public License       -->
11 <!-- as published by the Free Software Foundation; either version 2    -->
12 <!-- of the License, or (at your option) any later version.            -->
13 <!--                                                                   -->
14 <!-- HELM is distributed in the hope that it will be useful,           -->
15 <!-- but WITHOUT ANY WARRANTY; without even the implied warranty of    -->
16 <!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     -->
17 <!-- GNU General Public License for more details.                      -->
18 <!--                                                                   -->
19 <!-- You should have received a copy of the GNU General Public License -->
20 <!-- along with HELM; if not, write to the Free Software               -->
21 <!-- Foundation, Inc., 59 Temple Place - Suite 330, Boston,            -->
22 <!-- MA  02111-1307, USA.                                              -->
23 <!--                                                                   -->
24 <!-- For details, see the HELM World-Wide-Web page,                    -->
25 <!-- http://cs.unibo.it/helm/.                                         -->
26
27 <!--******************************************************************--> 
28 <!-- XSLT version 0.1 of CIC objects to MathML content:               -->
29 <!-- First draft: February 14 2000, Andrea Asperti, Irene Schena      -->
30 <!-- Revised: March 3 2000, Irene Schena                              -->
31 <!-- Revised: March 10 2000, Irene Schena                             -->
32 <!-- Revised: March 15 2000, Claudio Sacerdoti Coen, Irene Schena     -->
33 <!--******************************************************************-->
34
35 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
36                               xmlns:m="http://www.w3.org/1998/Math/MathML"
37                               xmlns:helm="http://www.cs.unibo.it/helm">
38
39 <xsl:include href="params.xsl"/>
40
41 <!--<xsl:output
42            method="xml" 
43            version="1.0" 
44            encoding="ISO-8859-1" 
45            omit-xml-declaration="no"
46            standalone="no" 
47            doctype-public="http://www.w3.org/TR/REC-MathML" 
48            indent="yes"
49            media-type="text/mathml" /> -->
50
51 <!-- DA FARE: 
52 1)risolvere nella fase di pre-processing le uri relative delle var, settando 
53 l'attributo
54 definitionURL dell'oggetto corrispondente (alcuni punteranno a nulla! -quelli 
55 che non hanno il file di definizione corrispondente-); [le uri assolute hanno
56 la forma cic:/.../ in definitionURL e questo schema di uri verra' risolto da
57 Amaya o da chi di dovere in /really_very_local/helm/PARSER/example/.../]
58 -->
59
60 <!--******************************************************************-->
61 <!-- Variable containing the absolute path of the CIC file            -->
62 <!--******************************************************************-->
63
64 <xsl:variable name="absPath">http://localhost:8081/getciconly?uri=</xsl:variable>
65
66 <!-- CIC TERMS -->
67
68 <xsl:template match="LAMBDA" mode="pure">
69     <m:lambda helm:xref="{@id}">
70      <m:bvar>
71       <m:ci>
72        <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="target/@binder"/></xsl:with-param></xsl:call-template>
73       </m:ci>
74       <m:type>
75        <xsl:apply-templates select="source/*[1]" mode="noannot"/>
76       </m:type>
77      </m:bvar>
78      <xsl:apply-templates select="target/*[1]" mode="noannot"/>
79     </m:lambda>
80 </xsl:template>
81
82 <xsl:template match="LETIN" mode="pure">
83     <m:apply helm:xref="{@id}">
84      <m:csymbol>letin</m:csymbol>
85      <m:bvar>
86       <m:ci>
87        <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="letintarget/@binder"/></xsl:with-param></xsl:call-template>
88       </m:ci>
89      </m:bvar>
90      <xsl:apply-templates select="*[1]" mode="noannot"/>
91      <xsl:apply-templates select="letintarget/*[1]" mode="noannot"/>
92     </m:apply>
93 </xsl:template>
94
95 <xsl:template match="PROD" mode="pure">
96     <m:apply helm:xref="{@id}">
97      <xsl:choose>
98      <xsl:when test="string(target/@binder)= &quot;&quot;">
99       <m:csymbol>arrow</m:csymbol>
100       <xsl:apply-templates select="source/*[1]" mode="noannot"/>
101      </xsl:when>
102      <xsl:otherwise>
103       <xsl:choose>
104        <xsl:when test="@type = 'Prop'">
105         <m:csymbol>forall</m:csymbol>
106        </xsl:when>
107        <xsl:otherwise>
108         <m:csymbol>prod</m:csymbol>
109        </xsl:otherwise>
110       </xsl:choose>
111        <m:bvar>
112         <m:ci>
113          <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="target/@binder"/></xsl:with-param></xsl:call-template>
114         </m:ci>
115         <m:type>
116          <xsl:apply-templates select="source/*[1]" mode="noannot"/>
117         </m:type>
118        </m:bvar>
119      </xsl:otherwise>
120      </xsl:choose>
121      <xsl:apply-templates select="target/*[1]" mode="noannot"/>
122     </m:apply>
123 </xsl:template>
124
125 <xsl:template match="CAST" mode="pure">
126     <m:apply helm:xref="{@id}">
127      <m:csymbol>cast</m:csymbol>
128      <xsl:apply-templates mode="noannot" select="*/*"/>
129     </m:apply>
130 </xsl:template>
131
132 <xsl:template match="REL" mode="pure">
133     <m:ci helm:xref="{@id}">
134      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="@binder"/></xsl:with-param></xsl:call-template>
135     </m:ci>
136 </xsl:template>
137
138 <xsl:template match="SORT" mode="pure">
139     <m:apply helm:xref="{@id}">
140      <m:csymbol>
141       <xsl:value-of select="@value"/>
142      </m:csymbol>
143     </m:apply>
144 </xsl:template>
145
146 <xsl:template match="APPLY" mode="pure">
147    <xsl:choose>
148     <!-- <xsl:when test="//InnerTypes and boolean(key('typeid',*/@id))"> -->
149     <!-- start looking for subproofs -->
150     <!-- <xsl:when test="((*/@id) = (//InnerTypes/TYPE/@of))"> -->
151     <xsl:when test="//InnerTypes and count(*[@sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX')]) > 0">
152      <m:apply helm:xref="{@id}">
153       <m:csymbol>letin</m:csymbol>
154       <!-- <xsl:for-each select="*[boolean(key('typeid',@id))]"> -->
155       <!-- first process all subproofs (let-in) -->
156       <xsl:for-each select="*[@sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX')]">
157        <m:apply>
158         <m:csymbol>let</m:csymbol>
159         <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>
160         <xsl:apply-templates mode="noannot" select="."/>
161        </m:apply>
162       </xsl:for-each>
163       <!-- now re-process the application in mode appflat -->
164       <xsl:apply-templates mode="appflat" select="."/> 
165      </m:apply>
166     </xsl:when>
167     <xsl:otherwise>
168      <xsl:apply-templates mode="appflat" select="."/>
169     </xsl:otherwise>
170    </xsl:choose>
171 </xsl:template>
172
173 <xsl:template match="APPLY" mode="appflat">
174       <m:apply helm:xref="{@id}">
175        <m:csymbol>app</m:csymbol>
176        <!-- mode flat looks for siblings: call with the first child -->
177        <xsl:apply-templates mode="flat" select="*[1]"/>
178       </m:apply>
179 </xsl:template>
180
181 <xsl:template match="*" mode="flat">
182  <xsl:param name="n" select="1"/>
183  <xsl:variable name="id" select="@id"/>
184  <xsl:choose>
185   <!-- <xsl:when test="key('typeid',@id)"> -->
186   <!-- <xsl:when test="//InnerTypes/TYPE[@of=$id]"> -->
187   <xsl:when test="//InnerTypes and @sort='Prop' and (name(.)='LAMBDA' or name(.)='LETIN' or name(.)='APPLY' or name(.)='MUTCASE' or name(.)='FIX' or name(.)='COFIX')">
188    <m:ci>
189     <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>
190    </m:ci>
191    <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
192     <xsl:with-param name="n" select="$n+1"/>
193    </xsl:apply-templates>
194   </xsl:when>
195   <xsl:otherwise>
196    <xsl:apply-templates mode="pure" select="."/>
197    <xsl:apply-templates mode="flat" select="following-sibling::*[1]">
198     <xsl:with-param name="n" select="$n"/>
199    </xsl:apply-templates>
200   </xsl:otherwise>
201  </xsl:choose>
202 </xsl:template>
203
204 <xsl:template match="VAR" mode="pure">
205     <m:ci helm:xref="{@id}">
206      <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>
207     </m:ci>
208 </xsl:template>
209
210 <xsl:template match="META" mode="pure">
211     <m:ci helm:xref="{@id}">
212      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="@no"/></xsl:with-param></xsl:call-template>
213     </m:ci>
214 </xsl:template>
215
216 <xsl:template match="CONST" mode="pure">
217     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
218      <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:call-template name="name_of_uri">
219       <xsl:with-param name="uri" select="@uri"/>
220      </xsl:call-template></xsl:with-param></xsl:call-template>
221      <!-- <xsl:value-of select="document(concat(string($absPath),@uri))/*/@name"/> -->
222     </m:ci>
223 </xsl:template>
224
225 <xsl:template match="MUTIND" mode="pure">
226     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
227      <xsl:variable name="index"><xsl:value-of select="@noType"/></xsl:variable>
228      <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>
229     </m:ci>
230 </xsl:template>
231
232 <xsl:template match="MUTCONSTRUCT" mode="pure">
233     <m:ci definitionURL="{@uri}" helm:xref="{@id}">
234      <xsl:variable name="Tindex"><xsl:value-of select="@noType"/></xsl:variable>
235      <xsl:variable name="Cindex"><xsl:value-of select="@noConstr"/></xsl:variable>
236      <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>
237     </m:ci>
238 </xsl:template>
239
240 <xsl:template match="MUTCASE" mode="pure">
241     <xsl:variable name="Tindex"><xsl:value-of select="@noType"/></xsl:variable>
242     <xsl:variable name="Turi"><xsl:value-of select="@uriType"/></xsl:variable>
243     <m:apply helm:xref="{@id}">
244      <m:csymbol>mutcase</m:csymbol>
245      <xsl:apply-templates select="patternsType/*[1]" mode="noannot"/>
246      <xsl:apply-templates select="inductiveTerm/*[1]" mode="noannot"/>
247      <xsl:variable name="nop"><xsl:value-of select="document(concat(string($absPath),$Turi))/InductiveDefinition/@noParams"/></xsl:variable>
248      <xsl:for-each select="pattern">
249       <xsl:variable name="pos" select="position()"/>
250       <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>
251       <xsl:choose>
252       <xsl:when test="$nopar = 0">
253        <m:ci>
254         <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>
255        </m:ci>
256       </xsl:when>
257       <xsl:otherwise>
258        <m:apply>
259         <m:csymbol>app</m:csymbol>
260         <m:ci>
261          <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>
262         </m:ci>
263         <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>
264         </m:apply>
265        </xsl:otherwise>
266        </xsl:choose>
267       <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>
268      </xsl:for-each> 
269     </m:apply>
270 </xsl:template>
271
272 <xsl:template match="FIX" mode="pure">
273     <m:apply helm:xref="{@id}">
274      <xsl:variable name="findex"><xsl:value-of select="@noFun"/></xsl:variable>
275      <m:csymbol>fix</m:csymbol>
276      <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>
277      <xsl:apply-templates mode="pure" select="*"/>
278     </m:apply>
279 </xsl:template>
280
281 <xsl:template match="COFIX" mode="pure">
282    <m:apply helm:xref="{@id}">
283      <xsl:variable name="findex"><xsl:value-of select="@noFun"/></xsl:variable>
284      <m:csymbol>cofix</m:csymbol>
285      <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>
286      <xsl:apply-templates mode="pure" select="*"/>
287     </m:apply>
288 </xsl:template>
289
290 <!-- ELEMENTS OF CIC TERMS -->
291
292 <xsl:template match="FixFunction" mode="pure">
293     <m:bvar>
294      <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>
295      <m:type><xsl:apply-templates select="type/*[1]" mode="noannot"/></m:type>
296     </m:bvar> 
297     <xsl:apply-templates select="body/*[1]" mode="noannot"/>
298 </xsl:template>
299
300 <xsl:template match="CofixFunction" mode="pure">
301     <m:bvar>
302      <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>
303      <m:type><xsl:apply-templates select="type/*[1]" mode="noannot"/></m:type>
304     </m:bvar> 
305     <xsl:apply-templates select="body/*[1]" mode="noannot"/>
306 </xsl:template>
307
308 </xsl:stylesheet>
309
310
311
312
313