Re: [xsl] Initializing global variables

Subject: Re: [xsl] Initializing global variables
From: Peter Davis <pdavis152@xxxxxxxxx>
Date: Wed, 5 Jun 2002 03:59:28 -0700
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 05 June 2002 01:49, trang_nguyen@xxxxxxxxxxx wrote:
> I understand that the value of a variable cannot be modified once it has

[Semantic nitpicking: *all* variables, global or not, cannot be modified -- 
only "covered up" by local declarations]

> been assigned, but is it possible to allocate a global variable at the
> start of a stylesheet and then assign it a value at a later time, such as
> within a named template?
>
> Example (doesn't work since notepadDesc is treated as a local variable in
> portFreqTemplate):
>...

There is no way to make your example work, because allocating a global 
variable with no value is the same thing as, well, assigning it to the empty 
string/node-set.  Your analysis is correct, but there is no way around it.

The way most people achieve what you want is to move the call to the template 
that outputs the value into the variable declaration itself:

<xsl:variable name="notepadDesc">
  <xsl:call-template name="portFreqTemplate">
    <xsl:with-param name="portFreqParam"
      select="/path/to/portFreqParam"/>
  </xsl:call-template>
</xsl:variable>

Sorry, but there is no other way to do it, unless you want to do some 
preprocessing of the source XML by an external program and pass the value as 
a stylesheet param.

- -- 
Peter Davis
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8/e8SNSZCJx7tYycRAvpzAKCVtKuhNy/KV/sxX2JLiDrYwEAFcgCgm9j0
s8yjKw8ql2sfUugvELSy7PE=
=NSjT
-----END PGP SIGNATURE-----


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread