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