This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: call-template can't find the template?
- From: "J.Pietschmann" <j3322ptm at yahoo dot de>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 24 Jun 2002 22:31:03 +0200
- Subject: Re: [xsl] call-template can't find the template?
- References: <4.3.2.7.2.20020624160828.02429b58@pop.mathworks.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Greg Kushmerek wrote:
I'm having trouble with the call-template element.
Here's how I'm using it in my stylesheet:
<!-- p template -->
<xsl:template match="p">
<xsl:text /><xsl:apply-templates /><xsl:text/>
</xsl:template>
<!-- bu template -->
<xsl:template match="bu">
- <xsl:call-template name="p" />
</xsl:template>
...
Yet if I call Xalan (1.3 on Linux), I get this error:
XSLT error: Could not find named template., style tree node:
...
What confuses me is how Xalan says it can't find the template when it's
there.
That's because you confused named templates and templates
matching elements. You use
<xsl:apply-templates select="p"/>
to tell the processor to apply tepleates to the elements
you have selected.
You use xsl:call-template for calling a named template, i.e.
one declared for example as
<xsl:template name="p">
... stuff ...
</xsl:template>
You can have both a match and a name on a template,
though this is a bit unconventional.
In your case, adding a name="p" to the template with
match='p' appears to do what you want, apart from:
> <xsl:template match="p">
> <xsl:text /><xsl:apply-templates /><xsl:text/>
> </xsl:template>
The <xsl:text/> are no-ops the way they are applied.
If you strip them, the template becomes:
<xsl:template match="p">
<xsl:apply-templates />
</xsl:template>
Calling this after adding a name is the same as
using xsl:apply-templates in the ssame place where
you call it. Furthermore, the template does exactly
the same as the built-in template matching p, so you
can omit it completely.
Furthermore
> Xalan (1.3 on Linux),
Upgrading to a more recent version is strongly recommended.
2.3.1 is available.
J.Pietschmann
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list