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

Re: Retaining value of a Global variable

Subject: Re: Retaining value of a Global variable
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 16 Jul 2004 18:41:25 -0400
global variable in xslt
Vivek,

At 05:04 PM 7/16/2004, you wrote:
In the second template when I print whead before the <img> it shows 'No' for all articles even if I set it to 'Yes' after the <img>. Any clues on how to retain the value of the variable?

You can't. Why do you want to?


This isn't just a flippant question. Depending on your honest response, we (well, someone: I'm shortly heading home) can give you an honest XSLT answer to your real question. It will probably be easier than trying to use a variable.

When thinking "variable" in XSLT (as David C our resident mathematician sometimes has to remind us) you should think "algebra" not "FORTRAN". In conventional algebra, the statement "x=x+1" is really meaningless (and it's a good thing too). XSLT is a functional or quasi-functional language (think of the stylesheet as a function that maps the input to an output), and most of (ideally, all) the state-maintenance, for which variables are so heavily used in other technologies, is handled under the hood by the processor. Less work for us.

So your global variable hasn't been reinitialized. Rather, when the local variable that shadows it goes out of scope, it is revealed again for what it is.

In XSLT if you *really* need a counter or something to pass state between your templates, you can use a parameter. Five times out of six, this is not necessary -- which is why we have to ask what you want to achieve with your variable, to guide you to the better answer.

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

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.