|
Subject: [xsl] [exsl] Global variables in functions From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Mon, 26 Feb 2001 11:32:52 +0000 |
Hi,
As you are no doubt aware, variable references can't be used in the
'match' attribute on xsl:template or the 'match' or 'use' attributes
on xsl:key. I'm not sure exactly why (perhaps someone can enlighten
me?) but I guess it's to do with not having template match patterns or
key values determined dynamically and that the restriction is a good
one.
Now, when we introduce extension functions we might have a problem.
What if we have:
<!-- global parameter for language -->
<xsl:param name="lang" select="'en'" />
<!-- function that tests whether the context node is in the language
specified by the global parameter -->
<exsl:function name="my:in-selected-language">
<exsl:return select="lang($lang)" />
</exsl:function>
<!-- template that matches para elements for which the
my:in-selected-language() function returns true -->
<xsl:template match="para[my:in-selected-language()]">
...
</xsl:template>
In essence, this is the same as:
<xsl:template match="para[lang($lang)]">
...
</xsl:template>
but legal.
There are two solutions that I can see:
1. ban using global variables in functions altogether
2. ban using global variables in functions that are called from the
'match' attribute on xsl:template or the 'match' or 'use'
attributes of xsl:key
I'm tempted by 1. for simplicity. After all, the values of global
variables can be passed into functions if they need them, and I think
that would encourage standalone functions. Either way, it has to be a
dynamic constraint: an XSLT function can't define a variable that has
as its content a call to a template that uses a global variable, for
example.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Re: [exsl] Re: Draft 0.1 , cutlass | Thread | [xsl] [exsl] Global variables in fu, Tobias Reif |
| [xsl] Re: [exsl] Re: Draft 0.1 - ca, Dimitre Novatchev | Date | [xsl] Re: [exsl] Re: Draft 0.1 - ca, Jeni Tennison |
| Month |