473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 .createProcessor 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 10914
In article <ff**************************@posting.google.com >,
Gadrin77 <ga*****@aol.com> 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:otherwise>
<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.com
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.com> wrote in message
news:ff**************************@posting.google.c om...
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 .createProcessor 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
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...
15
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...
3
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...
7
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
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. ...
3
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 =...
8
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",...
1
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...
21
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),...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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
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...

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.