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

Re: recursive passing parameter

Subject: Re: recursive passing parameter
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 07 Sep 1999 13:05:35 -0400
xsl parameter recursion
At 99/09/07 11:50 -0400, Honglin Su wrote:
I want the following stylesheet to produce an output like this:

 The variable value before passing is:: init value ...
 The variable value after passing is :: A1
 The variable value before passing is:: A1
 The variable value after passing is :: B1
 The variable value before passing is:: B1
...
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
<xsl:variable name="var" select="'init value ...'" />
<!-- process the children recursively -->
<xsl:template match="*">
 The variable value before passing is:: <xsl:value-of select="$var"/>
 <xsl:param name="var" select="name(.)"/>
 The variable value after passing is :: <xsl:value-of select="$var"/>
 <xsl:apply-templates/>
</xsl:template>
...
But the actually output is that every before passing value is 'init
value ...". What's wrong with my stylesheet?

The stylesheet is giving you what you are asking for because the scope of "$var" at the beginning of <xsl:template> is the globally scoped variable, not the locally scoped variable.


Once you declare the $var within the template, subsequent references in that template are to that locally scoped variable.

Perhaps your misunderstanding is the expectation that the value of the variable $var actually varies ... it does not vary. The <xsl:param> is declaring a variable and is supplying a default value to bind to that variable if the <xsl:apply-templates> or <xsl:call-templates> doesn't provide a <xsl:with-param> value as an overriding value to bind.

Once a value is bound to the variable, it does not change.

What you are seeing is a question of the scope of your variable reference, not an issue of variable values.

I hope this helps.

............ Ken



--
G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Website:  XSL/XML/DSSSL/SGML services, training, libraries, products.
Practical Transformation Using XSLT and XPath      ISBN 1-894049-01-2
Next instructor-led training:  1999-09-24, 1999-11-08, 1999-12-05/06,
                             1999-12-07, 2000-02-27/28, 2000-05-11/12



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.