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

RE: xslt 2.0 challenge

Subject: RE: xslt 2.0 challenge
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Thu, 8 Apr 2004 13:35:13 +0100
xsl variable total column
Ok here's my attempt.  This is as much about learning 2.0 as find a
solution, so all comments/criticisms welcome, including code formatting
suggestions (that's if the formatting makes it though the mailer).

<xsl:template match="/">

    <xsl:variable name="spanspec" select="/table/tgroup/spanspec"/>

    <!-- constucts a sequence of the two colspecs, note the 'as' -->
    <xsl:variable name="first" as="element()+">
      <xsl:sequence
select="/table//colspec[(preceding-sibling::colspan[@colname =
$spanspec/@namest]
                                           and
 
following-sibling::colspan[@colname = $spanspec/@nameend])
                                           or
                                           @colname = $spanspec/@namest
                                           or
                                           @colname =
$spanspec/@nameend]"/>
    </xsl:variable>

 
    <!-- sums the columns specified by the start and end column
         by the total number of columns, and then
         formats it to two decimal places
         and concats on a percentage symbol -->
    <xsl:value-of select="concat(
                            string(
                              format-number(
                                (sum(for $x in $first/@colwidth return
number(translate($x,'m','')))
                                div
                                sum(for $x in
$first/../colspec/@colwidth return number(translate($x,'m',''))))
                                * 100,
                              '00.00')
                            )
                            ,'%')"/>
     

</xsl:template>

One point of interest here is the the $first variable must be declared
as 'element()+' so that we can access it's siblings later on (thanks to
Roger L. Costello post on the Saxon list for that). 

This should be faster and less memory hungry than building three
temporary trees, I will get around to testing it out soon.

cheers
andrew

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.