Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2008, 09:54 AM
Authorized User
 
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anboss
Default question on with-param

hello

i have a template that takes in 5 parameters. i am calling this template twice: by passing all 5 parameters in first call and for the next time i pass only 3 parameters (and my requirement is just to pass 3 parameters when i call for second time). when i run this xsl error is not thrown. since my requirement is satisfied i am still following the same way. will there be any potential problem in this logic under any circumstances.

 
Old June 23rd, 2008, 10:07 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

If you specify a parameter for a template to have a select attribute then that acts as its default value if you don't pass it in when calling the template. e.g.:

<xsl:template name="test">
  <xsl:param name="value" select="10"/>
  <xsl:value-of select="$value"/>
</xsl:template>

<xsl:call-template name="test">
  <xsl:with-param name="value" select="20"/>

</xsl:call-template>

<xsl:call-template name="test">

</xsl:call-template>

/- Sam Judson : Wrox Technical Editor -/
 
Old June 23rd, 2008, 10:15 AM
Authorized User
 
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anboss
Default

Currently i am not initializing the parameter in the template. i would like to know if initialization is required? whether a default value (say an empty string) will be assigned automatically if i am not initializing the parameter?
 
Old June 23rd, 2008, 10:26 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can call a template passing in parameters that aren't defined without problems. For example the following is valid for the above template:

<xsl:call-template name="test">
  <xsl:with-param name="frogs" select="'Supercalifragilisticexpialidocious'"/>
</xsl:call-template>

/- Sam Judson : Wrox Technical Editor -/
 
Old June 23rd, 2008, 01:11 PM
Authorized User
 
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anboss
Default

let me confirm my understanding..

<xsl:template name="test">
<xsl:param name="value"/>

<xsl:value-of select="$value"/>
</xsl:template>

<xsl:call-template name="test">
<xsl:with-param name="value" select="20"/>

</xsl:call-template>

<xsl:call-template name="test">

</xsl:call-template>

so this should work under all circumstances. right?
 
Old June 23rd, 2008, 04:13 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I'm fairly sure that's allowed, the second call just returns nothing.

/- Sam Judson : Wrox Technical Editor -/
 
Old June 23rd, 2008, 05:58 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 1.0, parameters declared using xsl:param are always optional. The default value is provided by the select attribute; if there is no select attribute, the default value is a zero-length string.

In XSLT 2.0, parameters are optional provided you don't set required="yes". The rules for the default value take into account whether or not you specified the parameter type in an "as" attribute.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
document() and param - help please akentanaka XSLT 2 July 5th, 2008 06:35 AM
Reassign param value? victorcorey XSLT 2 November 29th, 2007 05:33 AM
with-param nodeset RoeZ XSLT 6 November 1st, 2007 06:53 PM
Param Question Tre XSLT 7 March 27th, 2007 09:13 AM
passing param to XSLT Dangerous Dave XSLT 0 April 30th, 2004 07:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.