You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Tory Toupin <tt...@PetroleumPlace.com> on 2000/10/16 21:26:10 UTC

Troubles with parameters

This is a largely usage question, but after digging around in the guts of
Xalan, I'm thinking it might be an "issue."

Here's the scenario.  With Xalan, I cannot consistently use with-param to
pass parameters to templates (whether through apply-templates or
call-template).  It seems that whenever I use with-param to apply-template
or call-template inside a for-each type block, the with-param parameters are
"blocked" (by the contextMarker) from the called context.  Something really
simple like this

	<xsl:template match="include" mode="html">
	<xsl:apply-templates select="document(@href)" mode="html/include">
		<xsl:with-param name="href" select="@href"/>
	</xsl:apply-templates>
	</xsl:template>

	<xsl:template match="html" mode="html/include">
	<xsl:param name="href"/>
	(From <xsl:value-of select="$href"/>.)
	<xsl:apply-templates select="body/*|body/text()" mode="html"/>
	</xsl:template>

	<xsl:template match="*|text()" mode="html/include"></xsl:template>

doesn't work.  If I change the code in such a way that there is no select,
the called context can see the with-param parameters; adding the select back
in causes the blockage.

Thoughts?

Tory Stephen Toupin
E-Mail: ttoupin@PetroleumPlace.com



Re: Troubles with parameters

Posted by Gary L Peskin <ga...@firstech.com>.
> Tory Toupin wrote:
> 
> This is a largely usage question, but after digging around in the guts
> of Xalan, I'm thinking it might be an "issue."
> 
> Here's the scenario.  With Xalan, I cannot consistently use with-param
> to pass parameters to templates (whether through apply-templates or
> call-template).  It seems that whenever I use with-param to
> apply-template or call-template inside a for-each type block, the
> with-param parameters are "blocked" (by the contextMarker) from the
> called context.  Something really simple like this
> 
>      <xsl:template match="include" mode="html">
>      <xsl:apply-templates select="document(@href)"
>      mode="html/include">
>              <xsl:with-param name="href" select="@href"/>
>      </xsl:apply-templates>
>      </xsl:template>
> 
>      <xsl:template match="html" mode="html/include">
>      <xsl:param name="href"/>
>      (From <xsl:value-of select="$href"/>.)
>      <xsl:apply-templates select="body/*|body/text()" mode="html"/>
>      </xsl:template>
> 
>      <xsl:template match="*|text()"
>      mode="html/include"></xsl:template>
> 
> doesn't work.  If I change the code in such a way that there is no
> select, the called context can see the with-param parameters; adding
> the select back in causes the blockage.
> 
> Thoughts?

Tory --

The document(@href) function returns the root node of the specified
document.  This is the node matched by /.  You don't have a template for
the root node so Xalan uses the built-in template which does not have an
xsl:param element to receive your passed parameter.  The built-in
template for the root node invokes apply-templates for the children of
the root which, in your case, seems to be <html>.  Of course, the
built-in template doesn't have your xsl:with-param either so your
match="html" template is invoked without parameters.

Try changing your select to select="document(@href)/html" and see if
this fixes your problem.

HTH,
Gary