|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] On XSLT 2.0 Writing Styles
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() <=
$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() <=
$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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








