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:variable name="suffix" select="substring-after($uri, "/")"/>
44 <xsl:when test="$suffix = """>
45 <!-- CSC: PROBLEMA: .con PUO' APPARIRE ALL'INTERNO DELLE URI ===>
46 SCRIVERE UNA FUNZIONE RICORSIVA CHE RISOLVA -->
47 <xsl:value-of select="substring-before($uri,".con")"/>
50 <xsl:call-template name="name_of_uri">
51 <xsl:with-param name="uri" select="$suffix"/>
57 <!--***********************************************************************-->
58 <!-- erase common prefix from two uris -->
59 <!--***********************************************************************-->
61 <xsl:template name="common_prefix">
62 <xsl:param name="first_uri" select=""""/>
63 <xsl:param name="second_uri" select=""""/>
65 <xsl:when test="(substring-before($first_uri,"/") =
66 substring-before($second_uri,"/") and
67 substring-after($second_uri,"/") != "")">
68 <xsl:call-template name="common_prefix">
70 name="first_uri" select="substring-after($first_uri,"/")"/>
72 name="second_uri" select="substring-after($second_uri,"/")"/> </xsl:call-template>
75 <xsl:call-template name="slash_counting">
76 <xsl:with-param name="uri" select="$second_uri"/>
77 <xsl:with-param name="counter" select="0"/>
83 <xsl:template name="slash_counting">
84 <xsl:param name="uri" select=""""/>
85 <xsl:param name="counter" select="0"/>
87 <xsl:when test="(substring-after($uri,"/") != "")">
88 <xsl:call-template name="slash_counting">
90 name="uri" select="substring-after($uri,"/")"/>
92 name="counter" select="$counter +1"/>
96 <xsl:value-of select="$counter"/>
101 <xsl:template name="blank_counting">
102 <xsl:param name="string" select=""""/>
103 <xsl:param name="counter" select="0"/>
105 <xsl:when test="(substring-after($string," ") != "")">
106 <xsl:call-template name="blank_counting">
108 name="string" select="substring-after($string," ")"/>
110 name="counter" select="$counter +1"/>
114 <xsl:value-of select="$counter + 1"/>
119 <xsl:template name="double_point_counting">
120 <xsl:param name="string" select=""""/>
121 <xsl:param name="counter" select="0"/>
123 <xsl:when test="(substring-after($string,":") != "")">
124 <xsl:call-template name="double_point_counting">
126 name="string" select="substring-after($string,":")"/>
128 name="counter" select="$counter +1"/>
132 <xsl:value-of select="$counter"/>
137 <xsl:template name="min">
138 <xsl:param name="string" select=""""/>
139 <xsl:param name="counter" select="0"/>
141 <xsl:when test="contains($string,concat($counter,":"))
143 <xsl:value-of select="$counter"/>
146 <xsl:call-template name="min">
148 name="string" select="$string"/>
150 name="counter" select="$counter -1"/>
156 <xsl:template name="get_no_params">
157 <xsl:param name="first_uri" select=""""/>
158 <xsl:param name="second_uri" select=""""/>
159 <xsl:variable name="offset">
160 <xsl:call-template name="common_prefix">
161 <xsl:with-param name="first_uri" select="$first_uri"/>
162 <xsl:with-param name="second_uri" select="$second_uri"/>
166 <xsl:when test="$offset > 0">
167 <xsl:variable name="params">
168 <xsl:variable name="second_url"><xsl:call-template name="URLofURI4getter"><xsl:with-param name="uri" select="$second_uri"/></xsl:call-template></xsl:variable>
170 select="document($second_url)/*/@params"/>
172 <xsl:variable name="minimum">
173 <xsl:call-template name="min">
174 <xsl:with-param name="string" select="$params"/>
175 <xsl:with-param name="counter" select="$offset - 1"/>
179 <xsl:when test="0 > $minimum">
183 <xsl:variable name="relevant_params">
184 <!-- the blank after : in the next line is essential -->
186 select="substring-after($params,concat($minimum,": "))"/>
188 <xsl:variable name="tokens">
189 <xsl:call-template name="blank_counting">
190 <xsl:with-param name="string" select="$relevant_params"/>
191 <xsl:with-param name="counter" select="0"/>
194 <xsl:variable name="separators">
195 <xsl:call-template name="double_point_counting">
196 <xsl:with-param name="string" select="$relevant_params"/>
197 <xsl:with-param name="counter" select="0"/>
200 <xsl:value-of select="$tokens - $separators"/>
211 <!--***********************************************************************-->
212 <!-- Insert a subscript if there is a number at the end of a ci element -->
213 <!--***********************************************************************-->
215 <xsl:template name="insert_subscript">
216 <xsl:param name="node_value" select=""""/>
217 <xsl:param name="current_pos" select="1"/>
218 <xsl:param name="start_pos" select="0"/>
220 <xsl:when test="$current_pos <= string-length(string($node_value))">
221 <xsl:variable name="current_char"><xsl:value-of select="substring(string($node_value),$current_pos,1)"/></xsl:variable>
223 <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")">
225 <xsl:when test="$start_pos != 0">
226 <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>
229 <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>
235 <xsl:when test="$start_pos = 0">
236 <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>
239 <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>
247 <xsl:when test="$start_pos != 0">
249 <m:mi><xsl:value-of select="substring(string($node_value),1,$start_pos -1)"/></m:mi>
250 <m:mn><xsl:value-of select="substring(string($node_value),$start_pos)"/></m:mn>
254 <xsl:value-of select="$node_value"/>
262 <!--*******************************************-->
263 <!-- ABSTRACTING PARAMETERS AND COUNTING -->
264 <!--*******************************************-->
265 <!-- Si dimentica i CAST dei termini che astrae. Nel caso dell'astrazione -->
266 <!-- dei lambda dei pattern del CASE, qualora i lambda non si trovino -->
267 <!-- nella forma weak-head, astrae solo i lambda che trova e restituisce -->
268 <!-- un corpo depurato da tutti i primi cast che precedono il termine -->
271 <xsl:template match="*" mode="abstparams">
272 <xsl:param name="noparams" select="0"/>
273 <xsl:param name="target" select="0"/>
274 <xsl:param name="binder">PROD</xsl:param>
276 <xsl:when test="($noparams != 0) and ((name(.)=string($binder)) or (name(.)="CAST"))">
278 <xsl:when test="name(.) = string($binder)">
279 <xsl:if test="$target = 0">
281 <xsl:when test="string($binder) = "LAMBDA"">
283 <xsl:call-template name="insert_subscript"><xsl:with-param name="node_value"><xsl:value-of select="target/@binder"/></xsl:with-param></xsl:call-template>
287 <Param name="{target/@binder}">
288 <xsl:apply-templates select="source"/>
293 <xsl:apply-templates select="target/*[1]" mode="abstparams">
294 <xsl:with-param name="noparams" select="$noparams - 1"/>
295 <xsl:with-param name="target" select="$target"/>
296 <xsl:with-param name="binder" select="$binder"/>
297 </xsl:apply-templates>
300 <xsl:apply-templates select="term/*[1]" mode="abstparams">
301 <xsl:with-param name="noparams" select="$noparams"/>
302 <xsl:with-param name="target" select="$target"/>
303 <xsl:with-param name="binder" select="$binder"/>
304 </xsl:apply-templates>
310 <xsl:when test="($target = 1) and ($noparams != 0)">
312 <m:csymbol>app</m:csymbol>
313 <!-- Mancava modalita': sono all'interno di un termine -->
314 <xsl:apply-templates select="." mode="pure"/>
315 <xsl:call-template name="printparam"><xsl:with-param name="noleft" select="$noparams"/></xsl:call-template>
320 <xsl:when test="$noparams != 0">
321 <xsl:call-template name="printparam"><xsl:with-param name="noleft" select="$noparams"/></xsl:call-template>
324 <xsl:if test="$target = 1">
325 <!-- Mancava modalita': con target=1 posso provenire sia da un oggetto che da un termine -->
327 <xsl:when test="string($binder) = "LAMBDA"">
328 <!-- CSC: era pure, ma deve essere noannot. Giusto, Irene? -->
329 <xsl:apply-templates select="." mode="noannot"/>
332 <xsl:apply-templates select="."/>
344 <xsl:template name="printparam">
345 <xsl:param name="noleft" select="0"/>
346 <xsl:param name="number" select="1"/>
347 <xsl:if test="$noleft != 0">
348 <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>
349 <xsl:call-template name="printparam"><xsl:with-param name="noleft" select="$noleft - 1"/><xsl:with-param name="number" select="$number + 1"/></xsl:call-template>
353 <xsl:template match="*" mode="counting">
354 <xsl:param name="noparams" select="0"/>
355 <xsl:param name="count" select="0"/>
357 <xsl:when test="name(.) = "PROD"">
358 <xsl:apply-templates select="target/*[1]" mode="counting">
359 <xsl:with-param name="noparams" select="$noparams"/>
360 <xsl:with-param name="count" select="$count + 1"/>
361 </xsl:apply-templates>
363 <xsl:when test="name(.) = "CAST"">
364 <xsl:apply-templates select="term/*[1]" mode="counting">
365 <xsl:with-param name="noparams" select="$noparams"/>
366 <xsl:with-param name="count" select="$count"/>
367 </xsl:apply-templates>
370 <xsl:value-of select="$count - $noparams"/>