Re: [xsl] template in template? (references)

Subject: Re: [xsl] template in template? (references)
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Fri, 15 Jun 2001 11:05:10 -0400
[Daniel Bauke]

> yep, i'm still asking stup..erm, simple questions :-)
> well, i'm wondering if it's possible to use sth like following:
> <xsl:template match="ref">
>    <link href="@id"> go to ref </link>
> </xsl:template>
> <xsl:template match="link">
>    <a href="@href"><xsl:apply-templates/></link>
> </xsl:template>

If I can understand what you are looking for (which you haven't made clear
at all), The answer is probably variables.  You cannot write out an element
and then have the stylesheet use it.  But you can select the nodes or values
you are interested in and assign them to one or more variables.  Remember
that once a variable is assigned within an invocation of a template, it
can't be changed.

You can pass these variables to other templates using parameters.  In fact,
you may be able to pass a parameter without having created a varable first.
So your example might go like this:

 <xsl:template match="ref">
     <xsl:call-template name='doLink'>
         <xsl:with-param name='theLink' select='@id'/>

 <xsl:template name="doLink">
   <xsl:param name='theLink'/>
    <a href="{$theLink}"><xsl:value-of select='link'/></a>

In this example, you wouldn't really need to use a parameter, but I'm just
showing how to use them.

Tom P

 XSL-List info and archive:

Current Thread