xsl-list
[Top] [All Lists]

RE: Passing empty parameters discard parameters default val ue

2004-06-16 08:44:14
Hi Michal

You are suppressing the default value by passing your template a parameter
with no value.

An easy solution would be to not pass a parameter if you have nothing to
pass.

<xsl:if test="$p"> etc

 or to have a default value for the upstream template

  <xsl:template name="mytemplate">
    <xsl:param name="p" select="'Default P'"/>
    <xsl:call-template name="mytemplate_impl">
      <xsl:with-param name="p" select="$p"/>
    </xsl:call-template>
  </xsl:template>

Cheers

Rod

-----Original Message-----
From: DURDINA Michal [mailto:Michal(_dot_)Durdina(_at_)assetsoft(_dot_)sk]
Sent: 16 June 2004 13:58
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Passing empty parameters discard parameters default value


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

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(_dot_)durdina(_at_)assetsoft(_dot_)sk

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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


_________________________________________________________________________
 
Any  opinions  expressed in  this email  are those of the individual  and
not necessarily  the Company.  Unless  expressly  stated to the contrary,
this email is not intended to give  rise to a new, or affect an existing,
contractual or other legal relationship.
 
This email  and  any  files  transmitted  with it, including replies  and
forwarded copies which  may contain alterations) subsequently transmitted
from the Company, are confidential and solely for the use of the intended
recipient.  The unauthorised use, disclosure or copying of this email, or
any other information contained  or attached, is prohibited and could, in
certain circumstances, be a criminal offence.
 
If you have received this email in error please notify the sender as soon
as possible.
 
This footnote  also confirms that  this email message  has been swept for
the presence of computer viruses.
 
www.focusdiy.co.uk
_________________________________________________________________________


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


<Prev in Thread] Current Thread [Next in Thread>
  • RE: Passing empty parameters discard parameters default val ue, Rod Humphris - FLPTN <=