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

RE: question on calling templates

Subject: RE: question on calling templates
From: "Hunsberger, Peter" <Peter.Hunsberger@xxxxxxxxxx>
Date: Thu, 29 Aug 2002 16:10:23 -0500
using named templates in xsl
> I was wondering if there is a way to store template name in the variable
and
> then call template.

No

> I want to be able to call diffent body templates depending on the value of
a
> variable.

The answer in this lies in how the variable is created.  If the variable is
based on the contents of your XML then the solution is to simply to base the
XPath used to select the template on the XPATH used to populate the
variable.  For example, if:

	<xsl:variable name="gunk" select="root/*/@name"/>

causes "gunk" to take on the values of "fee" and "foo" then you do something
like:\


	<xsl:apply-templates select="/root/*"/>
		 .
		etc.

	<xsl:template match="*[@name = 'foo']">
and
	<xsl:template match="*[@name = 'fee']>

The name() or local-name() functions being useful if the match is on element
name instead of attribute value.

If the variable is getting populated based on some value being passed into
the style sheet the problem may be a little harder.  If the number of
choices is limited and well defined then you use a choose block:

	<xsl:choose>
		<xsl:when test="$gunk = 'fee'><xsl:call-template
name="fee"/></xsl:when>
		<xsl:when test="$gunk = 'foo'><xsl:call-template
name="foo"/></xsl:when>

If you are possibly matching multiple nodes against the template (it doesn't
sound like it) then using modal templates is useful instead of using named
templates (using named templates is more efficient if there is only one type
of match possible.)

If the number of choices is large then you may be better off in using a two
pass mode where one stylesheet builds a second stylesheet that is then run
against the original input.  That can be complex or simple, depending on the
problem.  If none of this helps, you need to tell us ore about the real
problem that you are trying to solve.

 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.