Conditional variable assignment

H

Hoi Wong

I was trying to conditionally define a bunch of global variable but turns
out that I'm stuck with FAQ#27 in this page:
http://www.dpawson.co.uk/xsl/sect2/N8090.html

What it says is that I have to select the value inside variable definition,
instead of assigning different values to a variable depending on the
conditions.

However, I have 40 variables that needs to be defined base on 3 logical
cases (<xsl:choose>). Doing so will make my XSLT scripts unreadable and
there's a lot of typing. Is there any other way round?

Thanks.

Cheers,
Hoi
 
M

Martin Honnen

Hoi said:
I was trying to conditionally define a bunch of global variable but turns
out that I'm stuck with FAQ#27 in this page:
http://www.dpawson.co.uk/xsl/sect2/N8090.html

What it says is that I have to select the value inside variable definition,
instead of assigning different values to a variable depending on the
conditions.

However, I have 40 variables that needs to be defined base on 3 logical
cases (<xsl:choose>). Doing so will make my XSLT scripts unreadable and
there's a lot of typing. Is there any other way round?

I am not completely sure I understand your problem. If you want to
define variable values based on certain conditions and you want to avoid
repeating code then consider to put the code into a function (XSLT/XPath
2.0) or a template (XSLT/XPath 1.0 and 2.0).
 
H

Hoi Wong

FAQ#27 basically suggest breaking down <xsl:variable name="XX"
select="someXpath"> into <xsl:variable name="XX"><xsl:value-of
select="someXpath"></xsl:variable> and that'll make my code clumsy.

Even worse, I just found that <xsl:value-of> converts the results to
strings, which screws up boolean variables.

Is there any way that I can still define a variable conditionally yet the
result doesn't have to be converted to strings?

Thanks.

Cheers,
Hoi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top