[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Second of two consecutive call-template instructio
Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> wrote: > Sebastian, > > It appears that while your variables are in scope in the calling > template, they are no longer in scope in the templates called. > > The solution is to declare them also in the called templates if the > execution context (such as the context node) provides access to the > values you need for them, or if not (and sometimes even if so), to > pass their values into the named templates as parameters. > > In XSLT, variables are scoped within the context of their parent > elements. As the language is defined in such a way to be "side-effect > free", you can't declare a variable in one template and then refer to > it in another. > > Cheers, > Wendell Hi Wendell, I hope your class went well. You may remember that you were going to quote me as saying "we're just not used to having things done for us are we?" Regarding the problem in hand, I just don't get it. Why should this work fine: <xsl:call-template name="does-image-flickr" /> . . <xsl:template name="does-image-flickr"> <xsl:choose><!-- photo is a flickr link --> <xsl:when test="/page/images/image[@name=$name]/flickr"> ^^^^ [variable 'name' is OK] ...and this cause an error: <xsl:call-template name="does-image-flickr" /> <xsl:call-template name="write-caption"> <xsl:with-param name="cpos"><xsl:value-of select="$cpos" /></xsl:with-param> <xsl:with-param name="caption"><xsl:value-of select="$caption" /></xsl:with-param> </xsl:call-template> . . <xsl:template name="does-image-flickr"> <xsl:choose><!-- photo is a flickr link --> <xsl:when test="/page/images/image[@name=$name]/flickr"> ^^^^ [variable 'name' causes an error] ...where the only difference is the call to the 'write-caption' template that comes _after_ the call to the 'does-image-flickr' template. The fact that the call to 'does-image-flickr' works in the first instance proves to me what I have been lead to believe, namely that call-template differs from apply-templates in that the local scope is unchanged as well as the current node list. My experience whilst writing this template has also served to confirm this. I have several exapmples where templates called using call-template make use of params defined in the callee without explicitly passing the params using with-params. sdt
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|