473,503 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT variable/param question

I want to do this:

<xsl:template>
<xsl:choose>
<xsl:when>
Calculate a value.
<xsl:otherwise>
Calculate a value differently
</xsl:choose>
Use the value I calculated in a couple of different places
</xsl:template>

I can't wrap my head around how to do this. I'm desperate to do this
whole thing in XSLT, but I'm despairing that it may just not be
possible.

Is there a solution that would accomplish something like this?

Jan 10 '07 #1
2 1900
The trick that most beginners miss is that you need to turn this inside
out -- since XSL variables are single-assignment, you need to think in
terms of computing a conditional value rather than conditionally
computing a value. For example:

<xsl:variable name="foo">
<xsl:choose>
<xsl:when>
Calculate a value.
<xsl:otherwise>
Calculate a value differently
</xsl:choose>
</xsl:variable>

rather than trying to do separate variable assignments in the two
branches of the choose.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jan 10 '07 #2
That is genius.

I can't thank you enough. That helps me not only in this current
situation, but helps me understand XSLT even better. I appreciate it.
Joseph Kesselman wrote:
The trick that most beginners miss is that you need to turn this inside
out -- since XSL variables are single-assignment, you need to think in
terms of computing a conditional value rather than conditionally
computing a value. For example:

<xsl:variable name="foo">
<xsl:choose>
<xsl:when>
Calculate a value.
<xsl:otherwise>
Calculate a value differently
</xsl:choose>
</xsl:variable>

rather than trying to do separate variable assignments in the two
branches of the choose.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jan 11 '07 #3

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

Similar topics

6
2886
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
5
9521
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
9
12616
by: Eric Anderson | last post by:
Got a quick question trying to figure out the XSLT way of implementing the functionality of associative arrays. Basically want I want to do is the following: <xsl:template name="foo">...
1
1770
by: Scott | last post by:
The following is the XML I have to work with. Below is the question <Table0> <CaseID>102114</CaseID> <CaseNumber>1</CaseNumber> <DateOpened>2005-06-14T07:26:00.0000000-05:00</DateOpened>...
12
3381
by: Keith Chadwick | last post by:
I have a fairly hefty XSLT file that for the sake of debugging and clarity I wish to split into some separate sub-templates contained within the same file. The master template calls an...
2
1828
by: Michael Hamm | last post by:
I have the following XML file (simplified from the actual): <r> <o><n>1</n><si>s</si><v1>1</v1><v2>2</v2><v3>3</v3></o> <o><n>2</n><si>i</si><v1>4</v1><v2>5</v2><v3>6</v3></o>...
3
1740
by: Carles Company Soler | last post by:
Hello, I want to calculate the value of an attribute. For example <rect x="2+3" y="12"and be <rect x="5" y="12">. Is it possible using XSLT? Thanks!
10
2295
by: olivier.scalbert | last post by:
Hello, the following constraints: source: <Source> <Item>AAA</Item> <Item>BBBBBBBBBBB</Item> <Item>CCCCCCCCC</Item> <Item>DDDDDDDDDDDDDDD</Item>
4
3096
by: Zachary Turner | last post by:
Let's say I have a variable defined as follows: <xsl:variable name="test_variable_1" value="'test_value_A'"/> <xsl:variable name="test_variable_2" value="'test_value_B'"/> <xsl:variable...
3
9537
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.