|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: how to reassign a variable's 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








