xsl-list
[Top] [All Lists]

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

2007-07-19 01:42:49
On 7/19/07, Abel Braaksma <abel(_dot_)online(_at_)xs4all(_dot_)nl> 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--