xsl-list
[Top] [All Lists]

Re: [xsl] xsl:function vs. xsl:template

2008-11-19 08:40:47
What are other benefits/shortcomings of either side? I haven't found
any documentation on this issue but would appreciate any hints as to
where to find some.

Benefits of using <xsl:function/>:

  1. Composability.

   2. Looks great in an expression which uses it as a parameter, as
return value or as a partial application.

   3. Readability (compactness) and maintainability.

   4. More loose coupling (does not depend on an  implicit context node)

   5. Can be referenced in an XPath expression

Shortcomings:

   1. Parameters are identified only by position (not by name)

    2. Can be impure (can have a side effect, such as creating new
node(s)) and just by looking at an expression referencing this
function people may not understand that it has a side effect. However
this possibility of confusion can be eliminated if proper naming is
used.

I tend always to use <xsl:function/>. In the cases when the function
creates new node(s) I follow the convention of starting its local-name
with the string "make", as in makePerson().


-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play



On Wed, Nov 19, 2008 at 4:38 AM, Felix Geller <fgeller(_at_)gmail(_dot_)com> 
wrote:
Hi all,

  how does the experienced XSLT 2.0 programmer decide on whether to
use a xsl:function or a (named) xsl:template? Are any performance
issues involved (the processor I'm using is Saxon)?

When trying to comprehend a stylesheet, I find it easier if the
control-flow is managed by explicit function calls.
Using functions imposes the additional "burden" of passing the node to
work on, when compared to xsl:call-template. However, passing the node
brings the benefit of making the "context" explicit.
Being able to use a function in XPath expression also offers a less
verbose invocation of functionality.



cheers

-- Felix

--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>