[xsl] xslt 2.0 challenge

Subject: [xsl] xslt 2.0 challenge
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Thu, 8 Apr 2004 12:29:37 +0100
Consider the following CALS table xml fragment, especially the
<spanspec>: 

<table id="XBWQ24006" frame="TOPBOT">
  <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"/>
      <row>
         ...

I need to calculate a width for the spanspec, and I'm hoping xslt 2.0
can help me out here.

The steps involved are:

1.  Find the corresponding start and end <colspecs> based on @namest and
@nameend
2.  Sum the @colwidth values for the <colspecs> between (and including)
the columns found in step1
3.  Divide that value by the sum of all colwidths for that group
(siblings) and add on a % symbol

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.

Is it possible to now do it in a single pass? 

(the width should work out to be 38.46%)

Happy Easter...

andrew

Current Thread