Re: [xsl] [xslt 2.0] Difference betwen functions and templates

Subject: Re: [xsl] [xslt 2.0] Difference betwen functions and templates
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Thu, 19 Jul 2007 09:42:32 +0100
On 7/19/07, Abel Braaksma <abel.online@xxxxxxxxx> wrote:
   6. If you want polymorphism (partially, only nr of arguments) you
must use a function

You can use import precedence with named templates to get single polymorphism eg:

"Specific.xslt" :

<xsl:import href="common.xslt"/>
	
<xsl:template match="/">
	<xsl:call-template name="commonTemplate"/>
</xsl:template>

<xsl:template name="poly">Specfic</xsl:template>


and then "Common.xslt" :


<xsl:template name="commonTemplate">
	<xsl:call-template name="poly"/>
</xsl:template>	

<xsl:template name="poly">Common</xsl:template>

The output is "Specific" because the named template "poly" in the
specific stylesheet has a higher import precedence than that in the
common stylesheet.

You can make the poly template in common pseudo-abstract by doing
something like:

<xsl:template name="poly">
 <xsl:message terminate="yes" select="'This stylesheet must be
imported by another stylesheet and cannot be run on its own...'"/>

cheers
andrew

--
http://andrewjwelch.com

Current Thread