This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: xsl:when conditions
- To: xsl-list at lists dot mulberrytech dot com
- Subject: RE: [xsl] xsl:when conditions
- From: "Crowers, Steve" <scrowers at liberate dot com>
- Date: Thu, 16 Aug 2001 12:19:03 -0400
- Reply-To: xsl-list at lists dot mulberrytech dot com
try declaring the parameter with a default in the template and toss the
xsl:when statement...
<xsl:param name="alignment" select="string('left')"/>
Steve Crowers
Software Engineer
Liberate Technologies
2 Walnut Grove,
Suite 200
Horsham, PA 19044
Phone: 215-773-9400 x 9514
Fax: 215-773-9401
scrowers@liberate.com
http://www.liberate.com
"The good Lord sets definite limits on man's wisdom but sets no limits on
his stupidity -- and that's just not fair." --Konrad Adenauer, German
Chancellor
-----Original Message-----
From: Stuart Wilson [mailto:coracle@totalise.co.uk]
Sent: Thursday, August 16, 2001 12:00 PM
To: XSL-List@lists.mulberrytech.com
Subject: [xsl] xsl:when 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
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list