Altova Mailing List Archives

Re: [xsl] How to define a global parameter and change its value

From: "Thomas B. Passin" <tpassin@------------>
Date: 2/13/2002 7:54:00 AM
[Chi Lin]

> I would like to use a value from one of my template to pass to a
> different template.
> I tried to declare a global parameter and assign the value in the
> template, so I can use it in a different template.
> I can assign the value for the parameter in the template, but the
> following template can not pick the changed value.  It still contains
> the original value that I have initialized.  It seems to me that the
> "global parameter" does not really work, the local one is always
> "shadow" the global one.
> Is there anyway that I can change the global parameter's value after it
> has been declared, and used in different templates?

Once a variable or parameter has been assigned within its scope, it cannot
be changed. Once created, it is read-only, as you have found.  But that does
not mean you cannot achieve what you want.  You say that you want to assign
the value of the parameter in a template and pass it to another template.
You can do that without using a global template.

A parameter can be declared again each time a template is instantiated
because it is in a different scope each time (that is, the scope of the
instantiated template).  A typical way to do this is like so:

<xsl:template match='...'>
    <xsl:apply-templates select='xxx'><!--or xsl:call-template-->
        <xsl:with-param name='yyy' select='....'/>

<!-- In the called template, pick up the parameter like this:-->
<xsl:template match='xxx'>
    <xsl:param name='yyy'/>
    <!--rest of template goes here-->

The point to to always create and pass a parameter each time you need it.
This even works when you call a template recursively (i.e., a template calls

This approach does what you said you want to do.


Tom P

 XSL-List info and archive:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.