473,657 Members | 2,776 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:otherwis e>
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 1907
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:otherwis e>
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:otherwis e>
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
2909
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 this, and came across a problem that I haven't been able to solve elegantly. The problem is to find "linker" vertexes that a pair of verteces from a pre-defined set. For example, if the graph verteces represent cities and edges represent flights...
5
9546
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 where node ordering matters, and also the case where it doesn't, but perhaps that is an advanced topic). Ideally the method should be available to xpath expressions, so I think that creating new templates which compare nodes will not work (well,...
9
12626
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"> <xsl:param name="bar"/> <xsl:choose> <xsl:when test="$bar = 'a'">b</xsl:when> <xsl:when test="$bar = 'c'">d</xsl:when> <xsl:when test="$bar = 'e'">f</xsl:when>
1
1783
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> <OnCallPerson /> <CallType>Exposure</CallType> <ExposureReason>General</ExposureReason> <OtherExposureReason>Unintentional</OtherExposureReason> <ClientName>Test Client</ClientName>
12
3406
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 apply-templates and passes a node set to it. This template in turn defines approximately 15 variables that dictate how the following template should proceed. Pseudo example: <!-- Root transformation called via .NET XSLTransform()--> <xsl:template...
2
1861
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> <o><n>3</n><si>s</si><v1>7</v1><v2>8</v2><v3>9</v3></o> <o><n>5</n><si>i</si><v1>10</v1><v2>11</v2><v3>12</v3></o> <o><n>6</n><si>i</si><v1>13</v1><v2>14</v2><v3>15</v3></o> </r>
3
1744
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
2310
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
3100
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 name="test_variable_3" value="'test_value_C'"/> Then, somewhere else in my source document I have some elements like this: <some-doc-element param="2"/>
3
9584
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 difference between two source documents and output node-sets which are "different" (changed or new) to new XML files using xsl:result-document To describe the problem I have provided some example data below along with my a portion of my current...
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4168
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2735
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 we have to send another system
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.