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