[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: Call Template with variable name

Subject: Re: Re: Call Template with variable name
From: Eric van der Vlist <vdv@xxxxxxxxxxxx>
Date: Sat, 13 Oct 2001 19:45:53 +0200
call template variable name
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.