|
Subject: Re: [xsl] xslt 2.0 challenge From: David Carlisle <davidc@xxxxxxxxx> Date: Thu, 8 Apr 2004 13:56:13 +0100 |
My xslt 1.0 solution uses 3 temporary trees and a recursive template to
remove the 'mm' and sum the correct <colspec>'s respectively. This
still seems to run pretty fast, but I'm hoping to do away with it using
the new features in 2.0.
Here's a one-pass XSLT1 solution.
<tgroup cols="4">
<colspec colname="C.HNL" colnum="1" colwidth="55mm" align="LEFT"/>
<colspec colname="C.HNK" colnum="2" colwidth="32mm" align="CENTER"/>
<colspec colname="C.HNJ" colnum="3" colwidth="33mm" align="CENTER"/>
<colspec colname="C.HNI" colnum="4" colwidth="49mm" align="CENTER"/>
<spanspec spanname="S.HOJ" namest="C.HNG" nameend="C.HNF"
rowsep="1"/>
<thead>
<colspec colname="C.HNH" colnum="1" colwidth="55mm" align="LEFT"/>
<colspec colname="C.HNG" colnum="2" colwidth="32mm"
align="CENTER"/>
<colspec colname="C.HNF" colnum="3" colwidth="33mm"
align="CENTER"/>
<colspec colname="C.HNE" colnum="4" colwidth="49mm"
align="CENTER"/>
</thead>
</tgroup>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<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>
</xsl:stylesheet>
$ saxon spanspec.xml spanspec.xsl
<?xml version="1.0" encoding="utf-8"?>
[ 38.46% ]
--
http://www.dcarlisle.demon.co.uk/matthew
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] xslt 2.0 challenge, Andrew Welch | Thread | Re: [xsl] xslt 2.0 challenge, Jeni Tennison |
| Re: [xsl] Can I change variable con, Vikram Barate | Date | Re: [xsl] xslt 2.0 challenge, David Carlisle |
| Month |