[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

xsl:when conditions

Subject: xsl:when conditions
From: Stuart Wilson <coracle@xxxxxxxxxxxxxx>
Date: Thu, 16 Aug 2001 16:59:35 +0100
xsl conditions
Hello,
  In the XSL below I'm trying to pass a optional parameter called "alignment" 
into a template. When the parameter is not passed into the template I want to 
assign a default value (left) to the variable "alignment"

  The line <xsl:when test="$alignment"> seems to be causing the problem and 
did work under Xalan 1_2_2, however it fails under Xalan 2_2 with "Unknown 
error in XPath"

  Could someone explain how best to set a default value to the parameter ?

<?xml version="1.0"?>
<xsl:stylesheet    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0"    xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match ="/">

<!-- Text aligned right -->
 <xsl:call-template name="writeline">
	<xsl:with-param name="text" select="string('some text')"/>
	<xsl:with-param name="alignment" select="string('right')"/>
 </xsl:call-template>

<!-- Should take default -->
 <xsl:call-template name="writeline">
 	<xsl:with-param name="text" select="string('some more text')"/>
 </xsl:call-template>

</xsl:template>

<xsl:template name="writeline">
<xsl:param name="text"/>
<xsl:param name="alignment"/>
<xsl:variable name="alignment">
	<xsl:choose>

		<xsl:when test="$alignment"> <===== This syntax causes error
 			<xsl:value-of select="$alignment"/>
		</xsl:when>
 		<xsl:otherwise>
 			<xsl:value-of select="string('left')"/>
 		</xsl:otherwise>
 	</xsl:choose>
 </xsl:variable>


<table width="100%" border="1">
<tr>
<td align="{$alignment}"><xsl:value-of select="$text"/></td>
</tr>
</table>
</xsl:template>

</xsl:stylesheet>


Regards,

Stuart

-----------------------
The Totalise Email system, probably the most flexible email system in the
world. To register for an account goto http://www.totalise.net


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.