[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Passing empty parameters discard parameters default value

Subject: Passing empty parameters discard parameters default value
From: ĎURDINA Michal <Michal.Durdina@xxxxxxxxxxxx>
Date: Wed, 16 Jun 2004 14:58:16 +0200
xsl parameter 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.durdina@xxxxxxxxxxxx

http://www.assetsoft.sk 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.