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