Re: [xsl] Passing empty parameters discard parameters default value

Subject: Re: [xsl] Passing empty parameters discard parameters default value
From: Thijs Janssen <thijs.janssen@xxxxxxxxx>
Date: Wed, 16 Jun 2004 20:51:20 +0200
Hi Michal,

The problem is that you ARE passing a parameter to mytemplate_impl. It
might eventually be empty, but it still counts as a parameter, and
thus no default value is used... (after all, one can imagine cases
where passing an empty nodeset as a parameter has a semantical
meaning)

A possible work-around is:

<xsl:template name="mytemplate">
  <xsl:param name="p"/>
  <xsl:call-template name="mytemplate_impl">
    // parameter is not passed if its empty
    <xsl:if test="$p">
      <xsl:with-param name="p" select="$p"/>
    </xsl:if>
  </xsl:call-template>
</xsl:template>

regards,
Thijs Janssen

On Wed, 16 Jun 2004 14:58:16 +0200, ĎURDINA Michal
<michal.durdina@xxxxxxxxxxxx> wrote:
> 
> Hello,
> 
> I am having problems with passing empty parameters (no with-param specified) that discard default values of parameters. When I am calling the template and passing no value I want the template to use its default value.
> 
> Example:
> 
>   <xsl:template name="mytemplate">
>     <xsl:param name="p"/>
>     <xsl:call-template name="mytemplate_impl">
>       <xsl:with-param name="p" select="$p"/>
>     </xsl:call-template>
>   </xsl:template>
> 
>   <xsl:template name="mytemplate_impl">
>     <xsl:param name="p">default p</xsl:param>
>     p = <xsl:value-of select="$p"/>
>   </xsl:template>
> 
> When calling:
>     <xsl:call-template name="mytemplate_impl"/>
> the result is:
>         p = default p
> But when calling
>     <xsl:call-template name="mytemplate"/>
> the result is:
>         p =
> 
> what is wrong in my case, becase I did not supplied any value to parameter $p so I want to see its default value. I know that I can declare the same default value in template "mytemplate" , but then I will have the same value in more than one place and that's not good when I will need to change it.
> 
> Is there any workaround for my problem?
> 
> Thank you,
> Michal
>

Current Thread