3 <!-- Copyright (C) 2000, HELM Team -->
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. -->
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. -->
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. -->
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. -->
24 <!-- For details, see the HELM World-Wide-Web page, -->
25 <!-- http://cs.unibo.it/helm/. -->
27 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
28 xmlns:m="http://www.w3.org/1998/Math/MathML">
30 <!--***********************************************************************-->
31 <!-- auxiliary functions -->
32 <!-- HELM Group: Asperti, Padovani, Sacerdoti, Schena -->
33 <!--***********************************************************************-->
35 <!--***********************************************************************-->
36 <!-- get the name from a URI -->
37 <!--***********************************************************************-->
39 <!-- CSC: PROBLEMA: URI CHE NON CONTENGONO / ED INIZIANO CON cic: -->
40 <xsl:template name="name_of_uri">
41 <xsl:param name="uri" select=""""/>
42 <xsl:param name="extension" select="'.con'"/>
43 <xsl:variable name="suffix" select="substring-after($uri, "/")"/>
45 <xsl:when test="$suffix = """>
46 <!-- CSC: PROBLEMA: .con PUO' APPARIRE ALL'INTERNO DELLE URI ===>
47 SCRIVERE UNA FUNZIONE RICORSIVA CHE RISOLVA -->
48 <xsl:value-of select="substring-before($uri,$extension)"/>
51 <xsl:call-template name="name_of_uri">
52 <xsl:with-param name="uri" select="$suffix"/>
53 <xsl:with-param name="extension" select="$extension"/>
59 <!--***********************************************************************-->
60 <!-- erase common prefix from two uris -->
61 <!--***********************************************************************-->
63 <xsl:template name="common_prefix">
64 <xsl:param name="first_uri" select=""""/>
65 <xsl:param name="second_uri" select=""""/>
67 <xsl:when test="(substring-before($first_uri,"/") =
68 substring-before($second_uri,"/") and
69 substring-after($second_uri,"/") != "")">
70 <xsl:call-template name="common_prefix">
72 name="first_uri" select="substring-after($first_uri,"/")"/>
74 name="second_uri" select="substring-after($second_uri,"/")"/> </xsl:call-template>
77 <xsl:call-template name="slash_counting">
78 <xsl:with-param name="uri" select="$second_uri"/>
79 <xsl:with-param name="counter" select="0"/>
85 <xsl:template name="slash_counting">
86 <xsl:param name="uri" select=""""/>
87 <xsl:param name="counter" select="0"/>
89 <xsl:when test="(substring-after($uri,"/") != "")">
90 <xsl:call-template name="slash_counting">
92 name="uri" select="substring-after($uri,"/")"/>
94 name="counter" select="$counter +1"/>
98 <xsl:value-of select="$counter"/>
103 <!-- path gives the path of a uri, up to the final name -->
104 <xsl:template name="path">
105 <xsl:param name="uri" select=""""/>
106 <xsl:param name="current_path" select=""""/>
108 <xsl:when test="(substring-after($uri,"/") != "")">
109 <xsl:call-template name="path">
111 name="uri" select="substring-after($uri,"/")"/>
113 name="current_path" select="concat($current_path,substring-before($uri,"/"),'/')"/>
117 <xsl:value-of select="$current_path"/>
122 <xsl:template name="blank_counting">
123 <xsl:param name="string" select=""""/>
124 <xsl:param name="counter" select="0"/>
126 <xsl:when test="(substring-after($string," ") != "")">
127 <xsl:call-template name="blank_counting">
129 name="string" select="substring-after($string," ")"/>
131 name="counter" select="$counter +1"/>
135 <xsl:value-of select="$counter + 1"/>
140 <xsl:template name="double_point_counting">
141 <xsl:param name="string" select=""""/>
142 <xsl:param name="counter" select="0"/>
144 <xsl:when test="(substring-after($string,":") != "")">
145 <xsl:call-template name="double_point_counting">
147 name="string" select="substring-after($string,":")"/>
149 name="counter" select="$counter +1"/>
153 <xsl:value-of select="$counter"/>
158 <xsl:template name="min">
159 <xsl:param name="string" select=""""/>
160 <xsl:param name="counter" select="0"/>
162 <xsl:when test="contains($string,concat($counter,":"))
164 <xsl:value-of select="$counter"/>
167 <xsl:call-template name="min">
169 name="string" select="$string"/>
171 name="counter" select="$counter -1"/>
177 <xsl:template name="get_no_params">
178 <xsl:param name="first_uri" select=""""/>
179 <xsl:param name="second_uri" select=""""/>
180 <xsl:variable name="offset">
181 <xsl:call-template name="common_prefix">
182 <xsl:with-param name="first_uri" select="$first_uri"/>
183 <xsl:with-param name="second_uri" select="$second_uri"/>
187 <xsl:when test="$offset > 0">
188 <xsl:variable name="params">
189 <xsl:variable name="second_url"><xsl:call-template name="URLofURI4getter"><xsl:with-param name="uri" select="$second_uri"/></xsl:call-template></xsl:variable>
191 select="document($second_url)/*/@params"/>
193 <xsl:variable name="minimum">
194 <xsl:call-template name="min">
195 <xsl:with-param name="string" select="$params"/>
196 <xsl:with-param name="counter" select="$offset - 1"/>
200 <xsl:when test="0 > $minimum">
204 <xsl:variable name="relevant_params">
205 <!-- the blank after : in the next line is essential -->
207 select="substring-after($params,concat($minimum,": "))"/>
209 <xsl:variable name="tokens">
210 <xsl:call-template name="blank_counting">
211 <xsl:with-param name="string" select="$relevant_params"/>
212 <xsl:with-param name="counter" select="0"/>
215 <xsl:variable name="separators">
216 <xsl:call-template name="double_point_counting">
217 <xsl:with-param name="string" select="$relevant_params"/>
218 <xsl:with-param name="counter" select="0"/>
221 <xsl:value-of select="$tokens - $separators"/>
232 <!--***********************************************************************-->
233 <!-- Insert a subscript if there is a number at the end of a ci element -->
234 <!--***********************************************************************-->
236 <xsl:template name="insert_subscript">
237 <xsl:param name="node_value" select=""""/>
238 <xsl:param name="current_pos" select="1"/>
239 <xsl:param name="start_pos" select="0"/>
241 <xsl:when test="$current_pos <= string-length(string($node_value))">
242 <xsl:variable name="current_char"><xsl:value-of select="substring(string($node_value),$current_pos,1)"/></xsl:variable>
244 <xsl:when test="(string($current_char) != "0") and (string($current_char) != "1") and (string($current_char) != "2") and (string($current_char) != "3") and (string($current_char) != "4") and (string($current_char) != "5") and (string($current_char) != "6") and (string($current_char) != "7") and (string($current_char) != "8") and (string($current_char) != "9")">
246 <xsl:when test="$start_pos != 0">
247 <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value" select="$node_value"/><xsl:with-param name="current_pos" select="$current_pos + 1"/><xsl:with-param name="start_pos" select="0"/></xsl:call-template>
250 <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value" select="$node_value"/><xsl:with-param name="current_pos" select="$current_pos + 1"/><xsl:with-param name="start_pos" select="$start_pos"/></xsl:call-template>
256 <xsl:when test="$start_pos = 0">
257 <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value" select="$node_value"/><xsl:with-param name="current_pos" select="$current_pos + 1"/><xsl:with-param name="start_pos" select="$current_pos"/></xsl:call-template>
260 <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value" select="$node_value"/><xsl:with-param name="current_pos" select="$current_pos + 1"/><xsl:with-param name="start_pos" select="$start_pos"/></xsl:call-template>
268 <xsl:when test="$start_pos != 0">
270 <m:mi><xsl:value-of select="substring(string($node_value),1,$start_pos -1)"/></m:mi>
271 <m:mn><xsl:value-of select="substring(string($node_value),$start_pos)"/></m:mn>
275 <xsl:value-of select="$node_value"/>
283 <!--*******************************************-->
284 <!-- ABSTRACTING PARAMETERS AND COUNTING -->
285 <!--*******************************************-->
286 <!-- Si dimentica i CAST dei termini che astrae. Nel caso dell'astrazione -->
287 <!-- dei lambda dei pattern del CASE, qualora i lambda non si trovino -->
288 <!-- nella forma weak-head, astrae solo i lambda che trova e restituisce -->
289 <!-- un corpo depurato da tutti i primi cast che precedono il termine -->
292 <xsl:template match="*" mode="abstparams">
293 <xsl:param name="noparams" select="0"/>
294 <xsl:param name="target" select="0"/>
295 <xsl:param name="binder">PROD</xsl:param>
297 <xsl:when test="($noparams != 0) and ((name(.)=string($binder)) or (name(.)="CAST"))">
299 <xsl:when test="name(.) = string($binder)">
301 <xsl:when test="$noparams >= count(decl)">
302 <xsl:for-each select="decl">
303 <xsl:if test="$target = 0">
305 <xsl:when test="string($binder) = "LAMBDA"">
307 <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="@binder"/></xsl:with-param></xsl:call-template>
311 <Param name="{@binder}">
312 <xsl:apply-templates select="*[1]"/>
318 <xsl:apply-templates select="target/*[1]" mode="abstparams">
319 <xsl:with-param name="noparams" select="$noparams - count(decl)"/>
320 <xsl:with-param name="target" select="$target"/>
321 <xsl:with-param name="binder" select="$binder"/>
322 </xsl:apply-templates>
325 <xsl:for-each select="decl[$noparams >= position()]">
326 <xsl:if test="$target = 0">
328 <xsl:when test="string($binder) = "LAMBDA"">
330 <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="@binder"/></xsl:with-param></xsl:call-template>
334 <Param name="{@binder}">
335 <xsl:apply-templates select="*[1]"/>
341 <xsl:if test="$target = 1">
343 <xsl:when test="name(.)="PROD"">
344 <xsl:apply-templates select="decl[position()=$noparams+1]" mode="prod"/>
347 <xsl:apply-templates select="decl[position()=$noparams+1]" mode="lambda_prop"/>
355 <xsl:apply-templates select="term/*[1]" mode="abstparams">
356 <xsl:with-param name="noparams" select="$noparams"/>
357 <xsl:with-param name="target" select="$target"/>
358 <xsl:with-param name="binder" select="$binder"/>
359 </xsl:apply-templates>
365 <xsl:when test="($target = 1) and ($noparams != 0)">
367 <m:csymbol>app</m:csymbol>
368 <!-- Mancava modalita': sono all'interno di un termine -->
369 <xsl:apply-templates select="." mode="pure"/>
370 <xsl:call-template name="printparam"><xsl:with-param name="noleft" select="$noparams"/></xsl:call-template>
375 <xsl:when test="$noparams != 0">
376 <xsl:call-template name="printparam"><xsl:with-param name="noleft" select="$noparams"/></xsl:call-template>
379 <xsl:if test="$target = 1">
380 <!-- Mancava modalita': con target=1 posso provenire sia da un oggetto che da un termine -->
382 <xsl:when test="string($binder) = "LAMBDA"">
383 <!-- CSC: era pure, ma deve essere noannot. Giusto, Irene? -->
384 <xsl:apply-templates select="." mode="noannot"/>
387 <xsl:apply-templates select="."/>
399 <xsl:template name="printparam">
400 <xsl:param name="noleft" select="0"/>
401 <xsl:param name="number" select="1"/>
402 <xsl:if test="$noleft != 0">
403 <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>
404 <xsl:call-template name="printparam"><xsl:with-param name="noleft" select="$noleft - 1"/><xsl:with-param name="number" select="$number + 1"/></xsl:call-template>
408 <xsl:template match="*" mode="counting">
409 <xsl:param name="noparams" select="0"/>
410 <xsl:param name="count" select="0"/>
412 <xsl:when test="name(.) = "PROD"">
413 <xsl:apply-templates select="target/*[1]" mode="counting">
414 <xsl:with-param name="noparams" select="$noparams"/>
415 <xsl:with-param name="count" select="$count + count(decl)"/>
416 </xsl:apply-templates>
418 <xsl:when test="name(.) = "CAST"">
419 <xsl:apply-templates select="term/*[1]" mode="counting">
420 <xsl:with-param name="noparams" select="$noparams"/>
421 <xsl:with-param name="count" select="$count"/>
422 </xsl:apply-templates>
425 <xsl:value-of select="$count - $noparams"/>