Subject: RE: call-template question From: "Carl Soane" <csoane@xxxxxxxxxxxxx> Date: Wed, 16 Feb 2000 15:23:38 -0800 |
>> Is it possible to call a template and pass in as a parameter the name of the template you would like the called template to call? Here's a previously posted answer to an almost identical question: <previous_answer> Can't be done with call-template, except by an xsl:choose instruction that lists all the possibilities. You could achieve the effect with apply-templates with a bit of deviousness. Change your named template from <xsl:template name="xyz"> to <xsl:template name="xyz" match="xsl:template[@name='xyz']"/> and call it like this: <xsl:variable name="tname" select="'xyz'"/> <xsl:apply-templates select="document('')/*/xsl:template[@name=$tname]"/> However, this will change the current node and node list; if the named template needs these, they'll have to be passed as parameters. I suspect if you go back to the original problem, there is a better solution than this. Mike Kay </previous_answer> so, in your case, the xsl would look like this: <xsl:template match="/"> <HTML> <xsl:call-template name="buildpage"> <xsl:with-param name="nexttemplate">buildbody</xsl:with-param> </xsl:call-template> </HTML> </xsl:template> <xsl:template name="buildpage"> <xsl:param name="nexttemplate">defaulttemplate</xsl:param> <xsl:value-of select="$nexttemplate"/> <xsl:apply-templates select="document('')/*/xsl:template[@name=$nexttemplate]"/> </xsl:template> <xsl:template name="buildbody" match="xsl:template[@name='buildbody']"> <BODY> </BODY> </xsl:template> -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxx [SMTP:owner-xsl-list@xxxxxxxxxxxxxxxx] On Behalf Of Joni Fazo Sent: Wednesday, February 16, 2000 11:37 AM To: 'XSL-List-Digest@xxxxxxxxxxxxxxxx' Subject: xsl:call-template question Hello, Here's a (non-working) example of what I am trying to do: <!-- / Template --> <xsl:template match="/"> <HTML> <xsl:call-template name="buildpage"> <xsl:with-param name="nexttemplate">buildbody</xsl:with-param> </xsl:call-template> </HTML> </xsl:template> <!-- buildpage Template --> <xsl:template name="buildpage"> <xsl:param name="nexttemplate">defaulttemplate</xsl:param> <xsl:value-of select="$nexttemplate"/> <xsl:call-template name="{$nexttemplate}"/> </xsl:template> <!-- buildbody Template --> <xsl:template name="buildbody"> <BODY> </BODY> </xsl:template> I get the error "No named template "{$nexttemplate}" found" when the line <xsl:call-template name="{$nexttemplate}"/> is processed. I am able to get the value of $nexttemplate though... Thanks in advance for any help you can give me. Joni XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: xsl:call-template question, Tony Graham | Thread | Re: xsl:call-template question, Gerard Berthet |
RE: XSL & DTD, Mike Brown | Date | RE: Problem with entities and XT, Mike Brown |
Month |