[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Second of two consecutive call-template instructions appears to affect the first?


Subject: Re: [xsl] Second of two consecutive call-template instructions appears to affect the first?
From: Sebastian Tennant <sebyte@xxxxxxxxxxxxxxx>
Date: Wed, 15 Mar 2006 13:53:52 +0000

"Michael Kay" <mike@xxxxxxxxxxxx> wrote:

> This template:
>
>   <xsl:template name="does-image-flickr">
>     <xsl:choose><!-- photo is a flickr link -->
>       <xsl:when test="/page/images/image[@name=$name]/flickr">
>         <a href="{/page/images/image[@name=$name]/flickr}">
>           <xsl:call-template name="pass-image-params" />
>
> contains two refences to the variable $name, which isn't in scope in this
> template. If you want it to be available in this template, you need to pass
> it as a parameter.
>
> It looks as if Xalan isn't reporting this error if it occurs in a template
> that isn't called. The XSLT 1.0 spec isn't very precise about which errors
> are static errors and which are dynamic, so that's probably conformant:
XSLT
> 2.0 makes it mandatory to report this as a static error.
>
> Michael Kay
> http://www.saxonica.com/


Sorry Michael, I still don't get it.  The 'does-image-flickr' template
is called both times, i.e., whether the following instruction is a
call to 'write-caption' or not, so why should $name need to be
declared in one instance and not in another? ($name is a parameter by
the way).

What's more, look at the template 'pass-image-params'.  This is called
(using call-template) without explicitly passing it any parameters,
and it successfully passes parameters defined in its caller to the
'image' template (using apply-templates).  Its very raison-d'C*tre is
to cut down on the repetition of lines of code, because the
conditional logic requires me to pass these parameters to the 'image'
template from four different places.

No doubt my understanding is at fault, but I could have sworn blind
using call-template preserved the local scope as well as the current
node list.  Using it (rather than apply-templates) to provide this
functionality has worked for me time and time again thus far.

sdt


Current Thread
Keywords