xsl-list
[Top] [All Lists]

stylesheet functions or named templates

2005-12-19 18:34:07

Are there distinctions to be drawn that are not merely idiomatic or
stylistic between a stylesheet function and a named template?

That is, are there runtime considerations between a pair of named templates
like this:


  <xsl:template name="correctDate">
    <xsl:param name="dateParts"/>
    <xsl:variable name="tokens" select="fn:tokenize($dateParts, '/')"/>
    <xsl:value-of select="$tokens[3]"/>
    <xsl:text>-</xsl:text>
    <xsl:call-template name="pad">
      <xsl:with-param name="digits" select="$tokens[1]"/>
    </xsl:call-template>
    <xsl:text>-</xsl:text>
    <xsl:call-template name="pad">
      <xsl:with-param name="digits" select="$tokens[2]"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="pad">
    <xsl:param name="digits"/>
    <xsl:choose>
      <xsl:when test="fn:string-length($digits) = 1">
        <xsl:value-of select="concat('0', $digits)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$digits"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


And this pair of user defined functions:

  <xsl:function name="sfn:correctDate" as="xs:date">
    <xsl:param name="s"/>
    <xsl:variable name="seq" 
        select="fn:tokenize($s, '/')"/>
    <xsl:value-of 
        select="concat($seq[3],'-',sfn:pad($seq[1]),'-',sfn:pad($seq[2]))"/>
  </xsl:function>

  <xsl:function name="sfn:pad">
    <xsl:param name="digits"/>
    <xsl:choose>
      <xsl:when test="fn:string-length($digits) = 1">
        <xsl:value-of select="concat('0',$digits)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$digits"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>


Both contain template bodies, the tree representing the named *correctDate*
template is a few nodes bigger, perhaps.  I can call functions from within
XPath expressions.  Anything else to consider in terms of execution
efficiency?


TIA,

Mike

-----------------------------------
Mike Haarman,
XSL Developer,
Internet Broadcasting Systems, Inc.

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