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

Re: how to reassign a variable's value?

Subject: Re: how to reassign a variable's value?
From: "Charles Knell" <cknell@xxxxxxxxxx>
Date: Mon, 12 Aug 2002 13:56:10 -0700
xsl variable value
>You can't change the value of a variable in XSLT [...].
> 
> This must be one of the most frequently asked questions, and for a
> good
> reason. Haven't anyone ever proposed renaming <xsl:variable> to
> <xsl:constant>? To me, the essence of a "variable" is that it can change
> its value. This deserves to be one of the most frequently proposals.


The value of an XSLT variable can, and often does, change. Just not in
the same context where it was defined. A variable gets to have a value
assigned exatcly once in a given context. When the context node changes,
a new value will be assigned.

If you have a data file like this:

<root>
  <house>
    <location></location>
    <size></size>
    <value></value>
  </house>
  <house>
    <location></location>
    <size></size>
    <value></value>
  </house>
  <house>
    <location></location>
    <size></size>
    <value></value>
  </house>
</root>

and a template in your XSLT file like this:

<template match="house">
  <xsl:variable name="unitPrice" select="value div size" />
  <td><xsl:value-of select="location" /></td><td><xsl:value-of select="$unitPrice"
/></td>
</template>

every time that template is matched, the value of $unitPrice will vary,
so that it is no more a variable than it is a constant. It is constant
within a context and variable between contexts. "Varinstant", perhaps?
-- 
Charles Knell
cknell@xxxxxxxxxx - email
 

 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.