RE: [xsl] xslt 2.0 challenge

Subject: RE: [xsl] xslt 2.0 challenge
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Thu, 8 Apr 2004 14:38:17 +0100
> <xsl:template match="spanspec">
>  <xsl:apply-templates mode="s" 
> select="ancestor::tgroup//*[colspec[current()/@namest=@colname
> ]]/colspec[1]">
>    <xsl:with-param name="start" select="@namest"/>
>    <xsl:with-param name="end" select="@nameend"/>
>  </xsl:apply-templates>
> </xsl:template>
> 
> <xsl:template mode="s" match="colspec">
>  <xsl:param name="start" select="/.."/>
>  <xsl:param name="end" select="/.."/>
>  <xsl:param name="totala" select="0"/>
>  <xsl:param name="totalb" select="0"/>
>  <xsl:variable name="w" select="translate(@colwidth,'m','')"/>
>  <xsl:choose>
>   <xsl:when test="following-sibling::colspec[@colname=$start] 
> or preceding-sibling::colspec[@colname=$end]">
>    <xsl:apply-templates mode="s" 
> select="following-sibling::colspec[1]">
>      <xsl:with-param name="start" select="$start"/>
>      <xsl:with-param name="end" select="$end"/>
>      <xsl:with-param name="totala" select="$totala"/>
>      <xsl:with-param name="totalb" select="$totalb+$w"/>
>    </xsl:apply-templates>
>   <xsl:if test="not(following-sibling::colspec)">
>    [ <xsl:value-of select="format-number(100*($totala) div 
> ($totalb +  $w),'#.##')"/>% ]
>   </xsl:if>
>   </xsl:when>
>   <xsl:otherwise>
>    <xsl:apply-templates mode="s" 
> select="following-sibling::colspec[1]">
>      <xsl:with-param name="start" select="$start"/>
>      <xsl:with-param name="end" select="$end"/>
>      <xsl:with-param name="totala" select="$totala+$w"/>
>      <xsl:with-param name="totalb" select="$totalb+$w"/>
>    </xsl:apply-templates>
>   <xsl:if test="not(following-sibling::colspec)">
>    [ <xsl:value-of select="format-number(100*($totala +  $w) 
> div ($totalb +  $w),'#.##')"/>% ]
>   </xsl:if>
>   </xsl:otherwise>
>  </xsl:choose>
> </xsl:template>


This is very good,  here are some negative observations:

1.  It repeats the xsl:if test not(following-sibling::colspec) twice (I
know that's harsh :)
2.  The 2.0 version is 3-ish lines, this has 30-ish lines (I say 'ish'
because I'm counting xpath as 1 line)
3.  This will require a new stack frame for each <colspec>, the 2.0
version doesn't (harsh again)

After all that has been said about xpath 2.0, I'm not sure which is more
readable...


andrew

Current Thread