xslt - XSL recursive call - xsl:functions vs xsl:template with call template -


i have basic query. have been using xsl:template , use call tempate make recursive calls template. see xsl:function has feasibility make recursive function calls recursive template calls , achieve same. when should xsl:function used , when should xsl:template used. not sure diffence between 2 , when should used. special features of each of them. can please me understand better.

this how replied similar question 3 years ago:

benefits of using <xsl:function/>:

  1. composability.

  2. looks great in expression uses parameter, return value or partial application.

  3. readability (compactness) , maintainability.

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

  5. can referenced in xpath expression

shortcomings:

  1. parameters identified position (not name)

  2. can impure (can have side effect, such creating new node(s)) , looking @ expression referencing function people may not understand has side effect. possibility of confusion can eliminated if proper naming used.

i tend use <xsl:function/>. in cases when function creates new node(s) follow convention of starting local-name string "make", in makeperson().

i can add this:

always when possible use <xsl:function>.

in xpath 3.0 functions first-class data type of language (aka hof -- higher-order functions). can passed parameters or returned result to/from other functions.

this incredibly powerful leap forward using named templates.


Comments