This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Calling a template dynamically?
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Calling a template dynamically?
- From: Alessio Mazzieri <mazzieri at umbrars dot com>
- Date: Tue, 13 Nov 2001 15:36:23 +0100
- References: <85256B03.004DA739.00@ams-central-gate-5a.amsinc.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
>
>
>
>Hello everybody,
>I'm trying to call a template whose name is in the XML file that I'm parsing.
>Example:
>XML file contains a tag like:
>...
><label>sample</label>
>...
>
>And I want to call the template "sample".
>
>Therefore I think that I would need to do something like:
><xsl:variable name="templatename">
><xsl:value-of select="label"/>
></xsl:variable>
><xsl:call-template name="$templatename">
>
>but this doesn't work, as it doesn't the following:
>
><xsl:call-template name="{$templatename}">
>
I think it's not possibile, in fact, from the XSL documentation, this is
the sintax of <xsl:call-template>:
<xsl:call-template name=QName>
<xsl:with-param> *
</xsl:call-template>
So, the "name" attribute must be a valid QName, not an Expression.
I've had the same problem, and I've resolved it using a "static"
template, calling it with a param whose value is the "dynamic" name of
the node.
Then, the template, with <xsl:choose>, select the appropriate
transformation to apply.
Other solutions?
Alessio Mazzieri
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list