472,993 Members | 2,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

xsl:variable is Constant or really Variable?

Hi everybody there,
I've declared a <xsl:variable name="something" select="999"/> in my
xslt and when I want to set another value in it (with same syntax) I
get error the variable "something" has been declared previously. I
couldn't find a way to change it's value. It seems it is constant.
Is there any alternative way?

Thanks in Advance
Afshar

Jun 25 '06 #1
5 6273


Afshar Mohebbi wrote:

I've declared a <xsl:variable name="something" select="999"/> in my
xslt and when I want to set another value in it (with same syntax) I
get error the variable "something" has been declared previously. I
couldn't find a way to change it's value. It seems it is constant.
Is there any alternative way?


XSLT is a pure functional language so you can bind a value to a variable
once but not change that afterwards.
As for alternative ways, what exactly are you trying to achieve?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 25 '06 #2
In XSLT, all variables are single-assignment. You can mask them with
another variable having the same name in a deeper scope, but when you
exit that scope you're looking at the original variable again. (This is
a direct consequence of XSLT being designed as a pure functional
language, which has implications for efficiency.)

Yes, this requires that you change your coding style to fit the
language's capabilities.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jun 25 '06 #3
Dear Repliers!

It's the case I'm working on:
<xsl:choose>
<xsl:when test="viewheaderparameter_id = 32000">

AddViewParameter(0,viwsecPageContent,hdrprmPers onelId"<xsl:value-of
select="normalize-space(viewparameter_htmlcalssname)"/>", <xsl:value-of
select="viewparameter_flags"/> );
</xsl:when>
<xsl:when test="viewheaderparameter_id = 32001">

AddViewParameter(0,viwsecPageContent,hdrprmPers onelName"<xsl:value-of
select="normalize-space(viewparameter_htmlcalssname)"/>", <xsl:value-of
select="viewparameter_flags"/> );
</xsl:when>
<!--more when .... -->
</xsl:choose>

I'm genrating JScript code from an XML. Based on the value of
"viewheaderparameter_id" I should generate "AddViewParameter" function
with deifferent arguments. It's 3rd argument (hdrprmPersonelId,
hdrprmPersonelName, ...) must change in each xsl:when.

I don't want to repeat entire "AddViewParameter(..", instead to set a
variable in each xsl:when and finally produce my desired function...
Regards,
Afshar Mohebbi

Joe Kesselman wrote:
In XSLT, all variables are single-assignment. You can mask them with
another variable having the same name in a deeper scope, but when you
exit that scope you're looking at the original variable again. (This is
a direct consequence of XSLT being designed as a pure functional
language, which has implications for efficiency.)

Yes, this requires that you change your coding style to fit the
language's capabilities.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry


Jun 26 '06 #4
> I don't want to repeat entire "AddViewParameter(..", instead to set a
variable in each xsl:when and finally produce my desired function...


Try something like this:

<xsl:variable name="foo" ><xsl:choose>
<xsl:when test="viewheaderparameter_id = 32000">param1,
param2</xsl:when>
<xsl:when test="viewheaderparameter_id = 32001">param1, param2,
param3</xsl:when>
</xsl:choose></xsl:variable>

AddViewParameter(0,viwsecPageContent,hdrprmPers onelId"<xsl:value-of
select="normalize-space( $foo )"/>", <xsl:value-of
select="viewparameter_flags"/> );

You can set the value of an XSL variable as often as you like, to as
many different values as you like. The trick is that each instance must
be within a different scope (effectively the XML nesting level within
your XSL stylesheet).

Note here that I've embedded the <xsl:choose> within the <xsl:variable>
This is because doing it the other way round would be a much more
obvious way to set the variable, but it would also limit its scope so
much that its value couldn't be accessed from outside the <xsl:choose>.

Jun 26 '06 #5
Hi Andy!

That's a really nice trick! Thank you very much!

Afshar
Andy Dingley <di*****@codesmiths.com> wrote:
I don't want to repeat entire "AddViewParameter(..", instead to set a
variable in each xsl:when and finally produce my desired function...


Try something like this:

<xsl:variable name="foo" ><xsl:choose>
<xsl:when test="viewheaderparameter_id = 32000">param1,
param2</xsl:when>
<xsl:when test="viewheaderparameter_id = 32001">param1, param2,
param3</xsl:when>
</xsl:choose></xsl:variable>

AddViewParameter(0,viwsecPageContent,hdrprmPers onelId"<xsl:value-of
select="normalize-space( $foo )"/>", <xsl:value-of
select="viewparameter_flags"/> );

You can set the value of an XSL variable as often as you like, to as
many different values as you like. The trick is that each instance must
be within a different scope (effectively the XML nesting level within
your XSL stylesheet).

Note here that I've embedded the <xsl:choose> within the <xsl:variable>
This is because doing it the other way round would be a much more
obvious way to set the variable, but it would also limit its scope so
much that its value couldn't be accessed from outside the <xsl:choose>.


Jun 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Xeon | last post by:
Hi, I'm trying this code snippet below but the parser (sablotron) returns error : <xsl:choose> <xsl:when test="some test case"> <xsl:variable name="test" select="0"/> </xsl:when>...
4
by: sylvain.loiseau | last post by:
Hello Given a node set, I try to compute the total of the string-length value of each node. For instance, with : <xsl:for-each select="//q"> <!-- the length of each node is compute with:...
2
by: Richard | last post by:
Suppose I create a variable named "var" such as: <xsl:variable name="var">VarValue</xsl:variable> and then I want to insert its value into an attribute <Element attr=" {the value of var} "> so...
10
by: Tjerk Wolterink | last post by:
The following code does not work: <xsl:variable name="width" select="form:image-width"/> <xsl:if test="$width>$max_image_width"> <xsl:variable name="width" select="$max_image_width"/> </xsl:if>...
1
by: schaf | last post by:
Hello NG ! I have a big problem. I would like to go through a xml file in a xsl:for-each statement. for-each entry (ID) in the XML file i would like to call an xsl:function, which returns a...
1
by: ms_chika | last post by:
Please help! I just want to know how can i pass the return value of a javascript function to a xsl variable. I have an xsl file and from that file i will call a javascript function then the...
2
by: sucheta.phatak | last post by:
Hello, I am trying to use XSLT. Here is the problem that I am facing. My XML file: <Book level="1" name="Mapplicationtoc1"> ....... Some more tags </Book>
2
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer description follows: What I want to do is to be...
0
by: Markchivs | last post by:
Hi all, I wonder if anyone can shed any light on this problem for me? In the following code I'm trying to set a variable called 'atts' with a node set of attributes which will include the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.