This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Calculating column widths


Hello list,
I am trying to calculate column widths
for HTML tables generated from CALS
tables.
In CALS, you can set column widths as
absolute or proportional. Unfortunately,
browsers do not support the proportional
setting on an HTML width attribute.
This is a pain.
My approach is to strip the CALS colwidth
values of the measurement unit and calculate
the resulting numeric value as a percentage of our
standard HTML table width, which is 97%.

I currently use two parses: one to strip
the unit identifier off the CALS colwidth,
and another to do the calculation, which
is 
"(current colwidth + sum of all colwidths) * 97"

In my first parse (strip):

<!-- Strip measurement unit sign off colwidth values -->
  <xsl:template match="table//colspec[@colwidth]">
    <xsl:param name="colwidth" select="@colwidth"/>
    <xsl:variable name="unit">
      <xsl:choose>
        <xsl:when test="@colwidth[contains($colwidth, '*')]">*</xsl:when>
        <xsl:when test="@colwidth[contains($colwidth, 'pt')]">pt</xsl:when>
        <xsl:when test="@colwidth[contains($colwidth, 'cm')]">cm</xsl:when>
        <xsl:when test="@colwidth[contains($colwidth, 'mm')]">mm</xsl:when>
        <xsl:when test="@colwidth[contains($colwidth, 'pi')]">pi</xsl:when>
        <xsl:when test="@colwidth[contains($colwidth, 'in')]">in</xsl:when>
        <xsl:otherwise></xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <colspec>
      <xsl:copy-of select="@*[not(@colwidth)]"/>
      <xsl:attribute name="colwidth">
        <xsl:value-of select="substring-before($colwidth, $unit)"/>
      </xsl:attribute>
    </colspec>
  </xsl:template>

In my second parse (applied to the output of the first):

<xsl:template name="make.colgroup">
      <xsl:param name="sum" select="sum(colspec/@colwidth)"/>
      <xsl:for-each select="colspec">
        <xsl:variable name="self" select="@colwidth"/>
        <col>
          <!-- grab the alignment -->
          <xsl:if test="@align">
            <xsl:attribute name="align">
              <xsl:value-of select="@align"/>
            </xsl:attribute>
          </xsl:if>
          <!-- calculate column width as a percentage of 97 -->
          <xsl:if test="@colwidth">
            <xsl:variable name="width">
              <xsl:value-of select="round(($self div $sum) * 97)"/>
            </xsl:variable>
            <xsl:attribute name="width">
              <xsl:value-of select="concat($width,'%')"/>
            </xsl:attribute>
          </xsl:if>
        </col>
      </xsl:for-each>
</xsl:template>

This template is called in templates
processing the CALS tgroup and entrytbl
elements, depending on the presence
of the attribute "align" or "colwidth"
on the CALS colspec element.

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.

Any ideas|solutions?

Thanks,
Dr. Marc Beckers
Documentation Consultant
Software AG
Uhlandstraße 12
D-64297 Darmstadt
Phone +49-6151-92-1322
Fax              -1612
mailto:Marc.Beckers@softwareag.com
http://www.softwareag.com


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]