This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: xsl:when conditions


Hi Stuart,

> 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"

You can use the select attribute or the content of the xsl:with-param
element to set the default value of the parameter. In your case, you
should use:

<xsl:template name="writeline">
  <xsl:param name="text" />
  <xsl:param name="alignment" select="'left'" />
</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>
[snip]
> </xsl:template>

Your problem in this template is that you're declaring a variable with
the same name as an existing parameter. You can't have a variable and
parameter with the same name, nor can you change the value of a
variable or parameter once it's been set.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]