This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
xsl:when conditions
- To: XSL-List at lists dot mulberrytech dot com
- Subject: [xsl] xsl:when conditions
- From: Stuart Wilson <coracle at totalise dot co dot uk>
- Date: Thu, 16 Aug 2001 16:59:35 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
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