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

RE: Calculating column widths

Subject: RE: Calculating column widths
From: "Beckers, Marc" <Marc.Beckers@xxxxxxxxxxxxxx>
Date: Wed, 16 May 2001 18:33:57 +0200
column widths xsl
Hello Mike,

> > My question:
> > how can I do this calculation in one parse?
> > The sum() function requires a node-set
> > and numeric values to function properly,
> > and I have been unable to do the stripping
> > and the calculation in one template.
> 
> You could do the summation "by hand" in a recursive template, 
> rather than
> using the sum() function, but I'm not sure I'd recommend 
> this. It rather
> depends what you're trying to achieve.
> 
>
Yes, I had tried this, based on the example
on page 502 of your book (1st edition).
I would prefer it, but I can't get it
to work. I am enclosing the XSLT code. In this,
I am only stripping the proportional unit
indicator "*" from the CALS colwidth value. 
This stylesheet excerpt as it stands
is returning "Error" for the variable "rest"
and so the whole calculation won't work.
Also, the "self" variable is giving me
an empty value....
(I tried with Saxon 6.02 or Saxon 6.3)

<!-- Nested tables: no frame -->
<xsl:template match="entrytbl">
  <td><table>
    <xsl:attribute name="border">0</xsl:attribute>
    <xsl:attribute name="class">color</xsl:attribute>
    <xsl:if test="boolean(colspec[@colwidth]) or colspec[@align]">
      <colgroup>
        <xsl:call-template name="make.colgroup"/>
      </colgroup>
    </xsl:if>
    <xsl:apply-templates/>
  </table></td>
</xsl:template>

<xsl:template name="make.colgroup">
      <xsl:for-each select="colspec">
        <col>
          <!-- grab alignment -->
          <xsl:if test="@align">
            <xsl:attribute name="align">
              <xsl:value-of select="@align"/>
            </xsl:attribute>
          </xsl:if>
          <!-- read in value of column width -->
          <xsl:if test="@colwidth">
            <xsl:variable name="width">
              <xsl:call-template name="calculate.colwidth">
                <xsl:with-param name="context" select="../colspec"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:attribute name="width">
              <xsl:value-of select="concat($width,'%')"/>
            </xsl:attribute>
          </xsl:if>
        </col>
      </xsl:for-each>
</xsl:template>

<!-- the context of this named template will be colspec -->
  <xsl:template name="calculate.colwidth">
    <xsl:param name="context"/>
    <xsl:choose>
      <xsl:when test="$context">
        <xsl:variable name="first">
          <xsl:apply-templates select="$context[1]/@colwidth"/>
        </xsl:variable>
        <xsl:variable name="rest">
          <xsl:call-template name="calculate.colwidth">
            <xsl:with-param name="context"
select="$context[position()!=1]/@colwidth"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="sum">
         <xsl:value-of select="$first + $rest"/>
        </xsl:variable>
        <xsl:variable name="sum-as-number">
         <xsl:value-of select="substring-before($sum, '*')"/>
        </xsl:variable>
        <xsl:variable name="self">
          <xsl:variable name="widthval">
             <xsl:value-of select="@colwidth"/>
          </xsl:variable>
          <xsl:value-of select="substring-before($widthval, '*')"/>
        </xsl:variable>
        <xsl:value-of select="$rest"/>
        <!-- what I really want is: -->
        <!--xsl:value-of select="round(($self div $sum-as-number) * 97)"/-->
      </xsl:when>
      <xsl:otherwise>Error</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

What am I doing wrong?

Thanks,
Marc


 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.