RE: question about call-template

Subject: RE: question about call-template
From: "Carl Soane" <csoane@xxxxxxxxxxxxx>
Date: Mon, 31 Jan 2000 09:35:19 -0800
It's not a completely clean solution, but how I achieve the "pass function
by reference" functionality you're looking for is through a switcher
template.

Here's an example:

<xsl:template match="/">
  <html><body>
    <xsl:call-template name="SWITCHER">
      <xsl:with-param name="Tpl">C</xsl:with-param>
    </xsl:call-template>
  </body></html>
</xsl:template>

<xsl:template name="SWITCHER">
 <xsl:param name="Tpl"></xsl:param>
 <xsl:choose>
  <xsl:when test="'B'=$Tpl">
   <xsl:call-template name="B"/>
  </xsl:when>
  <xsl:when test="'C'=$Tpl">
   <xsl:call-template name="C"/>
 </xsl:when>
 </xsl:choose>
</xsl:template>

<xsl:template name="B">
  The B Template
  <HR/>
</xsl:template>

<xsl:template name="C">
  The C Template
  <HR/>
</xsl:template>

Hope that helps.

-----Original Message-----
From:	owner-xsl-list@xxxxxxxxxxxxxxxx [SMTP:owner-xsl-list@xxxxxxxxxxxxxxxx]
On Behalf Of Reid M. Pinchback
Sent:	Saturday, January 29, 2000 5:40 PM
To:	XSL-List@xxxxxxxxxxxxxxxx
Subject:	question about call-template


[Apologies if anybody has seen this message before.  I'm pretty sure the
 listserv never sent it out the first time, but the archive on Mulberry's
 web site is broken and I can't check to make sure.]


I'm stumped.

I've learned how to write a template.  Ditto for calling a template by name,
and for passing parameters to a template.

I can't find a way to pass the *name* of a template to another template,
and then call that template by that name.  In other words, something like:

<xsl:template match="/">
  <html><body>
    <xsl:call-template name="A">
      <xsl:with-param name="Tpl">B</xsl:with-param>
    </xsl:call-template>
  </body></html>
</xsl:template>

<xsl:template name="A">
  <xsl:param name="Tpl"></xsl:param>
  <xsl:call-template name="$Tpl"></xsl:call-template>
</xsl:template>

<xsl:template name="B">
  <HR/>
</xsl:template>

Should this be possible?  I'm using IBM's XSL processor, but when I try
this I just get:

    "XSL Error: Could not find template named: '$Tpl'

Basically what I'm looking for is the same kind of functionality you get
in languages that allow you to pass a function by reference.  That way
I could create one template that did common processing, and pass a
specialized template to it to handle issues specific to the portion
of the document tree I'm trying to process (eg: create a generic reusable
table layout vs dealing with content-specific layout issues in the rows).

Thanks in advance for any assistance.



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


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


Current Thread