RE: [xsl] Is it possible to test if a named template exists?

Subject: RE: [xsl] Is it possible to test if a named template exists?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 5 Sep 2006 14:17:03 +0100
Provided you use import rather than include, you could define a template
with the required name in your (imported) module: when you call it, if your
local version is called then you know there wasn't one with that name in the
importing module.

Has to be "import", because otherwise it's an error to have two templates
with the same name.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Neville Lugton [mailto:nlugton@xxxxxxxxxxx] 
> Sent: 05 September 2006 13:56
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Is it possible to test if a named template exists?
> 
> Simplified.. I am trying to use "xsl:call-template" from an 
> included .xsl file to insert a named template stored in the 
> main .xsl file.
> 
> However not all the main files are going to need/have the 
> named template. So I only want to use "xsl:call-template" if 
> the target document has the required named template.
> 
> So far I'm working on the theory I need something like the code below:
> 
> <xsl:template match="/">
>     <xsl:call-template name="insertHeader"/> </xsl:template>
> 
> <xsl:template match="insertHeader">
>     <!-- this template is included in ALL files -->
>     <xsl:if test="element-available(pageScripts)">
>         <xsl:call-template name="insertScripts"/>
>     </xsl:if>
> </xsl:template>
> 
> <xsl:template name="insertScripts">
>     <!-- NOT all files have this template -->
>    do things!!
> </xsl:template>
> 
> Can anyone help me with what test I need for "<xsl:if 
> test="??????">" or suggest another way to go about it all.
> 
> Regards
> Neville Lugton

Current Thread