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

Subject: Re: [xsl] How to define a global parameter and change its value
From: "Chi Lin" <chi_lin@xxxxxxxxxxxxxxx>
Date: Wed, 13 Feb 2002 13:19:44 -0700
Thanks Tom,

I found another way to assign value for a global parameter which takes value
from one specific element in the XML file.

This is line I used:    <xsl:param name="className" select="//Class"/>
The information I was looking for is the value in <Class>value</Class> to be
used in one template.

It works for me now.  Thanks for all the people who responded.



"Thomas B. Passin" wrote:

> [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='....'/>
>     </xsl:apply-templates.
> </xsl:template>
> <!-- In the called template, pick up the parameter like this:-->
> <xsl:template match='xxx'>
>     <xsl:param name='yyy'/>
>     <!--rest of template goes here-->
> </xsl:template>
> 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
> itself).
> This approach does what you said you want to do.
> Cheers,
> Tom P
>  XSL-List info and archive:

 XSL-List info and archive:

Current Thread