473,770 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mimicking a SELECT/CASE statement using XSL

as a newbie to XSL, is it possible to mimic a SELECT/CASE statement
using
XSL?

I tried a quickie and I kept getting errors either using PARAM or
WITH-PARAM
in the wrong place or VARIABLE. I ended up using .createProcesso r and
doing
all the work behind the scenes in my programming language, then using
the
..addParameter to pass the values.

I wanted to select data, then set variables using XSL:CHOOSE and
XSL:IF based
on the values found in the data, then further alter these farther down
in the XSL with math.

pseudo-code:

xml:
<main class="1">

XSL Logic...

if class == 1

xsl-var1 = 10
xsl-var2 = 20

else

xsl-var1 = 50
xsl-var2 = 60

endif

myNewNumber = "value-of xsl-var1 + value-of xsl-var2"

'convert myNewNumber to kilograms (was pounds)

myNewNumber = myNewNumber * 2.2

etc, etc.

I'm not sure the value of a XSL:VARIABLE can be redefined.

sorry for the fuzziness, any help is greatly appreciated.
Jul 20 '05 #1
2 10953
In article <ff************ **************@ posting.google. com>,
Gadrin77 <ga*****@aol.co m> wrote:

% as a newbie to XSL, is it possible to mimic a SELECT/CASE statement
% using
% XSL?

Yes.

% I tried a quickie and I kept getting errors either using PARAM or
% WITH-PARAM
% in the wrong place or VARIABLE.

With is nothing to do with the former question. Yes, there's something
like a select (xsl:choose), and no, it doesn't change the scoping
rules for variables.

<xsl:variable name='xsl-var1'>
<xsl:choose>
<xsl:when test='$class = 1'><xsl:text>10 </xsl:text></xsl:if>
<xsl:otherwise> <xsl:text>20</xsl:text></xsl:if>
</xsl:choose>
</xsl:variable name='xsl-var1'>

% I'm not sure the value of a XSL:VARIABLE can be redefined.

It can't be. You can get the same effect using parameters and
recursive template calls. You could also use recursive calls to
solve your initial problem.

<xsl:choose>
<xsl:when test='$class = 1'>
<xsl:call-template name='guts'>
<xsl:with-param name='xsl-var1' select='10'/>
<xsl:with-param name='xsl-var2' select='11'/>
</xsl:call-template>
</xsl:when>
<xsl:otherwis e>
<xsl:call-template name='guts'>
<xsl:with-param name='xsl-var1' select='20'/>
<xsl:with-param name='xsl-var2' select='21'/>
</xsl:call-template>
<'xsl:otherwise >
</xsl:choose>

then you'd use the parameters in a template called guts.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.c om
Jul 20 '05 #2
In addition to Patrick's comments, it's worth adding that XSLT follows
what's known as a "functional programming" paradigm, very different to
procedural programming (mainly in that variables can't be updated which at
first seems crazy to a traditional programmer)

If you aren't familiar with functional programming, I'd recommend you try
and get your head round these concepts so you can understand how to use
recursion in templates (Jeni Tennision's "beginning XSLT" is very good book
but I'm sure there are others)

Andy
"Gadrin77" <ga*****@aol.co m> wrote in message
news:ff******** *************** ***@posting.goo gle.com...
as a newbie to XSL, is it possible to mimic a SELECT/CASE statement
using
XSL?

I tried a quickie and I kept getting errors either using PARAM or
WITH-PARAM
in the wrong place or VARIABLE. I ended up using .createProcesso r and
doing
all the work behind the scenes in my programming language, then using
the
.addParameter to pass the values.

I wanted to select data, then set variables using XSL:CHOOSE and
XSL:IF based
on the values found in the data, then further alter these farther down
in the XSL with math.

pseudo-code:

xml:
<main class="1">

XSL Logic...

if class == 1

xsl-var1 = 10
xsl-var2 = 20

else

xsl-var1 = 50
xsl-var2 = 60

endif

myNewNumber = "value-of xsl-var1 + value-of xsl-var2"

'convert myNewNumber to kilograms (was pounds)

myNewNumber = myNewNumber * 2.2

etc, etc.

I'm not sure the value of a XSL:VARIABLE can be redefined.

sorry for the fuzziness, any help is greatly appreciated.

Jul 20 '05 #3

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

Similar topics

17
14644
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to allow entry to one or the other or Both at the same time. Now I tried to use an If ElseIf but it got too hard to track, so now I am using a SELECT CASE Statement.
15
2742
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to start at the bottom. What seems to plague many ORM systems is the syntactic confusion and string-manipulation required to build the SQL Statements. If you want to do a Left Outer Join, support nested functions, and a nested conditional clause, you'd...
3
6472
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
7
9338
by: Lauren Quantrell | last post by:
Is there any speed/resource advantage/disadvantage in using Select Case x Case 1 Case 2 etc. many more cases... End Select VS.
3
19741
by: pgraeve | last post by:
I am a convert from VB to C# so bear with me on this "conversion" question C# switch statement seems to be the closest relative to VB's Select Case. I used VB's Select Case statement liberally. Now I find myself wanting to use "Select Case" i.e., "switch" in C# regularly, but I always have to find another way b/c C#'s switch statement only allows static or integral variables. For example, I often want to use a switch statement based on the...
3
3398
by: mark.irwin | last post by:
Hello all, Have an issue where a redirect pushes data to a page with a select case which then redirects to another page. Problem is the redirect isnt working in 1 case. Code below: strURL = "" if i = 1 then strURL = "redirect.aspx?page=APIQ&parcel=" & strParcel &
8
4722
by: | last post by:
Hello, This is gonna sound real daft, but how do I test a Select Case statement for variants of a theme? Here's a snippet of my code... Select Case sUsr Case "Guest", "TsInternetUser", "krbtgt", "quality7" ' don't show
1
21687
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case "01" : dWarrExpDateMonth="Jan" : dRetailDateMonth="Jan" case "02" : dWarrExpDateMonth="Feb" : dRetailDateMonth="Feb" End Select
21
17454
beacon
by: beacon | last post by:
Hello to everybody, I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know), but each answer is given a different point value for each question. For instance, question 1 might ask "Do you like candy?" and if you answer Yes you will get +1, No will earn you -1, and Don't know will net you zero points. The next question might...
0
9591
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
10228
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...
1
10002
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
9869
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7415
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
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
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
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
3575
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.