]> matita.cs.unibo.it Git - helm.git/blob - helm/meta_style/meta_cic2mathml.xsl
First version of Di Lena's stylesheet generator (for the HELM DTD).
[helm.git] / helm / meta_style / meta_cic2mathml.xsl
1 <?xml version="1.0"?>
2
3 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4                               xmlns:m="http://www.w3.org/1998/Math/MathML"
5                               xmlns:helm="http://www.cs.unibo.it/helm"
6                               xmlns:oxsl="http://www.w3.org/1999/XSL/TransformAlias">
7
8 <xsl:output method="xml"/>
9
10 <xsl:namespace-alias stylesheet-prefix="oxsl" result-prefix="xsl"/>
11
12 <xsl:template match="OpList">
13         <xsl:comment> Copyright (C) 2000, HELM Team                                     </xsl:comment>
14         <xsl:comment>                                                                   </xsl:comment>
15         <xsl:comment> This file is part of HELM, an Hypertextual, Electronic            </xsl:comment>
16         <xsl:comment> Library of Mathematics, developed at the Computer Science         </xsl:comment>
17         <xsl:comment> Department, University of Bologna, Italy.                         </xsl:comment>
18         <xsl:comment>                                                                   </xsl:comment>
19         <xsl:comment> HELM is free software; you can redistribute it and/or             </xsl:comment>
20         <xsl:comment> modify it under the terms of the GNU General Public License       </xsl:comment>
21         <xsl:comment> as published by the Free Software Foundation; either version 2    </xsl:comment>
22         <xsl:comment> of the License, or (at your option) any later version.            </xsl:comment>
23         <xsl:comment>                                                                   </xsl:comment>
24         <xsl:comment> HELM is distributed in the hope that it will be useful,           </xsl:comment>
25         <xsl:comment> but WITHOUT ANY WARRANTY; without even the implied warranty of    </xsl:comment>
26         <xsl:comment> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     </xsl:comment>
27         <xsl:comment> GNU General Public License for more details.                      </xsl:comment>
28         <xsl:comment>                                                                   </xsl:comment>
29         <xsl:comment> You should have received a copy of the GNU General Public License </xsl:comment>
30         <xsl:comment> along with HELM; if not, write to the Free Software               </xsl:comment>
31         <xsl:comment> Foundation, Inc., 59 Temple Place - Suite 330, Boston,            </xsl:comment>
32         <xsl:comment> MA  02111-1307, USA.                                              </xsl:comment>
33         <xsl:comment>                                                                   </xsl:comment>
34         <xsl:comment> For details, see the HELM World-Wide-Web page,                    </xsl:comment>
35         <xsl:comment> http://cs.unibo.it/helm/.                                         </xsl:comment>
36         
37         <oxsl:stylesheet version="1.0">
38                 <xsl:apply-templates/>
39         </oxsl:stylesheet>
40 </xsl:template>
41
42 <xsl:template match="import">
43         <oxsl:import href="{@href}"/>
44 </xsl:template>
45
46 <xsl:template match="include">
47         <oxsl:include href="{@href}"/>
48 </xsl:template>
49
50 <xsl:template match="Operator|NotOperator">
51         <xsl:variable name="uri">
52                 <xsl:call-template name="remove_white_spaces">
53                         <xsl:with-param name="uri" select="@uri"/>
54                 </xsl:call-template>
55         </xsl:variable>
56
57         <xsl:variable name="not">
58                 <xsl:choose>
59                         <xsl:when test="name() = 'Operator'">false</xsl:when>
60                         <xsl:otherwise>true</xsl:otherwise>
61                 </xsl:choose>
62         </xsl:variable>
63
64         <xsl:choose>
65                 <xsl:when test="@arity = 0 and @hide = 0 and $not = 'true'">
66                         <xsl:call-template name="out_comment">
67                                 <xsl:with-param name="name" select="concat($uri,': &quot;not&quot; cannot  be applyed to a constant operator')"/>
68                         </xsl:call-template>
69                 </xsl:when>
70                 <xsl:when test="@arity = 0 and @hide = 0 and @cook = 'true'">
71                         <xsl:call-template name="out_comment">
72                                 <xsl:with-param name="name" select="concat($uri,': a constant operator cannot be cooked')"/>
73                         </xsl:call-template>
74                 </xsl:when>
75                 <xsl:otherwise>
76                         <!-- All uris in uri1 list (if not empty) have CONST c-tag -->
77                         <xsl:variable name="uri1">
78                                 <xsl:call-template name="select_uris">
79                                         <xsl:with-param name="uris"  select="$uri"/>
80                                         <xsl:with-param name="c-tag" select="'CONST'"/>
81                                 </xsl:call-template>
82                         </xsl:variable>
83                         
84                         <!-- All uris in uri2 list (if not empty) have MUTIND c-tag -->
85                         <xsl:variable name="uri2">
86                                 <xsl:call-template name="select_uris">
87                                         <xsl:with-param name="uris"  select="$uri"/>
88                                         <xsl:with-param name="c-tag" select="'MUTIND'"/>
89                                 </xsl:call-template>
90                         </xsl:variable>
91
92                         <xsl:if test="$uri1 != ''">
93                                 <xsl:call-template name="out_template">
94                                         <xsl:with-param name="name"  select="@name"/>
95                                         <xsl:with-param name="not"   select="$not"/>
96                                         <xsl:with-param name="uri"   select="$uri1"/>
97                                         <xsl:with-param name="cook"  select="@cook"/>
98                                         <xsl:with-param name="hide"  select="@hide"/>
99                                         <xsl:with-param name="arity" select="@arity"/>
100                                         <xsl:with-param name="m-tag" select="@m-tag"/>
101                                         <xsl:with-param name="c-tag" select="'CONST'"/>
102                                 </xsl:call-template>
103                         </xsl:if>
104
105                         <xsl:if test="$uri2 != ''">
106                                 <xsl:call-template name="out_template">
107                                         <xsl:with-param name="name"  select="@name"/>
108                                         <xsl:with-param name="not"   select="$not"/>
109                                         <xsl:with-param name="uri"   select="$uri2"/>
110                                         <xsl:with-param name="cook"  select="@cook"/>
111                                         <xsl:with-param name="hide"  select="@hide"/>
112                                         <xsl:with-param name="arity" select="@arity"/>
113                                         <xsl:with-param name="m-tag" select="@m-tag"/>
114                                         <xsl:with-param name="c-tag" select="'MUTIND'"/>
115                                 </xsl:call-template>
116                         </xsl:if>
117                 </xsl:otherwise>
118         </xsl:choose>
119 </xsl:template>
120
121 <xsl:template match="OpSet|NotOpSet">
122         <xsl:variable name="uri">
123                 <xsl:call-template name="remove_white_spaces">
124                         <xsl:with-param name="uri" select="@uri"/>
125                 </xsl:call-template>
126         </xsl:variable>
127
128         <xsl:variable name="not">
129                 <xsl:choose>
130                         <xsl:when test="name() = 'OpSet'">false</xsl:when>
131                         <xsl:otherwise>true</xsl:otherwise>
132                 </xsl:choose>
133         </xsl:variable>
134
135         <xsl:choose>
136                 <xsl:when test="*[name() = 'Case']/@arity = 0 and @hide = 0 and $not = 'true'">
137                         <xsl:call-template name="out_comment">
138                                 <xsl:with-param name="name" select="concat($uri,': &quot;not&quot; cannot  be applyed to a constant operator')"/>
139                         </xsl:call-template>
140                 </xsl:when>
141                 <xsl:when test="*[name() = 'Case']/@arity = 0 and @hide = 0 and @cook = 'true'">
142                         <xsl:call-template name="out_comment">
143                                 <xsl:with-param name="name" select="concat($uri,': a constant operator cannot be cooked')"/>
144                         </xsl:call-template>
145                 </xsl:when>
146                 <xsl:otherwise>
147                         <xsl:variable name="uri1">
148                                 <xsl:call-template name="select_uris">
149                                         <xsl:with-param name="uris"  select="$uri"/>
150                                         <xsl:with-param name="c-tag" select="'CONST'"/>
151                                 </xsl:call-template>
152                         </xsl:variable>
153
154                         <xsl:variable name="uri2">
155                                 <xsl:call-template name="select_uris">
156                                         <xsl:with-param name="uris"  select="$uri"/>
157                                         <xsl:with-param name="c-tag" select="'MUTIND'"/>
158                                 </xsl:call-template>
159                         </xsl:variable>
160
161                         <xsl:if test="$uri1 != ''">
162                                 <xsl:call-template name="out_template_set">
163                                         <xsl:with-param name="name"  select="@name"/>
164                                         <xsl:with-param name="not"   select="$not"/>
165                                         <xsl:with-param name="uri"   select="$uri1"/>
166                                         <xsl:with-param name="cook"  select="@cook"/>
167                                         <xsl:with-param name="hide"  select="@hide"/>
168                                         <xsl:with-param name="m-tag" select="@m-tag"/>
169                                         <xsl:with-param name="c-tag" select="'CONST'"/>
170                                 </xsl:call-template>
171                         </xsl:if>
172
173                         <xsl:if test="$uri2 != ''">
174                                 <xsl:call-template name="out_template_set">
175                                         <xsl:with-param name="name"  select="@name"/>
176                                         <xsl:with-param name="not"   select="$not"/>
177                                         <xsl:with-param name="uri"   select="$uri2"/>
178                                         <xsl:with-param name="cook"  select="@cook"/>
179                                         <xsl:with-param name="hide"  select="@hide"/>
180                                         <xsl:with-param name="m-tag" select="@m-tag"/>
181                                         <xsl:with-param name="c-tag" select="'MUTIND'"/>
182                                 </xsl:call-template>
183                         </xsl:if>
184                 </xsl:otherwise>
185         </xsl:choose>
186 </xsl:template>
187
188 <!-- *********************************************************************** -->
189 <!--                             MAIN FUNCTIONS                              -->
190 <!-- *********************************************************************** -->
191
192
193 <xsl:template name="out_template">
194         <xsl:param name="name"/>
195         <xsl:param name="not"   select="'false'"/>
196         <xsl:param name="uri"/>
197         <xsl:param name="cook"  select="'false'"/>
198         <xsl:param name="hide"  select="0"/>
199         <xsl:param name="arity" select="0"/>
200         <xsl:param name="m-tag"/>
201         <xsl:param name="c-tag"/>
202
203         <xsl:variable name="apply_not">
204                 <xsl:if test="$not = 'true'">*[2]/</xsl:if>
205         </xsl:variable>
206
207         <xsl:variable name="match">
208                 <xsl:call-template name="out_match">
209                         <xsl:with-param name="not"   select="$not"/>
210                         <xsl:with-param name="uri"   select="$uri"/>
211                         <xsl:with-param name="cook"  select="$cook"/>
212                         <xsl:with-param name="hide"  select="$hide"/>
213                         <xsl:with-param name="arity" select="$arity"/>
214                         <xsl:with-param name="c-tag" select="$c-tag"/>
215                 </xsl:call-template>    
216         </xsl:variable>
217
218         <xsl:variable name="op_uri_attr">
219                 <xsl:variable name="tmp_op_uri_attr">
220                         <xsl:call-template name="op_uri_attr">
221                                 <xsl:with-param name="not"   select="$not"/>
222                                 <xsl:with-param name="c-tag" select="$c-tag"/>
223                                 <xsl:with-param name="const" select="$arity = 0 and $hide = 0"/>
224                         </xsl:call-template>
225                 </xsl:variable>
226                 <xsl:value-of select="substring-after(substring-before($tmp_op_uri_attr,'}'),'{')"/>
227         </xsl:variable>
228
229         <!--                     TEMPLATE                     -->
230         <xsl:call-template name="out_comment">
231                 <xsl:with-param name="name" select="$name"/>
232         </xsl:call-template>
233
234         <oxsl:template match="{$match}" mode="pure">
235                 <xsl:choose>
236                         <xsl:when test="$cook = 'true'">
237                                 <oxsl:variable name="no_params">
238                                         <oxsl:variable name="no_params_tmp">
239                                                 <oxsl:call-template name="get_no_params">
240                                                         <oxsl:with-param name="first_uri"  select="$CICURI"/>
241                                                         <oxsl:with-param name="second_uri" select="{$op_uri_attr}"/>
242                                                 </oxsl:call-template>
243                                         </oxsl:variable>
244                                         <oxsl:value-of select="number($no_params_tmp)"/>
245                                 </oxsl:variable>
246                                 <oxsl:choose>
247                                         <oxsl:when test="{concat('count(',$apply_not,'*) = $no_params + ',$arity + $hide + 1)}">
248                                                 <xsl:call-template name="out_body">
249                                                         <xsl:with-param name="c-tag" select="$c-tag"/>
250                                                         <xsl:with-param name="m-tag" select="$m-tag"/>
251                                                         <xsl:with-param name="cook"  select="$cook"/>
252                                                         <xsl:with-param name="hide"  select="$hide"/>
253                                                         <xsl:with-param name="arity" select="$arity"/>
254                                                         <xsl:with-param name="not"   select="$not"/>
255                                                 </xsl:call-template>
256                                          </oxsl:when>
257                                          <oxsl:otherwise>
258                                                 <oxsl:apply-imports/>
259                                         </oxsl:otherwise>
260                                 </oxsl:choose>
261                         </xsl:when>
262                         <xsl:otherwise>
263                                 <xsl:call-template name="out_body">
264                                         <xsl:with-param name="c-tag" select="$c-tag"/>
265                                         <xsl:with-param name="m-tag" select="$m-tag"/>
266                                         <xsl:with-param name="cook"  select="$cook"/>
267                                         <xsl:with-param name="hide"  select="$hide"/>
268                                         <xsl:with-param name="arity" select="$arity"/>
269                                         <xsl:with-param name="not"   select="$not"/>
270                                 </xsl:call-template>
271                         </xsl:otherwise>
272                 </xsl:choose>
273         </oxsl:template>
274 </xsl:template>
275
276 <xsl:template name="out_template_set">
277         <xsl:param name="name"/>
278         <xsl:param name="not"  select="'false'"/>
279         <xsl:param name="cook" select="'false'"/>
280         <xsl:param name="uri"/>
281         <xsl:param name="hide" select="0"/>
282         <xsl:param name="m-tag"/>
283         <xsl:param name="c-tag"/>
284
285         <xsl:variable name="no_params_var">
286                 <xsl:if test="$cook = 'true'">$no_params + </xsl:if>
287         </xsl:variable>
288
289         <xsl:variable name="match">
290                 <xsl:call-template name="out_match_op">
291                         <xsl:with-param name="not"   select="$not"/> 
292                         <xsl:with-param name="uri"   select="$uri"/> 
293                         <xsl:with-param name="c-tag" select="$c-tag"/>
294                 </xsl:call-template>
295         </xsl:variable>
296
297         <xsl:variable name="apply_not">
298                 <xsl:if test="$not = 'true'">*[2]/</xsl:if>
299         </xsl:variable>
300
301         <xsl:variable name="op_uri_attr">
302                 <xsl:variable name="tmp_op_uri_attr">
303                         <xsl:call-template name="op_uri_attr">
304                                 <xsl:with-param name="not"   select="$not"/>
305                                 <xsl:with-param name="c-tag" select="$c-tag"/>
306                         </xsl:call-template>
307                 </xsl:variable>
308                 <xsl:value-of select="substring-after(substring-before($tmp_op_uri_attr,'}'),'{')"/>
309         </xsl:variable>
310
311
312         <!--                     TEMPLATE                     -->
313         <xsl:call-template name="out_comment">
314                 <xsl:with-param name="name" select="$name"/>
315         </xsl:call-template>
316         
317         <oxsl:template match="{concat('APPLY[',$match,']')}" mode="pure">
318                 <xsl:if test="$cook = 'true'">
319                         <oxsl:variable name="no_params">
320                                 <oxsl:variable name="no_params_tmp">
321                                         <oxsl:call-template name="get_no_params">
322                                                 <oxsl:with-param name="first_uri"  select="$CICURI"/>
323                                                 <oxsl:with-param name="second_uri" select="{$op_uri_attr}"/>
324                                         </oxsl:call-template>
325                                 </oxsl:variable>
326                                 <oxsl:value-of select="number($no_params_tmp)"/>
327                         </oxsl:variable>
328                 </xsl:if>       
329                 <oxsl:choose>
330                         <xsl:for-each select="Case">
331                                 <oxsl:when test="{concat('count(',$apply_not,'*) = ',$no_params_var,@arity + $hide + 1)}">
332                                         <xsl:call-template name="out_body">
333                                                 <xsl:with-param name="c-tag" select="$c-tag"/>
334                                                 <xsl:with-param name="m-tag" select="$m-tag"/>
335                                                 <xsl:with-param name="cook"  select="$cook"/>
336                                                 <xsl:with-param name="hide"  select="$hide"/>
337                                                 <xsl:with-param name="arity" select="@arity"/>
338                                                 <xsl:with-param name="not"   select="$not"/>
339                                         </xsl:call-template>
340                                 </oxsl:when>
341                         </xsl:for-each>
342                                 <oxsl:otherwise>
343                                         <oxsl:apply-imports/>
344                                 </oxsl:otherwise>
345                 </oxsl:choose>
346         </oxsl:template>
347 </xsl:template>
348
349 <xsl:template name="out_comment">
350         <xsl:param name="name"/>
351         <xsl:if test="$name">
352                 <xsl:comment>
353                         <xsl:value-of select="concat(' ',$name,' ')"/>
354                 </xsl:comment>
355         </xsl:if>                                                               
356 </xsl:template>
357
358 <!-- Returns a regular expression with matching operators -->
359 <xsl:template name="out_match_op">
360         <xsl:param name="not"  select="'false'"/>
361         <xsl:param name="uri"/>
362         <xsl:param name="c-tag"/>
363         
364         <!-- application with not operator -->
365         <xsl:variable name="app_not">
366                 <xsl:if test="$not = 'true'">CONST[@uri='cic:/Coq/Init/Logic/not.con'] and </xsl:if>
367         </xsl:variable>
368
369         <xsl:variable name="uris">
370                 <xsl:call-template name="test_on_uris">
371                         <xsl:with-param name="uris" select="$uri"/>
372                 </xsl:call-template>
373         </xsl:variable>
374
375         <xsl:variable name="app_op">
376                 <xsl:if test="$not = 'true'">APPLY[</xsl:if>
377                 <xsl:value-of select="concat($c-tag,'[',$uris,']')"/>
378                 <xsl:if test="$not = 'true'">]</xsl:if>
379         </xsl:variable>
380
381         <xsl:value-of select="concat($app_not,$app_op)"/>
382 </xsl:template>
383
384 <!-- Returns a test on apply node children number-->
385 <xsl:template name="out_match_child">
386         <xsl:param name="not"   select="'false'"/>
387         <xsl:param name="cook"  select="'false'"/>
388         <xsl:param name="hide"  select="0"/>
389         <xsl:param name="arity" select="0"/>
390
391         <!--
392                 Test on children number only if the operator is concatenated with not of 
393                 if it is not constant and it has not to be cooked.
394                 It is not possible to concatenate a constant operator with not.
395         -->
396         <xsl:if test="$not = 'true' or (($arity != 0 or $hide != 0) and $cook = 'false')">
397                 <xsl:choose>
398                         <!-- if the operator has been concatenated with not, the root apply node must have only two child -->
399                         <xsl:when test="$not = 'true'">
400                                 <xsl:variable name="test_apply_children">
401                                         <xsl:if test="$cook = 'false'">
402                                                 <xsl:value-of select="concat(' and count(*[2]/*) = ',$arity + $hide + 1)"/>
403                                         </xsl:if>
404                                 </xsl:variable>
405                                 
406                                 <xsl:value-of select="concat('count(*) = 2',$test_apply_children)"/>
407                         </xsl:when>
408                         <xsl:otherwise>
409                                 <xsl:value-of select="concat('count(*) = ',$arity + $hide + 1)"/>
410                         </xsl:otherwise>
411                 </xsl:choose>
412         </xsl:if>
413 </xsl:template>
414
415 <xsl:template name="out_match">
416         <xsl:param name="not"   select="'false'"/>
417         <xsl:param name="uri"/>
418         <xsl:param name="cook"  select="'false'"/>
419         <xsl:param name="hide"  select="0"/>
420         <xsl:param name="arity" select="0"/>
421         <xsl:param name="c-tag"/>
422         
423         <!--           TEST ON OPERATOR(S) TYPE         -->
424         <xsl:variable name="match_op">
425                 <xsl:call-template name="out_match_op">
426                         <xsl:with-param name="not"   select="$not"/>
427                         <xsl:with-param name="uri"   select="$uri"/>
428                         <xsl:with-param name="hide"  select="$hide"/>
429                         <xsl:with-param name="c-tag" select="$c-tag"/>
430                 </xsl:call-template>
431         </xsl:variable>
432                 
433         <!--           TEST ON CHILD(REN) NUMBER         -->
434         <xsl:variable name="match_child">
435                 <xsl:call-template name="out_match_child">
436                         <xsl:with-param name="not"   select="$not"/>
437                         <xsl:with-param name="cook"  select="$cook"/>
438                         <xsl:with-param name="hide"  select="$hide"/>
439                         <xsl:with-param name="arity" select="$arity"/>
440                 </xsl:call-template>
441         </xsl:variable>
442
443         <xsl:choose>
444                 <!-- not a constant operator -->
445                 <xsl:when test="$arity != 0 or $hide != 0">
446                         <xsl:choose>
447                                 <xsl:when test="$match_child != ''">
448                                         <xsl:value-of select="concat('APPLY[',$match_op,' and ',$match_child,']')"/>
449                                 </xsl:when>
450                                 <xsl:otherwise>
451                                         <xsl:value-of select="concat('APPLY[',$match_op,']')"/>
452                                 </xsl:otherwise>
453                         </xsl:choose>
454                 </xsl:when>
455                 <xsl:otherwise>
456                         <xsl:choose>
457                                 <xsl:when test="$match_child != ''">
458                                         <xsl:value-of select="concat($match_op,' and ',$match_child)"/>
459                                 </xsl:when>
460                                 <xsl:otherwise>
461                                         <xsl:value-of select="$match_op"/>
462                                 </xsl:otherwise>
463                         </xsl:choose>
464                 </xsl:otherwise>
465         </xsl:choose>
466 </xsl:template>
467
468 <xsl:template name="out_params">
469         <xsl:param name="params" select="1"/>
470         <xsl:param name="cook"   select="'false'"/>
471         <xsl:param name="hide"   select="0"/>
472         <xsl:param name="not"    select="'false'"/>
473         <xsl:param name="mode"   select="'noannot'"/>
474         <xsl:param name="arity"  select="0"/>
475
476         <xsl:if test="$params &lt;= $arity">
477                 <xsl:variable name="param">
478                         <xsl:call-template name="param">
479                                 <xsl:with-param name="id"    select="$params"/>
480                                 <xsl:with-param name="not"   select="$not"/>
481                                 <xsl:with-param name="cook"  select="$cook"/>
482                                 <xsl:with-param name="hide"  select="$hide"/>
483                         </xsl:call-template>
484                 </xsl:variable>
485
486                 <oxsl:apply-templates select="{$param}" mode="{$mode}"/>
487                 
488                 <xsl:call-template name="out_params">
489                         <xsl:with-param name="params" select="$params + 1"/>
490                         <xsl:with-param name="cook"   select="$cook"/>
491                         <xsl:with-param name="hide"   select="$hide"/>
492                         <xsl:with-param name="not"    select="$not"/>
493                         <xsl:with-param name="mode"   select="$mode"/>
494                         <xsl:with-param name="arity"  select="$arity"/>
495                 </xsl:call-template>
496         </xsl:if>
497 </xsl:template>
498
499
500 <xsl:template name="out_body">
501         <xsl:param name="c-tag"/>
502         <xsl:param name="cook"  select="'false'"/>
503         <xsl:param name="m-tag"/>
504         <xsl:param name="hide"  select="0"/>
505         <xsl:param name="arity" select="0"/>
506         <xsl:param name="not"   select="'false'"/>
507
508         <xsl:choose>
509                 <!--            SIMPLE TRANSFORMATIONS            -->
510                 <xsl:when test="count(*) = 0">
511                         <xsl:variable name="xref">{@id}</xsl:variable>
512
513                         <xsl:variable name="definitionURL">
514                                 <xsl:call-template name="op_uri_attr">
515                                         <xsl:with-param name="not"   select="$not"/>
516                                         <xsl:with-param name="c-tag" select="$c-tag"/>
517                                         <xsl:with-param name="const" select="$arity = 0 and $hide = 0"/>
518                                 </xsl:call-template>
519                         </xsl:variable>
520
521                          <xsl:variable name="helm:xref">
522                                 <xsl:call-template name="op_id_attr">
523                                         <xsl:with-param name="not"   select="$not"/>
524                                         <xsl:with-param name="c-tag" select="$c-tag"/>
525                                         <xsl:with-param name="const" select="$arity = 0 and $hide = 0"/>
526                                 </xsl:call-template>
527                          </xsl:variable>
528                 
529                         <!--            APPLY            -->
530                         <m:apply helm:xref="{$xref}">
531                                 <!--            OPERATOR            -->
532                                 <xsl:element name="{concat('m:',$m-tag)}">
533                                         <xsl:attribute name="definitionURL">
534                                                 <xsl:value-of select="$definitionURL"/>
535                                         </xsl:attribute>
536                                         <xsl:attribute name="helm:xref">
537                                                 <xsl:value-of select="$helm:xref"/>
538                                         </xsl:attribute>
539                                 </xsl:element>
540                                 <!--            PARAMS            -->
541                                 <xsl:call-template name="out_params">
542                                         <xsl:with-param name="cook"   select="$cook"/>
543                                         <xsl:with-param name="hide"   select="$hide"/>  
544                                         <xsl:with-param name="not"    select="$not"/>
545                                         <xsl:with-param name="arity"  select="$arity"/>
546                                 </xsl:call-template>
547                         </m:apply>
548                 </xsl:when>
549                 <!--            COMPLEX TRANSFORMATIONS            -->
550                 <xsl:otherwise>
551                         <xsl:apply-templates>
552                                 <xsl:with-param name="c-tag" select="$c-tag"/>
553                                 <xsl:with-param name="cook"  select="$cook"/>
554                                 <xsl:with-param name="hide"  select="$hide"/>
555                                 <xsl:with-param name="arity" select="$arity"/>
556                                 <xsl:with-param name="not"   select="$not"/>
557                         </xsl:apply-templates>
558                 </xsl:otherwise>
559         </xsl:choose>
560 </xsl:template>
561
562 <xsl:template name="out_mvar">
563         <xsl:param name="vname"/>
564         
565         <m:ci>
566                 <xsl:choose>
567                         <xsl:when test="(ancestor-or-self::*[preceding-sibling::*[(name() = 'mbvar') and (@name = $vname)]]/preceding-sibling::*[(name() = 'mbvar') and (@name = $vname)])[position() = last()]">
568                                 <oxsl:value-of select="{concat('$bvar_',$vname)}"/>
569                         </xsl:when>
570                         <xsl:otherwise>
571                                 <xsl:value-of select="$vname"/>
572                         </xsl:otherwise>
573                 </xsl:choose>
574         </m:ci>
575 </xsl:template>
576
577
578 <xsl:template name="out_choose_binder">
579         <xsl:param name="binded_params" select="''"/>
580         <xsl:param name="not"           select="'false'"/>
581         <xsl:param name="cook"          select="'false'"/>
582         <xsl:param name="hide"          select="0"/>
583         <xsl:param name="binder"/>
584         
585         <xsl:if test="$binded_params != ''">
586                 <xsl:choose>
587                         <xsl:when test="contains($binded_params,'+')">
588                                 <xsl:call-template name="out_choose_binder">
589                                         <xsl:with-param name="binded_params" select="substring-before($binded_params,'+')"/>
590                                         <xsl:with-param name="not"           select="$not"/>
591                                         <xsl:with-param name="cook"          select="$cook"/>
592                                         <xsl:with-param name="hide"          select="$hide"/>
593                                         <xsl:with-param name="binder"        select="$binder"/>
594                                 </xsl:call-template>
595
596                                 <xsl:call-template name="out_choose_binder">
597                                         <xsl:with-param name="binded_params" select="substring-after($binded_params,'+')"/>
598                                         <xsl:with-param name="not"           select="$not"/>
599                                         <xsl:with-param name="cook"          select="$cook"/>
600                                         <xsl:with-param name="hide"          select="$hide"/>
601                                         <xsl:with-param name="binder"        select="$binder"/>
602                                 </xsl:call-template>
603                         </xsl:when>
604                         <xsl:otherwise>
605                                 <xsl:variable name="param">
606                                         <xsl:call-template name="param">
607                                                 <xsl:with-param name="id"    select="$binded_params"/>
608                                                 <xsl:with-param name="not"   select="$not"/>
609                                                 <xsl:with-param name="cook"  select="$cook"/>
610                                                 <xsl:with-param name="hide"  select="$hide"/>
611                                         </xsl:call-template>
612                                 </xsl:variable>
613
614                                 <oxsl:when test="{concat('name(',$param,') = ',&quot;'LAMBDA'&quot;)}">
615                                         <oxsl:value-of select="{concat($param,$binder)}"/>
616                                 </oxsl:when>
617                         </xsl:otherwise>
618                 </xsl:choose>
619         </xsl:if>
620 </xsl:template>
621
622 <!-- *********************************************************************** -->
623 <!--                     META LANGUAGE FOR MathML                            --> 
624 <!-- *********************************************************************** -->
625         
626 <xsl:template match="mapp">
627         <xsl:param name="c-tag"/>
628         <xsl:param name="cook"  select="'false'"/>
629         <xsl:param name="hide"  select="0"/>
630         <xsl:param name="arity" select="0"/>
631         <xsl:param name="not"   select="'false'"/>
632         
633         <xsl:variable name="helm:xref">
634                 <xsl:choose>
635                         <xsl:when test="@xref">
636                                 <xsl:call-template name="set_attribute">
637                                         <xsl:with-param name="attr"  select="@xref"/>
638                                         <xsl:with-param name="c-tag" select="$c-tag"/>
639                                         <xsl:with-param name="hide"  select="$hide"/>
640                                         <xsl:with-param name="arity" select="$arity"/>
641                                         <xsl:with-param name="not"   select="$not"/>
642                                 </xsl:call-template>
643                         </xsl:when>
644                         <xsl:otherwise>{@id}</xsl:otherwise>
645                 </xsl:choose>
646         </xsl:variable>
647
648         <m:apply helm:xref="{$helm:xref}">
649                 <xsl:call-template name="copy_attributes">
650                         <xsl:with-param name="c-tag"  select="$c-tag"/>
651                         <xsl:with-param name="hide"   select="$hide"/>
652                         <xsl:with-param name="arity"  select="$arity"/>
653                         <xsl:with-param name="not"    select="$not"/>
654                         <xsl:with-param name="ignore" select="'xref'"/>
655                 </xsl:call-template>
656         
657                 <xsl:apply-templates>
658                         <xsl:with-param name="c-tag" select="$c-tag"/>
659                         <xsl:with-param name="cook"  select="$cook"/>
660                         <xsl:with-param name="hide"  select="$hide"/>
661                         <xsl:with-param name="arity" select="$arity"/>
662                         <xsl:with-param name="not"   select="$not"/>
663                 </xsl:apply-templates>
664         </m:apply>
665 </xsl:template>
666
667
668 <xsl:template match="mop">
669         <xsl:param name="c-tag"/>
670         <xsl:param name="cook"  select="'false'"/>
671         <xsl:param name="hide"  select="0"/>
672         <xsl:param name="arity" select="0"/>
673         <xsl:param name="not"   select="'false'"/>
674
675         <!-- set definitonURL attribute -->
676         <xsl:variable name="definitionURL">
677                 <xsl:choose>
678                         <xsl:when test="@definitionURL">
679                                 <xsl:call-template name="set_attribute">
680                                         <xsl:with-param name="attr"  select="@definitionURL"/>
681                                         <xsl:with-param name="c-tag" select="$c-tag"/>
682                                         <xsl:with-param name="hide"  select="$hide"/>
683                                         <xsl:with-param name="arity" select="$arity"/>
684                                         <xsl:with-param name="not"   select="$not"/>
685                                 </xsl:call-template>
686                         </xsl:when>
687                         <xsl:otherwise>
688                                 <xsl:call-template name="op_uri_attr">
689                                         <xsl:with-param name="not"   select="$not"/>
690                                         <xsl:with-param name="c-tag" select="$c-tag"/>
691                                         <xsl:with-param name="const" select="$arity = 0 and $hide = 0"/>
692                                 </xsl:call-template>
693                         </xsl:otherwise>
694                 </xsl:choose>
695         </xsl:variable>
696
697         <!-- set helm:xref attribute -->
698         <xsl:variable name="helm:xref">
699                 <xsl:choose>
700                         <xsl:when test="@xref">
701                                 <xsl:call-template name="set_attribute">
702                                         <xsl:with-param name="attr"  select="@xref"/>
703                                         <xsl:with-param name="c-tag" select="$c-tag"/>
704                                         <xsl:with-param name="hide"  select="$hide"/>
705                                         <xsl:with-param name="arity" select="$arity"/>
706                                         <xsl:with-param name="not"   select="$not"/>
707                                 </xsl:call-template>
708                         </xsl:when>
709                         <xsl:otherwise>
710                                 <xsl:call-template name="op_id_attr">
711                                         <xsl:with-param name="not"   select="$not"/>
712                                         <xsl:with-param name="c-tag" select="$c-tag"/>
713                                         <xsl:with-param name="const" select="$arity = 0 and $hide = 0"/>
714                                 </xsl:call-template>
715                         </xsl:otherwise>
716                 </xsl:choose>
717         </xsl:variable>
718
719         <xsl:element name="{concat('m:',@tag)}">
720                 <xsl:attribute name="definitionURL">
721                         <xsl:value-of select="$definitionURL"/>
722                 </xsl:attribute>
723                 <xsl:attribute name="helm:xref">
724                         <xsl:value-of select="$helm:xref"/>
725                 </xsl:attribute>
726                 
727                 <xsl:call-template name="copy_attributes">
728                         <xsl:with-param name="c-tag"  select="$c-tag"/>
729                         <xsl:with-param name="hide"   select="$hide"/>
730                         <xsl:with-param name="arity"  select="$arity"/>
731                         <xsl:with-param name="not"    select="$not"/>
732                         <xsl:with-param name="ignore" select="'xref + definitionURL + tag'"/>
733                 </xsl:call-template>
734                 
735                 <xsl:apply-templates>
736                         <xsl:with-param name="c-tag" select="$c-tag"/>
737                         <xsl:with-param name="cook"  select="$cook"/>
738                         <xsl:with-param name="hide"  select="$hide"/>
739                         <xsl:with-param name="arity" select="$arity"/>
740                         <xsl:with-param name="not"   select="$not"/>
741                 </xsl:apply-templates>
742         </xsl:element>
743 </xsl:template>
744
745 <xsl:template match="param">
746         <xsl:param name="cook" select="'false'"/>
747         <xsl:param name="hide" select="0"/>
748         <xsl:param name="not"  select="'false'"/>
749
750         <xsl:variable name="param">
751                 <xsl:call-template name="param">
752                         <xsl:with-param name="id"    select="@id"/>
753                         <xsl:with-param name="not"   select="$not"/>
754                         <xsl:with-param name="cook"  select="$cook"/>
755                         <xsl:with-param name="hide"  select="$hide"/>
756                 </xsl:call-template>
757         </xsl:variable>
758
759         <xsl:choose>
760                 <xsl:when test="@bvar">
761                         <oxsl:choose>
762                                 <oxsl:when test="{concat('name(',$param,') = ',&quot;'LAMBDA'&quot;)}">
763                                         <oxsl:apply-templates select="{concat($param,'/target')}" mode="{@mode}"/>
764                                 </oxsl:when>
765                                 <oxsl:otherwise>
766                                         <m:apply>
767                                                 <m:csymbol>app</m:csymbol>
768                                                 <oxsl:apply-templates select="{$param}" mode="{@mode}"/>
769                                                 <m:ci>
770                                                         <xsl:value-of select="@bvar"/>
771                                                 </m:ci>
772                                         </m:apply>
773                                 </oxsl:otherwise>
774                         </oxsl:choose>
775                 </xsl:when>
776                 <xsl:otherwise>
777                         <oxsl:apply-templates select="{$param}" mode="{@mode}"/>
778                 </xsl:otherwise>
779         </xsl:choose>
780 </xsl:template>
781
782 <xsl:template match="m:*">
783         <xsl:param name="c-tag"/>
784         <xsl:param name="cook"  select="'false'"/>
785         <xsl:param name="hide"  select="0"/>
786         <xsl:param name="arity" select="0"/>
787         <xsl:param name="not"   select="'false'"/>
788         
789         <xsl:copy>
790                 <xsl:call-template name="copy_attributes">
791                         <xsl:with-param name="c-tag" select="$c-tag"/>
792                         <xsl:with-param name="hide"  select="$hide"/>
793                         <xsl:with-param name="arity" select="$arity"/>
794                         <xsl:with-param name="not"   select="$not"/>
795                 </xsl:call-template>
796         
797                 <xsl:apply-templates>
798                         <xsl:with-param name="c-tag" select="$c-tag"/>
799                         <xsl:with-param name="cook"  select="$cook"/>
800                         <xsl:with-param name="hide"  select="$hide"/>
801                         <xsl:with-param name="arity" select="$arity"/>
802                         <xsl:with-param name="not"   select="$not"/>
803                 </xsl:apply-templates>
804         </xsl:copy>
805 </xsl:template>
806
807 <xsl:template match="mbvar">
808         <xsl:param name="c-tag"/>
809         <xsl:param name="cook"  select="'false'"/>
810         <xsl:param name="hide"  select="0"/>
811         <xsl:param name="arity" select="0"/>
812         <xsl:param name="not"   select="'false'"/>
813
814         <xsl:variable name="binded_params">
815                 <xsl:call-template name="get_binded_params">
816                         <xsl:with-param name="var"  select="@name"/>
817                         <xsl:with-param name="node" select="following-sibling::*"/>
818                 </xsl:call-template>
819         </xsl:variable>
820
821         <xsl:variable name="test">
822                 <xsl:call-template name="test_on_lambda">
823                         <xsl:with-param name="binded_params" select="$binded_params"/>
824                         <xsl:with-param name="not"           select="$not"/>
825                         <xsl:with-param name="cook"          select="$cook"/>
826                         <xsl:with-param name="hide"          select="$hide"/>
827                 </xsl:call-template>
828         </xsl:variable>
829
830         <xsl:variable name="binder">/target/@binder</xsl:variable>
831
832         <xsl:choose>
833                 <xsl:when test="$binded_params != ''">
834                         <oxsl:variable name="{concat('bvar_',@name)}">
835                                 <oxsl:choose>
836                                         <!-- one or more lambdas exist -->
837                                         <oxsl:when test="{$test}">
838                                                 <xsl:choose>
839                                                         <!-- binded params > 1 (more than 1 lambda) -->
840                                                         <xsl:when test="contains($binded_params,'+')">
841                                                                 <oxsl:variable name="binder">
842                                                                         <oxsl:choose>
843                                                                                 <xsl:call-template name="out_choose_binder">
844                                                                                         <xsl:with-param name="binded_params" select="$binded_params"/>
845                                                                                         <xsl:with-param name="not"           select="$not"/>
846                                                                                         <xsl:with-param name="hide"          select="$hide"/>
847                                                                                         <xsl:with-param name="cook"          select="$cook"/>
848                                                                                         <xsl:with-param name="binder"        select="$binder"/>
849                                                                                 </xsl:call-template>
850                                                                         </oxsl:choose>
851                                                                 </oxsl:variable>
852                                                                 <oxsl:call-template name="insert_subscript">
853                                                                         <oxsl:with-param name="node_value" select="$binder"/>
854                                                                 </oxsl:call-template>
855                                                         </xsl:when>
856                                                         <!-- binded parms = 1 (1 lambda) -->
857                                                         <xsl:otherwise>
858                                                                 <xsl:variable name="param">
859                                                                         <xsl:call-template name="param">
860                                                                                 <xsl:with-param name="id"    select="$binded_params"/>
861                                                                                 <xsl:with-param name="not"   select="$not"/>
862                                                                                 <xsl:with-param name="cook"  select="$cook"/>
863                                                                                 <xsl:with-param name="hide"  select="$hide"/>
864                                                                         </xsl:call-template>
865                                                                 </xsl:variable>
866                                                         
867                                                                 <oxsl:call-template name="insert_subscript">
868                                                                         <oxsl:with-param name="node_value" select="{concat($param,$binder)}"/>
869                                                                 </oxsl:call-template>
870                                                         </xsl:otherwise>
871                                                 </xsl:choose>
872                                         </oxsl:when>
873                                         <!-- no one lambda -->
874                                         <oxsl:otherwise>
875                                                 <xsl:value-of select="@name"/>
876                                         </oxsl:otherwise>
877                                 </oxsl:choose>
878                         </oxsl:variable>
879
880                         <m:bvar>
881                                 <m:ci>
882                                         <oxsl:value-of select="{concat('$bvar_',@name)}"/>
883                                 </m:ci>
884                                 <xsl:apply-templates>
885                                         <xsl:with-param name="c-tag" select="$c-tag"/>
886                                         <xsl:with-param name="cook"  select="$cook"/>
887                                         <xsl:with-param name="hide"  select="$hide"/>
888                                         <xsl:with-param name="arity" select="$arity"/>
889                                         <xsl:with-param name="not"   select="$not"/>
890                                 </xsl:apply-templates>
891                         </m:bvar>
892                 </xsl:when>
893                 <xsl:otherwise>
894                         <m:bvar>
895                                 <m:ci>
896                                         <xsl:value-of select="@name"/>
897                                 </m:ci>
898                                 <xsl:apply-templates>
899                                         <xsl:with-param name="c-tag" select="$c-tag"/>
900                                         <xsl:with-param name="cook"  select="$cook"/>
901                                         <xsl:with-param name="hide"  select="$hide"/>
902                                         <xsl:with-param name="arity" select="$arity"/>
903                                         <xsl:with-param name="not"   select="$not"/>
904                                 </xsl:apply-templates>
905                         </m:bvar>
906                 </xsl:otherwise>
907         </xsl:choose>
908 </xsl:template>
909
910 <xsl:template match="mvar">
911         <xsl:call-template name="out_mvar">
912                 <xsl:with-param name="vname" select="@name"/>
913         </xsl:call-template>
914 </xsl:template>
915
916
917
918 <!-- *********************************************************************** -->
919 <!--                          AUXILIARY FUNCTIONS                            -->
920 <!-- *********************************************************************** -->
921
922
923 <!-- Returns a value if all uris in the list have the same c-tag  -->
924 <xsl:template name="get_c_tag">
925         <xsl:param name="uri" select="''"/>
926         
927         <xsl:if test="$uri != ''">
928                 <xsl:choose>
929                         <xsl:when test="contains($uri,'|')">
930                                 <xsl:variable name="c-tag1">
931                                         <xsl:call-template name="get_c_tag">
932                                                 <xsl:with-param name="uri" select="substring-before($uri,'|')"/>
933                                         </xsl:call-template>
934                                 </xsl:variable>
935                         
936                                 <xsl:variable name="c-tag2">
937                                         <xsl:call-template name="get_c_tag">
938                                                 <xsl:with-param name="uri" select="substring-after($uri,'|')"/>
939                                         </xsl:call-template>
940                                 </xsl:variable>
941
942                                 <xsl:if test="$c-tag1 = $c-tag2">
943                                         <xsl:value-of select="$c-tag1"/>
944                                 </xsl:if>
945                         </xsl:when>
946                         <xsl:otherwise>
947                                 <xsl:choose>
948                                         <xsl:when test="substring($uri,string-length($uri)-3) = '.con'">CONST</xsl:when>
949                                         <xsl:when test="substring($uri,string-length($uri)-3) = '.ind'">MUTIND</xsl:when>
950                                 </xsl:choose>
951                         </xsl:otherwise>
952                 </xsl:choose>
953         </xsl:if>
954 </xsl:template>
955
956 <!-- Creates a list selecting uris according to c-tag specified -->
957 <xsl:template name="select_uris">
958         <xsl:param name="uris" select="''"/>
959         <xsl:param name="c-tag"/>
960
961         <xsl:if test="$uris != ''">
962                 <xsl:choose>
963                         <xsl:when test="contains($uris,'|')">
964                                 <xsl:variable name="list1">
965                                         <xsl:call-template name="select_uris">
966                                                 <xsl:with-param name="uris"  select="substring-before($uris,'|')"/>
967                                                 <xsl:with-param name="c-tag" select="$c-tag"/>
968                                         </xsl:call-template>
969                                 </xsl:variable>
970
971                                 <xsl:variable name="list2">
972                                         <xsl:call-template name="select_uris">
973                                                 <xsl:with-param name="uris"  select="substring-after($uris,'|')"/>
974                                                 <xsl:with-param name="c-tag" select="$c-tag"/>
975                                         </xsl:call-template>
976                                 </xsl:variable>
977
978                                 <xsl:choose>
979                                         <xsl:when test="$list1 != '' and $list2 != ''">
980                                                 <xsl:value-of select="concat($list1,'|',$list2)"/>
981                                         </xsl:when>
982                                         <xsl:when test="$list1 != '' and $list2 = ''">
983                                                 <xsl:value-of select="$list1"/>
984                                         </xsl:when>
985                                         <xsl:when test="$list1 = '' and $list2 != ''">
986                                                 <xsl:value-of select="$list2"/>
987                                         </xsl:when>
988                                 </xsl:choose>
989                         </xsl:when>
990                         <xsl:otherwise>
991                                 <xsl:variable name="c-tag1">
992                                         <xsl:call-template name="get_c_tag">
993                                                 <xsl:with-param name="uri" select="$uris"/>
994                                         </xsl:call-template>
995                                 </xsl:variable>
996
997                                 <xsl:if test="$c-tag1 = $c-tag">
998                                         <xsl:value-of select="$uris"/>
999                                 </xsl:if>
1000                         </xsl:otherwise>
1001                 </xsl:choose>
1002         </xsl:if>
1003 </xsl:template>
1004
1005 <!-- Returns a xpath expression matching on uri attributes -->
1006 <xsl:template name="test_on_uris">
1007         <xsl:param name="uris" select="''"/>
1008
1009         <xsl:if test="$uris != ''">
1010                 <xsl:choose>
1011                         <xsl:when test="contains($uris,'|')">
1012                                 <xsl:variable name="expr1">
1013                                         <xsl:call-template name="test_on_uris"> 
1014                                                 <xsl:with-param name="uris" select="substring-before($uris,'|')"/>
1015                                         </xsl:call-template>
1016                                 </xsl:variable>
1017
1018                                 <xsl:variable name="expr2">
1019                                         <xsl:call-template name="test_on_uris"> 
1020                                                 <xsl:with-param name="uris" select="substring-after($uris,'|')"/>
1021                                         </xsl:call-template>
1022                                 </xsl:variable>
1023
1024                                 <xsl:value-of select="concat($expr1,' or ',$expr2)"/>
1025                         </xsl:when>
1026                         <xsl:otherwise>
1027                                 <xsl:value-of select="concat('@uri=',&quot;'&quot;,$uris,&quot;'&quot;)"/>
1028                         </xsl:otherwise>
1029                 </xsl:choose>
1030         </xsl:if>
1031 </xsl:template>
1032
1033 <!-- Returns a xpath expression testing on LAMBDA node existence -->
1034 <xsl:template name="test_on_lambda">
1035         <xsl:param name="binded_params" select="''"/>
1036         <xsl:param name="not"           select="'false'"/>
1037         <xsl:param name="cook"          select="'false'"/>
1038         <xsl:param name="hide"          select="0"/>
1039         
1040         <xsl:if test="$binded_params != ''">
1041                 <xsl:choose>
1042                         <xsl:when test="contains($binded_params,'+')">
1043                                 <xsl:variable name="expr1">
1044                                         <xsl:call-template name="test_on_lambda">
1045                                                 <xsl:with-param name="binded_params" select="substring-before($binded_params,'+')"/>
1046                                                 <xsl:with-param name="not"           select="$not"/>
1047                                                 <xsl:with-param name="cook"          select="$cook"/>
1048                                                 <xsl:with-param name="hide"          select="$hide"/>
1049                                         </xsl:call-template>
1050                                 </xsl:variable>
1051
1052                                 <xsl:variable name="expr2">
1053                                         <xsl:call-template name="test_on_lambda">
1054                                                 <xsl:with-param name="binded_params" select="substring-after($binded_params,'+')"/>
1055                                                 <xsl:with-param name="not"           select="$not"/>
1056                                                 <xsl:with-param name="cook"          select="$cook"/>
1057                                                 <xsl:with-param name="hide"          select="$hide"/>
1058                                         </xsl:call-template>
1059                                 </xsl:variable>
1060                                 
1061                                 <xsl:value-of select="concat($expr1,' or ',$expr2)"/>
1062                         </xsl:when>
1063                         <xsl:otherwise>
1064                                 <xsl:variable name="param">
1065                                         <xsl:call-template name="param">
1066                                                 <xsl:with-param name="id"    select="$binded_params"/>
1067                                                 <xsl:with-param name="not"   select="$not"/>
1068                                                 <xsl:with-param name="cook"  select="$cook"/>
1069                                                 <xsl:with-param name="hide"  select="$hide"/>
1070                                         </xsl:call-template>
1071                                 </xsl:variable>
1072
1073                                 <xsl:value-of select="concat('name(',$param,') = ',&quot;'LAMBDA'&quot;)"/>                             
1074                         </xsl:otherwise>
1075                 </xsl:choose>
1076         </xsl:if>
1077 </xsl:template>
1078
1079 <!-- Removes white spaces from uris list -->
1080 <xsl:template name="remove_white_spaces">
1081         <xsl:param name="uri" select="''"/>
1082
1083         <xsl:if test="$uri != ''">
1084                 <xsl:choose>
1085                         <xsl:when test="contains($uri,'|')">
1086                                 <xsl:variable name="uri1">
1087                                         <xsl:call-template name="remove_white_spaces">
1088                                                 <xsl:with-param name="uri" select="substring-before($uri,'|')"/>
1089                                         </xsl:call-template>
1090                                 </xsl:variable>
1091
1092                                 <xsl:variable name="uri2">
1093                                         <xsl:call-template name="remove_white_spaces">
1094                                                 <xsl:with-param name="uri" select="substring-after($uri,'|')"/>
1095                                         </xsl:call-template>
1096                                 </xsl:variable>
1097
1098                                 <xsl:value-of select="concat($uri1,'|',$uri2)"/>
1099                         </xsl:when>
1100                         <xsl:otherwise>
1101                                 <xsl:value-of select="normalize-space($uri)"/>
1102                         </xsl:otherwise>
1103                 </xsl:choose>
1104         </xsl:if>
1105 </xsl:template>
1106
1107 <!-- 
1108         Returns a list of params id attributes concatenated with '+'.
1109         The params'id attribute are selected according to the value of bindig variable 'var'  
1110  -->
1111 <xsl:template name="get_binded_params">
1112         <xsl:param name="var"/>
1113         <xsl:param name="node"/>
1114
1115         <xsl:if test="count($node) != 0">
1116                 <xsl:choose>
1117                         <!-- another variable declaration with same name -->
1118                         <xsl:when test="($node[1][name() = 'mbvar']) and ($node[1][@name = $var])"></xsl:when>
1119                         <!-- a binded param -->
1120                         <xsl:when test="($node[1][name() = 'param']) and ($node[1][@bvar = $var])">
1121                                 <!-- search on siblings -->
1122                                 <xsl:variable name="siblings_params">
1123                                         <xsl:call-template name="get_binded_params">
1124                                                 <xsl:with-param name="var"  select="$var"/>
1125                                                 <xsl:with-param name="node" select="$node[position() > 1]"/>
1126                                         </xsl:call-template>
1127                                 </xsl:variable>
1128                                 <xsl:choose>
1129                                         <xsl:when test="$siblings_params != ''">
1130                                                 <xsl:value-of select="concat($node[1]/@id,'+',$siblings_params)"/>
1131                                         </xsl:when>
1132                                         <xsl:otherwise> 
1133                                                 <xsl:value-of select="$node[1]/@id"/>
1134                                         </xsl:otherwise>
1135                                 </xsl:choose>
1136                         </xsl:when>
1137                         <xsl:otherwise>
1138                                 <!-- search on siblings -->
1139                                 <xsl:variable name="siblings_params">
1140                                         <xsl:call-template name="get_binded_params">
1141                                                 <xsl:with-param name="var"  select="$var"/>
1142                                                 <xsl:with-param name="node" select="$node[position() > 1]"/>
1143                                         </xsl:call-template>
1144                                 </xsl:variable>
1145                                 <!-- search on children -->
1146                                 <xsl:variable name="children_params">
1147                                         <xsl:call-template name="get_binded_params">
1148                                                 <xsl:with-param name="var"  select="$var"/>
1149                                                 <xsl:with-param name="node" select="$node[1]/child::*"/>
1150                                         </xsl:call-template>
1151                                 </xsl:variable>
1152
1153                                 <xsl:choose>
1154                                         <xsl:when test="$children_params != '' and $siblings_params != ''">
1155                                                 <xsl:value-of select="concat($children_params,'+',$siblings_params)"/>
1156                                         </xsl:when>
1157                                         <xsl:when test="$children_params != '' and $siblings_params = ''">
1158                                                 <xsl:value-of select="$children_params"/>
1159                                         </xsl:when>
1160                                         <xsl:when test="$children_params = '' and $siblings_params != ''">
1161                                                 <xsl:value-of select="$siblings_params"/>
1162                                         </xsl:when>     
1163                                 </xsl:choose>
1164                         </xsl:otherwise>
1165                 </xsl:choose>
1166         </xsl:if>
1167 </xsl:template>
1168
1169 <!-- Returns a xpath string with the location of the parameter with the id specified -->
1170 <xsl:template name="param">
1171         <xsl:param name="id"/>
1172         <xsl:param name="not"   select="'false'"/>
1173         <xsl:param name="cook"  select="'false'"/>
1174         <xsl:param name="hide"  select="0"/>
1175
1176         <xsl:variable name="apply_not">
1177                 <xsl:if test="$not = 'true'">*[2]/</xsl:if>
1178         </xsl:variable>
1179
1180         <xsl:variable name="no_params_var">
1181                 <xsl:if test="$cook = 'true'">$no_params+</xsl:if>
1182         </xsl:variable>
1183
1184         <xsl:value-of select="concat($apply_not,'*[',$no_params_var,$id + $hide + 1,']')"/>
1185 </xsl:template>
1186
1187 <!-- Returns a xpath string with the location of the operator uri attribute -->
1188 <xsl:template name="op_uri_attr">
1189         <xsl:param name="not"   select="'false'"/>
1190         <xsl:param name="c-tag"/>
1191         <xsl:param name="const" select="'false'"/>
1192
1193         <xsl:call-template name="op_attr">
1194                 <xsl:with-param name="attr_type" select="'@uri'"/>
1195                 <xsl:with-param name="not"       select="$not"/>
1196                 <xsl:with-param name="c-tag"     select="$c-tag"/>
1197                 <xsl:with-param name="const"     select="$const"/>
1198         </xsl:call-template>
1199 </xsl:template>
1200
1201 <!-- Returns a xpath string with the location of the operator id attribute -->
1202 <xsl:template name="op_id_attr">
1203         <xsl:param name="not"  select="'false'"/>
1204         <xsl:param name="c-tag"/>
1205         <xsl:param name="const" select="'false'"/>
1206         
1207         <xsl:call-template name="op_attr">
1208                 <xsl:with-param name="attr_type" select="'@id'"/>
1209                 <xsl:with-param name="not"       select="$not"/>
1210                 <xsl:with-param name="c-tag"     select="$c-tag"/>
1211                 <xsl:with-param name="const"     select="$const"/>
1212         </xsl:call-template>
1213 </xsl:template>
1214         
1215
1216 <!-- Returns a xpath string with the location of the operator uri or id attribute -->
1217 <xsl:template name="op_attr">
1218         <xsl:param name="attr_type"/>
1219         <xsl:param name="not"  select="'false'"/>
1220         <xsl:param name="c-tag"/>
1221         <xsl:param name="const" select="'false'"/>
1222
1223         <xsl:variable name="apply">
1224                 <xsl:if test="$not = 'true'">APPLY/</xsl:if>
1225         </xsl:variable>
1226         
1227         <xsl:choose>
1228                 <xsl:when test="$const = 'true'">
1229                         <xsl:value-of select="concat('{',$attr_type,'}')"/>     
1230                 </xsl:when>
1231                 <xsl:otherwise>
1232                         <xsl:value-of select="concat('{',$apply,$c-tag,'/',$attr_type,'}')"/>                   
1233                 </xsl:otherwise>
1234         </xsl:choose>
1235 </xsl:template>
1236
1237 <xsl:template name="copy_attributes">
1238         <xsl:param name="c-tag"/>
1239         <xsl:param name="hide"   select="0"/>
1240         <xsl:param name="arity"  select="0"/>
1241         <xsl:param name="not"    select="'false'"/>
1242         <xsl:param name="ignore" select="''"/>
1243         
1244         <xsl:variable name="test">
1245                 <xsl:call-template name="test_on_attributes">
1246                         <xsl:with-param name="names" select="$ignore"/>
1247                 </xsl:call-template>
1248         </xsl:variable>
1249         
1250         <xsl:for-each select="@*">
1251                 <xsl:if test="contains($test,concat('+',name(),'+')) = false()">
1252                         <xsl:attribute name="{name()}">
1253                                 <xsl:call-template name="set_attribute">
1254                                         <xsl:with-param name="attr"  select="."/>
1255                                         <xsl:with-param name="c-tag" select="$c-tag"/>
1256                                         <xsl:with-param name="hide"  select="$hide"/>
1257                                         <xsl:with-param name="arity" select="$arity"/>
1258                                         <xsl:with-param name="not"   select="$not"/>
1259                                 </xsl:call-template>
1260                         </xsl:attribute>
1261                 </xsl:if>
1262         </xsl:for-each>
1263 </xsl:template>
1264
1265 <xsl:template name="test_on_attributes">
1266         <xsl:param name="names" select="''"/>
1267
1268         <xsl:choose>
1269                 <xsl:when test="contains($names,'+')">
1270                         <xsl:variable name="name">
1271                                 <xsl:call-template name="test_on_attributes">
1272                                         <xsl:with-param name="names" select="normalize-space(substring-after($names,'+'))"/>
1273                                 </xsl:call-template>
1274                         </xsl:variable>
1275
1276                         <xsl:value-of select="concat('+',normalize-space(substring-before($names,'+')),$name)"/>        
1277                 </xsl:when>
1278                 <xsl:otherwise>
1279                         <xsl:value-of select="concat('+',normalize-space($names),'+')"/>
1280                 </xsl:otherwise>
1281         </xsl:choose>
1282 </xsl:template>
1283
1284 <xsl:template name="set_attribute">
1285         <xsl:param name="attr"/>
1286         <xsl:param name="c-tag"/>
1287         <xsl:param name="hide"  select="0"/>
1288         <xsl:param name="arity" select="0"/>
1289         <xsl:param name="not"   select="'false'"/>
1290         
1291         <xsl:choose>
1292                 <xsl:when test="$attr = '$APP-ID'">{@id}</xsl:when>
1293                 <xsl:when test="$attr = '$OP-ID' or $attr = '$OP-URI'">
1294                         <xsl:variable name="attr_type">
1295                                 <xsl:choose>
1296                                         <xsl:when test="$attr = '$OP-ID'">@id</xsl:when>
1297                                         <xsl:otherwise>@uri</xsl:otherwise>
1298                                 </xsl:choose>
1299                         </xsl:variable>
1300
1301                         <xsl:call-template name="op_attr">
1302                                 <xsl:with-param name="attr_type" select="$attr_type"/>
1303                                 <xsl:with-param name="not"       select="$not"/>
1304                                 <xsl:with-param name="c-tag"     select="$c-tag"/>
1305                                 <xsl:with-param name="const"     select="$arity = 0 and $hide = 0"/>
1306                         </xsl:call-template>
1307                 </xsl:when>
1308                 <xsl:otherwise>
1309                         <xsl:value-of select="$attr"/>
1310                 </xsl:otherwise>
1311         </xsl:choose>
1312 </xsl:template>
1313
1314 </xsl:stylesheet>