|
Subject: RE: [xsl] Passing empty parameters discard parameters default value From: ĎURDINA Michal <Michal.Durdina@xxxxxxxxxxxx> Date: Fri, 18 Jun 2004 19:20:17 +0200 |
Probably only workaround is to define default parameter for template like this:
<xsl:template name="mytemplate_impl">
<xsl:param name="p">default p</xsl:param>
<xsl:variable name="p2">
<xsl:choose>
<xsl:when test="$p = ''">default p</xsl:when>
<xsl:otherwise><xsl:copy-of select="$p"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
p = <xsl:value-of select="$p2"/>
</xsl:template>
<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>
Then calling
<xsl:call-template name="mytemplate"/>
gives required result:
p = default p
providing one is not allowed to use empty string as a valid parameter value.
Or does anyone have better idea?
Anyway, I find this as a lack of XSLT Specification that could specify extra meaning to
<xsl:param name="p"/>. In this case $p should have special value 'nothing' and sending this variable as a value to parameter in another template would be equal to as not sending that parameter.
I don't know if there is something prepared in XSLT2.0 that could solve this in more elegant way. If there is I would be happy to know of such a feature.
Thank you,
Michal
> -----Original Message-----
> From: Michael Kay [mailto:mhk@xxxxxxxxx]
> Sent: Thursday, June 17, 2004 12:59 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Passing empty parameters discard parameters default
> value
>
>
> >
> > 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"/>
>
> This is exactly the same as specifying
>
> <xsl:param name="p" select="''"/>
>
> that is: $p is given a value which is the zero-length string.
> You are then
> supplying this value to the other template. The only way to
> get the second
> template to use its default value for the parameter is to omit the
> xsl:with-param from the call.
>
> Michael Kay
>
>
> > <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
> >
> > PS: If you want to have full pricture why I need this default
> > parameter mechanism, here it is:
> >
> > I have hierarchy of importing stylesheets and I try to
> > simulate polymorphism for named templates via shadowing of
> > "interface" templates and by calling "implementation" templates.
> >
> > library.xsl:
> > <!-- interface template -->
> > <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>
> >
> > <!-- implementation template -->
> > <xsl:template name="mytemplate_impl">
> > <xsl:param name="p">default p</xsl:param>
> > p = <xsl:value-of select="$p"/>
> > </xsl:template>
> >
> > customized-library.xsl:
> > <xsl:import href="library.xsl"/>
> >
> > <!-- interface template -->
> > <xsl:template name="mytemplate">
> > <xsl:param name="p"/>
> > <b>
> > <xsl:call-template name="mytemplate_impl">
> > <xsl:with-param name="p" select="$p"/>
> > </xsl:call-template>
> > </b>
> > </xsl:template>
> >
> > user-stylesheet.xsl:
> >
> > <xsl:include href="customized-library.xsl"/>
> > ...
> > <xsl:template match="/">
> > <xsl:call-template name="mytemplate"/>
> > </xsl:template>
> >
> > user-input.xml:
> > <?xml-stylesheet type="text/xsl" href="user-stylesheet.xsl"?>
> > <root/>
> >
> > required output:
> > <b>p = default p</b>
> >
> > actual output:
> > <b>p = </b>
> >
> > I hope the idea is ok, developer of user-stylesheet.xsl can
> > customize templates from library.xsl that he/she uses in
> > user-stylesheet.xsl. But I am having the problem with passing
> > empty parameter (no parameter) that discard default value in
> > original template.
> >
> > -----------
> > Michal Ďurdina
> > ASSET Soft, a.s. / eBussiness Solutions
> > Košická 56, 821 08 Bratislava SLOVAK REPUBLIC
> > Phone: +421-2-50703-523
> > Fax: +421-2-50703-444
> > e-mail: michal.durdina@xxxxxxxxxxxx
> >
> > http://www.assetsoft.sk
> >
> >
> --+------------------------------------------------------------------
> > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
> > To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> > or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> > --+--
> >
> >
>
>
> --+------------------------------------------------------------------
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --+--
>
>
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] ?Could sort+ be quicker t, Michael Kay | Thread | RE: [xsl] re: ANN: Saxon.NET - v.8., Pieter Reint Siegers |
| RE: [xsl] adding a duration to a da, Michael Kay | Date | Re: [xsl] Accents problems in "acti, Josh Canfield |
| Month |