[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:function vs. xsl:template

Subject: Re: xsl:function vs. xsl:template
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Wed, 19 Nov 2008 05:40:24 -0800
Re:  xsl:function vs. xsl:template
> 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@xxxxxxxxx> 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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.