[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

[exsl] Global variables in functions

Subject: [exsl] Global variables in functions
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 26 Feb 2001 11:32:52 +0000
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.