[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: xslt 2.0 challenge
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
|
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
|