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

Re: How to define a global parameter and change its va

Subject: Re: How to define a global parameter and change its value
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Wed, 13 Feb 2002 12:56:47 -0500
defining a global company
[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:  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.