This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: template in template? (references)


[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:call-template>
 </xsl:template>

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

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:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]