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

On XSLT 2.0 Writing Styles

Subject: On XSLT 2.0 Writing Styles
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sat, 11 Oct 2003 09:14:07 +0200
writing functions in xslt
In XSLT 2.0 the programmer has the choice to write the same code in two
different styles as below:

func-dvc-foldl.xsl:
=============
<xsl:stylesheet version="2.0"
 xmlns:f="http://fxsl.sf.net/"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 exclude-result-prefixes="f">

    <xsl:import href="func-apply.xsl"/>

    <xsl:function name="f:foldl">
      <xsl:param name="pFunc" as="element()"/>
      <xsl:param name="pA0"/>
      <xsl:param name="pList" as="item()*"/>

      <xsl:sequence select=
       "if(empty($pList))
          then
             $pA0
          else
             for $vcntList in count($pList) return
               if($vcntList = 1)
                  then
                     f:apply($pFunc, $pA0, $pList[1])
                  else
                     for $vHalfLen in floor($vcntList div 2) return
                       f:foldl($pFunc,
                             f:foldl($pFunc, $pA0, $pList[position() &lt;=
$vHalfLen]),
                             $pList[position() > $vHalfLen]
                             )"/>

    </xsl:function>

</xsl:stylesheet>


and


func-dvc-foldl-oldStyle.xsl:
===================
<xsl:stylesheet version="2.0"
 xmlns:f="http://fxsl.sf.net/"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 exclude-result-prefixes="f">

    <xsl:import href="func-apply.xsl"/>

    <xsl:function name="f:foldl">
      <xsl:param name="pFunc" as="element()"/>
      <xsl:param name="pA0"/>
      <xsl:param name="pList" as="item()*"/>

      <xsl:choose>
         <xsl:when test="not($pList)">
            <xsl:copy-of select="$pA0"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:variable name="vcntList" select="count($pList)"/>
            <xsl:choose>
              <xsl:when test="$vcntList = 1">
                <xsl:sequence select="f:apply($pFunc,$pA0, $pList[1])"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:variable name="vHalfLen"
                              select="floor($vcntList div 2)"/>

                <xsl:sequence select=
                "f:foldl($pFunc,
                         f:foldl($pFunc, $pA0, $pList[position() &lt;=
$vHalfLen]),
                         $pList[position() > $vHalfLen]
                         )"/>
              </xsl:otherwise>
            </xsl:choose>
         </xsl:otherwise>
      </xsl:choose>
    </xsl:function>
</xsl:stylesheet>


Which one of these two styles should be preferred?

What are the advantages and shortcomings of each style regarding
readability, compactness, flexibility, efficiency and maintainability?

Ideally, there should be an agreement (consensus) on the answers to
questions like these and one should be able to find such answers easily in
the archives and the FAQ.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.