|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] [exsl] Global variables in functions
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








