473,385 Members | 1,742 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,385 software developers and data experts.

XSLT: Multiple conditional variable assignment

Hello,

Is there a better way of doing:

Expand|Select|Wrap|Line Numbers
  1.   <xsl:variable name="frlink">
  2.   <xsl:choose>
  3.   <xsl:when test="@isFriend = '0'"><xsl:value-of select="concat('friends.php?add=', @uid)"/></xsl:when>
  4.   <xsl:otherwise> <xsl:value-of select="concat('friends.php?add=', @uid)"/></xsl:otherwise>
  5.   </xsl:choose>
  6.   </xsl:variable>
  7.   <xsl:variable name="frstr">
  8.   <xsl:choose>
  9.   <xsl:when test="@isFriend = '0'"><xsl:value-of select="'FR_ADD_TO_FRIENDS'"/></xsl:when>
  10.   <xsl:otherwise> <xsl:value-of select="'FR_REMOVE_FRIEND'"/></xsl:otherwise>
  11.   </xsl:choose>
  12.   </xsl:variable>
I.e. in an procedural language I would do:

if(a)
{
i = someval; j = someval; k = someval;
}
else
{
i = someotherval; j = someotherval; k = someotherval;
}

In XSLT it seems to be a case of put the conditional inside every single variable assignment - is there a better way?

Thanks,

Dave
Feb 29 '08 #1
1 7242
jkmyoung
2,057 Expert 2GB
There is another way, although this has it's own problems.

You could create a super variable


Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="super">
  2.   <super>
  3.     <xsl:choose>
  4.       <xsl:when test="@isFriend = '0'">
  5.         <frlink><xsl:value-of select="concat('friends.php?add=', @uid)"/></frlink>
  6.         <frstr><xsl:value-of select="'FR_ADD_TO_FRIENDS'"/></frstr>
  7.       </xsl:when>
  8.       <xsl:otherwise>
  9.         <frlink><xsl:value-of select="concat('friends.php?add=', @uid)"/></frlink>
  10.         <frstr><xsl:value-of select="'FR_REMOVE_FRIEND'"/></frstr>
  11.       </xsl:otherwise>
  12.     </xsl:choose>
  13.   </super>
  14. </xsl:variable>
  15.  
However, then $frlink beomes: $super//frlink
and $frstr becomes $super//frstr

If this causes errors due to result-tree-fragments, then you might need to use exsl:node-set($super//frlink) or msxsl:node-set($super//frlink)
Feb 29 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Eric Anderson | last post by:
I'm not sure if this is the correct place to post this question so please feel free to redirect me if needed. I am writing a XSL transform document to perform a transform on an XML document. I...
4
by: David Blickstein | last post by:
I have an application where I have a shared "method" of selecting a nodeset. The method currently is duplicated everywhere it is needed but I'd like that code to be shared. The method also...
8
by: Kathleen Dollard | last post by:
Hi, Oleg's answer about attribute value templates led me to look back at a different problem, and wonder if someone else had solved it. I want to output an ASP.NET page. Thus I need to output...
4
by: mux | last post by:
Hi I found out that the following piece of code throws an error. 1 #include "stdio.h" 2 3 int main() 4 { 5 int a,b; 6 a= 10;
2
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>...
6
by: aidy | last post by:
Hi, This is a snippet of my XSLT <xsl:for-each select = "SAFS_LOG/LOG_MESSAGE"> <xsl:choose> <xsl:when test="@type = 'FAILED'"> <xsl:variable name="isFailed" select="@type" /> <BR>...
5
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
2
by: darel.finkbeiner | last post by:
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...
2
by: rajan sood | last post by:
Hi How can i get the single node value if i have node value is in multiple nodes under parent node. I need <START_DATE> in output ..what code should i need to write in XSL so that below XML...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.