Re: [xsl] Re: Call Template with variable name

Subject: Re: [xsl] Re: Call Template with variable name
From: Eric van der Vlist <vdv@xxxxxxxxxxxx>
Date: Sat, 13 Oct 2001 19:45:53 +0200
Dimitre Novatchev wrote:

"Yash" <yashdeep at ekartha dot com> wrote:


Why is there a syntax problem with the following:
<xsl:call-template name="$abc"/>
i.e. is there a way to call a template whose name is specified with the
variable 'abc'?


No -- not in XSLT 1.0 and probably not in XSLT 2.0 judging from the working draft I've seen.

However, almost the same effect can be accomplished using the mechanism of generic
templates, as described in:

http://lists.fourthought.com/pipermail/exslt/2001-May/000169.html


Just thought that one of the techniques I am using in my "stylefree stylesheets" can apply here...

What about diverting unnamed templates to use them as "variably named" templates using hook nodes in the XSLT sheet itself to match the variable names ?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:vn="http://dyomedea.com/ns/variable-names";>


<!-- just a shortcup... -->
<xsl:variable name="varnames" select="document('')/xsl:stylesheet/vn:templates"/>


<!-- hooks -->
<vn:templates>
 <vn:template1/>
 <vn:template2>I am template 2</vn:template>
 <vn:template3>
	<info> Some more info for template 3</info>
 <vn:template3>
</vn:templates>

.../...

And instead of <xsl:call-template name="$abc"/>,

<xsl:apply-templates select="$varnames/*[local-name()=$abc]"/>

or when the context node is important:

 <xsl:apply-templates select="$varnames/*[local-name()=$abc]">
   <xsl:with-param name="context" select="."/>
 </xsl:apply-templates>


and


  <xsl:template match="vn:template1">
...

That can do the trick for a number of applications and you can pass additional info to your templates in the "hook" elements.

Eric
--
Rendez-vous à Paris pour une visite guidee de la nebuleuse XML.
                                          http://dyomedea.com/formation/
------------------------------------------------------------------------
Eric van der Vlist       http://xmlfr.org            http://dyomedea.com
http://xsltunit.org      http://4xt.org           http://examplotron.org
------------------------------------------------------------------------


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread