Subject: [xsl] passing parameters with apply-template and document() From: "Robert McGrath" <rmcgrath@xxxxxxxxxxx> Date: Fri, 08 Oct 2004 10:31:44 +0100 |
Hi, I noticed somthing unusual when passing parameters to a template. If I pass a parameter to a template using <apply-template> where the select is a document() it fails but appears to work in every other case. I was wondering if this was the expected behaviour and if so could sombody explain why. I have included examples of what works and what deoesn't below. Thanks Rob. ----- Examples ----- <xsl:call-template name=TemplateA> <xsl:with-param name="paramA" select="MYVALUE"/> </xsl:call-template> <xsl:template name="TemplateA"> <xsl:param name="paramA"/> TemplateA.paramA= <xsl:value-of select="$paramA"/> <xsl:for-each select="document('docB.xml')"> <xsl:call-template name="TemplateB"> <xsl:with-param name="paramB" select="$paramA"/> </xsl:call-template> </xsl:for-each> </xsl:template> <xsl:template name="TemplateB" match="topElement"> <xsl:param name="paramB"/> <xsl:value-of select="$paramB"/> </xsl:template> <--- OUTPUT ---> TemplateA.paramA=MYVALUE TemplateB.paramB=MYVALUE <--- OUTPUT ---> As expected however it should not be necessary to use the for-each tag when calling the template <xsl:for-each select="document('docB.xml')"> <xsl:call-template name="TemplateB"> If I try and do this using an apply-templates it fails <xsl:call-template name=TemplateA> <xsl:with-param name="paramA" select="MYVALUE"/> </xsl:call-template> <xsl:template name="TemplateA"> <xsl:param name="paramA"/> TemplateA.paramA= <xsl:value-of select="$paramA"/> <xsl:apply-templates select="document('docB.xml')"> <xsl:with-param name="paramB" select="$paramA"/> </xsl:call-template> </xsl:template> <xsl:template name="TemplateB" match="topElement"> <xsl:param name="paramB"/> <xsl:value-of select="$paramB"/> </xsl:template> <--- OUTPUT ---> TemplateA.paramA=MYVALUE TemplateB.paramB= <--- OUTPUT ---> The paramB value is lost. topElement is the top level Element in docB. TemplateB is the only template which matches on TopElement. I have used the second syntax in several cases where the select did not contain a document and it worked fine. I have also expanded templateB to print wout some of the data from topElement and it also worked fine so it appears that my context is correct. The difficulty only appears if I pass a parameter and change context to a different document in the same apply-templates call.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] <xsl:include> and CSS, Werner, Wolfgang | Thread | Re: [xsl] passing parameters with a, Oleg Tkachenko |
Re: [xsl] <xsl:include> and CSS, Werner, Wolfgang | Date | Re: [xsl] passing parameters with a, Oleg Tkachenko |
Month |