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