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

Subject: Re: [xsl] [xslt 2.0] Difference betwen functions and templates
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 23 Jul 2007 16:13:13 +0100
> Has is also be explained in this thread already that another
> difference is that xsl:functions do not receive any initial
> focus?

That can be viewed (more or less) as a difference in syntax rather than
a difference in functionality.

<xsl:template name="my:f">
  <xsl:with-param name="x" select="$x"/>...

is more or less the same as

my:f(.,$x)

passing the current node explictly, with the body of the function being
the body of the template, wrapped in

<xsl:param name="here" as="item()"/>
<xsl:param name="x"/>
<xsl:for-each select="$here">
 .....
</xsl:for-each>




 or to be even closer, you can pass
last() as well

my:f(.,last(),$x)


This doesn't capture current mode, and the state of any grouping
constructs that are in effect, but it does mean that you can rewrite the
vast majority of existing named templates as functions if you wish.
For example, if you want to port them to XQuery. Of coourse templates
using modes or xsl:for-each-group would have other difficulties being
translated to Xquery, anyway.

David


________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

Current Thread