]> matita.cs.unibo.it Git - helm.git/blob - helm/style/objcontent.xsl
added support for compressed files
[helm.git] / helm / style / objcontent.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 objects and MathML content:   -->
29 <!-- First draft: March 21 2000, Irene Schena                         -->
30 <!--******************************************************************-->
31
32 <!--******************************************************************-->
33 <!-- MANCA: gestione annotation e linking                             -->
34 <!--******************************************************************-->
35
36 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
37                               xmlns:m="http://www.w3.org/1998/Math/MathML"
38                               xmlns:helm="http://www.cs.unibo.it/helm">
39
40 <xsl:import href="content.xsl"/>
41
42 <!-- ROOT -->
43
44 <xsl:template match="cicxml">
45     <xsl:variable name="url"><xsl:value-of select="@baseurl"/></xsl:variable>
46     <xsl:variable name="stylesheet"><xsl:value-of select="@stylesheet"/></xsl:variable>
47     <xsl:processing-instruction name="cocoon-format">type="text/xml"</xsl:processing-instruction>
48     <xsl:processing-instruction name="xml-stylesheet">href="<xsl:value-of select='concat($url,$stylesheet)'/>" type="text/xsl"</xsl:processing-instruction>
49     <xsl:processing-instruction name="cocoon-process">type="xslt"</xsl:processing-instruction>
50     <xsl:apply-templates select="*[1]"/>
51 </xsl:template>
52
53 <!-- CIC OBJECTS -->
54
55 <xsl:template match="Definition" mode="noannot">
56     <Definition name="{@name}" helm:xref="{@id}">  
57      <xsl:if test="string(@params) != &quot;&quot;">
58       <Params>
59        <xsl:value-of select="@params"/>
60       </Params>
61      </xsl:if>
62 <!--     <xsl:choose>
63       <xsl:when test="$showproof=0">
64        <body>
65         <m:mi>Here</m:mi>
66        </body>
67       </xsl:when>
68       <xsl:otherwise>
69        <body>
70         <xsl:apply-templates select="body"/>
71        </body>
72       </xsl:otherwise>
73      </xsl:choose> -->
74      <body>
75       <xsl:apply-templates select="body/*"/>
76      </body>
77      <type>
78        <xsl:apply-templates select="type/*"/>
79      </type>
80     </Definition> 
81 </xsl:template>
82
83 <xsl:template match="Axiom" mode="noannot"> 
84     <Axiom name="{@name}" helm:xref="{@id}">
85      <xsl:if test="string(@params) != &quot;&quot;">
86       <Params>
87        <xsl:value-of select="@params"/>
88       </Params>
89      </xsl:if>
90      <type>
91        <xsl:apply-templates select="type/*"/>
92      </type>
93     </Axiom> 
94 </xsl:template>
95
96 <xsl:template match="CurrentProof" mode="noannot">
97     <CurrentProof name="{@name}" helm:xref="{@id}">
98      <xsl:for-each select="Conjecture">
99       <Conjecture no="./{@no}">
100         <xsl:apply-templates select="."/>
101       </Conjecture>
102      </xsl:for-each>
103      <body>
104        <xsl:apply-templates select="body/*"/>
105      </body>
106      <type>
107        <xsl:apply-templates select="type/*"/>
108      </type>
109     </CurrentProof> 
110 </xsl:template>
111
112 <xsl:template match="InductiveDefinition" mode="noannot">
113     <InductiveDefinition helm:xref="{@id}">
114      <xsl:if test="string(@params) != &quot;&quot;">
115       <Params>
116        <xsl:value-of select="@params"/>
117       </Params>
118      </xsl:if> 
119      <xsl:if test="string(@noParams) != 0"> 
120       <xsl:apply-templates select="InductiveType/arity/*[1]" mode="abstparams">
121        <xsl:with-param name="noparams" select="@noParams"/>
122       </xsl:apply-templates>
123      </xsl:if>
124      <xsl:for-each select="InductiveType">
125       <InductiveType name="{./@name}" inductive="{./@inductive}">
126        <arity>
127          <xsl:apply-templates select="./arity/*[1]" mode="abstparams">
128           <xsl:with-param name="noparams" select="../@noParams"/>
129           <xsl:with-param name="target" select="1"/>
130          </xsl:apply-templates>
131        </arity>
132        <xsl:for-each select="./Constructor">
133         <Constructor name="{./@name}">
134           <xsl:apply-templates select="./*[1]" mode="abstparams">
135            <xsl:with-param name="noparams" select="../../@noParams"/>
136            <xsl:with-param name="target" select="1"/>
137           </xsl:apply-templates>
138         </Constructor>
139        </xsl:for-each>
140       </InductiveType>
141      </xsl:for-each> 
142     </InductiveDefinition>       
143 </xsl:template>
144
145 <xsl:template match="Variable" mode="noannot"> 
146     <Variable name="{@name}" helm:xref="{@id}">
147      <xsl:if test="name(*[1])='body'">
148       <body>
149        <xsl:apply-templates select="body/*"/>
150       </body>
151      </xsl:if>
152      <type>
153        <xsl:apply-templates select="type/*"/>
154      </type>
155     </Variable> 
156 </xsl:template>
157
158 <!--*******************************************-->
159 <!--    ABSTRACTING PARAMETERS AND COUNTING    -->
160 <!--*******************************************-->
161 <!-- Si dimentica i CAST dei termini che astrae. Nel caso dell'astrazione -->
162 <!-- dei lambda dei pattern del CASE, qualora i lambda non si trovino     -->
163 <!-- nella forma weak-head, astrae solo i lambda che trova e restituisce  -->
164 <!-- un corpo depurato da tutti i primi cast che precedono il termine     -->
165 <!-- restituito.                                                          -->
166
167 <xsl:template match="*" mode="abstparams">
168 <xsl:param name="noparams" select="0"/>
169 <xsl:param name="target" select="0"/>
170 <xsl:param name="binder">PROD</xsl:param>
171     <xsl:choose>
172     <xsl:when test="($noparams != 0) and ((name(.)=string($binder)) or (name(.)=&quot;CAST&quot;))">
173      <xsl:choose>
174      <xsl:when test="name(.) = string($binder)">
175       <xsl:if test="$target = 0">
176        <xsl:choose>
177        <xsl:when test="string($binder) = &quot;LAMBDA&quot;">
178         <m:ci>
179          <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="target/@binder"/></xsl:with-param></xsl:call-template>
180         </m:ci>
181        </xsl:when>
182        <xsl:otherwise> 
183         <Param name="{target/@binder}">
184          <xsl:apply-templates select="source" mode="noannot"/>
185         </Param>
186        </xsl:otherwise>
187        </xsl:choose>
188       </xsl:if>
189       <xsl:apply-templates select="target/*[1]" mode="abstparams">
190        <xsl:with-param name="noparams" select="$noparams - 1"/>
191        <xsl:with-param name="target" select="$target"/>
192        <xsl:with-param name="binder" select="$binder"/>
193       </xsl:apply-templates>
194      </xsl:when>
195      <xsl:otherwise>
196       <xsl:apply-templates select="term/*[1]" mode="abstparams">
197        <xsl:with-param name="noparams" select="$noparams"/>
198        <xsl:with-param name="target" select="$target"/>
199        <xsl:with-param name="binder" select="$binder"/>
200       </xsl:apply-templates>
201      </xsl:otherwise>
202      </xsl:choose>
203     </xsl:when>
204     <xsl:otherwise> 
205      <xsl:choose>
206      <xsl:when test="($target = 1) and ($noparams != 0)">
207       <m:apply>
208       <m:csymbol>app</m:csymbol>
209       <xsl:apply-templates select="." mode="noannot"/>
210       <xsl:call-template name="printparam"><xsl:with-param name="noleft" select="$noparams"/></xsl:call-template>
211       </m:apply>
212      </xsl:when>
213      <xsl:otherwise>
214       <xsl:choose>
215       <xsl:when test="$noparams != 0">
216       <xsl:call-template name="printparam"><xsl:with-param name="noleft" select="$noparams"/></xsl:call-template>
217       </xsl:when>
218       <xsl:otherwise>
219        <xsl:if test="$target = 1">
220         <xsl:apply-templates select="." mode="noannot"/>
221        </xsl:if>
222       </xsl:otherwise>
223       </xsl:choose>
224      </xsl:otherwise>
225      </xsl:choose>
226     </xsl:otherwise>
227     </xsl:choose>
228 </xsl:template>
229
230 <xsl:template name="printparam">
231 <xsl:param name="noleft" select="0"/>
232 <xsl:param name="number" select="1"/>
233     <xsl:if test="$noleft != 0">
234      <m:ci><xsl:call-template name="insert_subscript"><xsl:with-param name="node_value">$<xsl:value-of select="$number"/></xsl:with-param></xsl:call-template></m:ci>
235      <xsl:call-template name="printparam"><xsl:with-param name="noleft" select="$noleft - 1"/><xsl:with-param name="number" select="$number + 1"/></xsl:call-template>  
236     </xsl:if>
237 </xsl:template>
238
239 <xsl:template match="*" mode="counting">
240 <xsl:param name="noparams" select="0"/>
241 <xsl:param name="count" select="0"/>
242  <xsl:choose>
243  <xsl:when test="name(.) = &quot;PROD&quot;">
244   <xsl:apply-templates select="target/*[1]" mode="counting">
245    <xsl:with-param name="noparams" select="$noparams"/>
246    <xsl:with-param name="count" select="$count + 1"/>
247   </xsl:apply-templates>
248  </xsl:when>
249  <xsl:when test="name(.) = &quot;CAST&quot;">
250   <xsl:apply-templates select="term/*[1]" mode="counting">
251    <xsl:with-param name="noparams" select="$noparams"/>
252    <xsl:with-param name="count" select="$count"/> 
253   </xsl:apply-templates>
254  </xsl:when>
255  <xsl:otherwise>
256   <xsl:value-of select="$count - $noparams"/>
257  </xsl:otherwise>
258  </xsl:choose>
259 </xsl:template>
260
261 </xsl:stylesheet>