Re: [xsl] initial template parameters

Subject: Re: [xsl] initial template parameters
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 18 Mar 2010 08:07:41 +0100
At 2010-03-18 01:29 -0400, Max Toro wrote:
"Parameters passed to the transformation by the client application are
matched against stylesheet parameters (see 9.5 Global Variables and
Parameters), not against the template parameters declared within the
initial template. All template parameters within the initial template
to be executed will take their default values."

Why? :-(

Why not? It is quite flexible that way.


If you want to have parameters passed to the transformation to be accessed from within the initial template to be executed, then have the default values of the initial template use the global values:

  <xsl:param name="global-command-line"/>
  <xsl:template match="/">
    <xsl:param name="initial" select="$global-command-line"/>
    ...$initial...
  </xsl:template>

Because local variables shadow global variables you could have the following if you plan to invoke the initial template a number of times in the transform:

  <xsl:param name="x"/>
  <xsl:template match="/">
    <xsl:param name="x" select="$x"/>
    ...$x...
  </xsl:template>

Since global variables are visible to all templates, if you are only ever invoking the initial template once, then you don't need the parameter in the template because the global parameter is visible:

  <xsl:param name="x"/>
  <xsl:template match="/">
    ...$x...
  </xsl:template>

I think this flexibility is quite important.

In my XSLStyle documentation methodology for XSLT stylesheets I have a template rule for the root node that has parameters initialized when first invoked from the command line but passed with new values when the same template rule is invoked later in the transformation.

Can you express what concerns you about not having them passed?

I hope this helps.

. . . . . . . . . . Ken


-- XSLT/XQuery training: San Carlos, California 2010-04-26/30 Principles of XSLT for XQuery Writers: San Francisco,CA 2010-05-03 XSLT/XQuery training: Ottawa, Canada 2010-05-10/14 XSLT/XQuery/UBL/Code List training: Trondheim,Norway 2010-06-02/11 Vote for your XML training: http://www.CraneSoftwrights.com/s/i/ Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread