Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 14th, 2011, 07:11 PM
Registered User
 
Join Date: Dec 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Question Place a variable in html hyperlink for option in xsl:choose

Hi,
First time poster, and very new to XML and XSL. My question is this, I have a table which is sorted using xsl sort. I would like to sort it ascending when the parameter equals a certain value, say 'sortTime', otherwise sort it descending. I was hoping to set this parameter to that value using a hyperlink. I have searched high and low, and still dont even know about setting up a parameter correctly so I dont know if that is the issue or if this can even be done. Here is my code:
Any help or direction to information will be greatly appreciated.
Kind Regards
Barry T
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
	<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	  	<xsl:template match="/">
	  	<xsl:param name="sortkey" />
<html>
	<head>
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
		<title>Euro 2012 Assignment</title>
		<script language="javascript" type="text/javascript" src="weatherRss.js"></script>
		<script language="javascript" type="text/javascript" src="showRSS1.js"></script>
		
		
		
		<link rel="stylesheet" type="text/css" href="stylesheet1.css" />
		<!--link rel="stylesheet" type="text/css" href="football.css" /-->
	</head>

<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<h2><strong>RSS news feeds</strong></h2>
<br/>
<div class="centerback">
		
	<div class="fixturesTable">
	   	
	   	<form method="GET" action="" name="form1">
			<table border="4" style="color:white; white-space: nowrap;" id="tableFix">
		   
		        <tr style="color:white;" bgcolor="silver">
			        <td>Team Name</td>
			        <td>.</td>
			        <td>Team Name</td>
			        <td>Venue</td>
			        <td><a href="football.xml?sortkey=sortTime">Time</a></td>
		        </tr>
		        
		        
		  		
		  		<xsl:choose>
		    		<xsl:when test="sortkey=sortTime">
		       			<xsl:for-each select="fixture/game">
		  					<xsl:sort select="time" order="ascending"></xsl:sort>
		   				        <tr style="color:silver;">
							        <td><xsl:value-of select="teamA"/></td>
							        <td> VS </td>
							        <td><xsl:value-of select="teamB"/></td>
						        	<td><xsl:value-of select="venue"/></td>
							        <th value="qwe" id="timeRow"><xsl:value-of select="time"/></th>
						        </tr>
						</xsl:for-each>
		    		</xsl:when>
		    	
		    		<xsl:otherwise>
		    			<xsl:for-each select="fixture/game">
		  					<xsl:sort select="time" order="descending"></xsl:sort>
		   				        <tr style="color:silver;">
							        <td><xsl:value-of select="teamA"/></td>
							        <td> VS </td>
							        <td><xsl:value-of select="teamB"/></td>
						        	<td><xsl:value-of select="venue"/></td>
							        <th value="qwe" id="timeRow"><xsl:value-of select="time"/></th>
						        </tr>
						</xsl:for-each>
		    		</xsl:otherwise>
		   		</xsl:choose>
		   	</table>
		    <input type="submit" name="btn" value="alert" onclick="" />
	    </form>
	    
	</div>

</div>

<div class="rightside"></div>
<div class="leftside"></div>
  	
   	    
 	</body>
  	</html>
	</xsl:template>
</xsl:stylesheet>
 
Old December 14th, 2011, 07:59 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First point is that to answer questions about XSLT, we really need to know whether you are using XSLT 1.0 or XSLT 2.0. Using 2.0 makes a lot of things easier, but it isn't available in all environments.

The general structure of the solution is likely to be something like this:

Code:
<xsl:variable name="order" select="if (...) then 'ascending' else 'descending'"/>
<xsl:for-each ...>
   <xsl:sort select="..." order="{$order}"/>
   ...
</xsl:for-each>
except that the if-then-else is XSLT 2.0, and in 1.0 you'll need to use the more long-winded xsl:choose.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
Barry_T (December 14th, 2011)
 
Old December 14th, 2011, 09:16 PM
Registered User
 
Join Date: Dec 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Re: reply

Thank you for a very prompt reply! I am using XSLT 1.0
I will give it a go, Thanks for your help.
Kind Regards
Barry_T





Similar Threads
Thread Thread Starter Forum Replies Last Post
attach the xsl variable into the attribute html tag giamba78 XSLT 3 July 22nd, 2010 09:19 AM
applying XSL stylesheet from an HTML hyperlink beckfield XML 0 February 14th, 2010 03:34 PM
Passing xsl variable in hyperlink querystring b.preetam XSLT 5 November 13th, 2009 10:42 AM
html option value assigned to xsl:variable bergs77 XSLT 2 February 23rd, 2006 02:27 PM
choose option in combobox Perseus VB Databases Basics 0 August 11th, 2005 01:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.