xsl-list
[Top] [All Lists]

RE: CALS Tables (was: RE: XSL(check attribute exists in the parent node and get value for another attribute in the same node))

2003-08-14 01:41:18


hi andrew,

If you have a css which has t,bl & r defined, can you
please copy it for me.

Thanks,

Sure, 

It's as you would have probably guessed:

.t {border-top-color:black ; border-top-style:solid; border-top-width:1}
.b {border-bottom-color:black ; border-bottom-style:solid ;
border-bottom-width:1}
.l {border-left-color:black ; border-left-style:solid ;
border-left-width:1}
.r {border-right-color:black ; border-right-style:solid ;
border-right-width:1}



--- Andrew Welch <AWelch(_at_)piper-group(_dot_)com> wrote:

For anyone working with CALS tables, here is a
stylesheet I wrote a while back to display them.  I
think it covers all of the variations that CALS
allows (which is a lot).

It will produce a table 300px high, with a 'fixed
header' so that the body scrolls while the head is
fixed.

It just requires that 't' 'b' 'l' and 'r' are
defined in your CSS as 1px solid black borders.

Im confident that it can take whatever gets thrown
at it, but if anyone can improve it (and repost :)
or find a fault, please let me know.

cheers
andrew

(Ive just removed some things specific to my
company, so if some of the html structure looks
slightly off, its probably because Ive just deleted
some it)


<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:exsl="http://exslt.org/common";
    extension-element-prefixes="exsl"
    version="1.0">

<xsl:param name="print" select="'no'"/>
<xsl:param name="printWidth" select="0"/>

<!-- tests for aircrew dm, we dont use scroll bars
on aircrew dm's-->
<xsl:variable name="acrw"
select="boolean(/dmodule/content/acrw)"/>

<xsl:variable name="colspecs-firstPass-rtf">
  <xsl:for-each select="//table">
    <table id="{generate-id()}">
      <xsl:for-each select="tgroup">
        <tgroup id="{generate-id()}">
          <xsl:for-each select=".//colspec">
            <col id="{generate-id()}"
colname="{(_at_)colname}"
number="{count(preceding-sibling::colspec|.)}"
width="{translate(@colwidth,'inm*','')}"
align="{(_at_)align}">
              <xsl:attribute name="inHead">
                <xsl:choose>
                  <xsl:when
test="parent::thead">yes</xsl:when>
                  <xsl:otherwise>no</xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
            </col>
          </xsl:for-each>
          <xsl:for-each select="spanspec">
            <spanspec id="{generate-id()}"
spanname="{(_at_)spanname}" namest="{(_at_)namest}"
nameend="{(_at_)nameend}" align="{(_at_)align}"/>
          </xsl:for-each>
        </tgroup>
      </xsl:for-each>
    </table>
  </xsl:for-each>
</xsl:variable>

<xsl:variable name="colspecs-firstPass"
select="exsl:node-set($colspecs-firstPass-rtf)"/>

<xsl:variable name="colspecs-rtf">
  <xsl:for-each select="$colspecs-firstPass">
    <xsl:for-each select="table">
      <table id="{(_at_)id}">
        <xsl:for-each select="tgroup">
          <tgroup id="{(_at_)id}">
            <xsl:variable name="totalGroupWidth"
select="sum(col[(_at_)inHead = 'no']/@width)"/>
            <xsl:variable name="totalHeadWidth"
select="sum(col[(_at_)inHead = 'yes']/@width)"/>
            <xsl:for-each select="col">
              <col id="{(_at_)id}" colname="{(_at_)colname}"
number="{(_at_)number}" align="{(_at_)align}"
inHead="{(_at_)inHead}">
                <xsl:attribute name="width">
                  <xsl:choose>
                    <xsl:when test="@inHead = 'no'">
                      <xsl:value-of select="@width
div $totalGroupWidth * 100"/>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="@width
div $totalHeadWidth * 100"/>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:attribute>
              </col>
            </xsl:for-each>
            <xsl:for-each select="spanspec">
              <xsl:copy-of select="."/>
            </xsl:for-each>
          </tgroup>
        </xsl:for-each>
      </table>
    </xsl:for-each>
  </xsl:for-each>
</xsl:variable>

<xsl:variable name="colspecs"
select="exsl:node-set($colspecs-rtf)"/>

<xsl:variable name="spanspecs-rtf">
  <xsl:for-each select="$colspecs">
    <xsl:for-each select="table/tgroup">
      <xsl:variable name="tgroupId" select="@id"/>
      <xsl:for-each select="spanspec">
        <col id="{(_at_)id}" spanname="{(_at_)spanname}">
          <xsl:attribute name="colspan">
            <xsl:value-of select="1 +
preceding-sibling::col[(_at_)colname =
current()/@nameend]/@number -
preceding-sibling::col[(_at_)colname =
current()/@namest]/@number"/>
          </xsl:attribute>
          <xsl:attribute name="width">
            <xsl:call-template
name="calculateWidth">
              <xsl:with-param name="tgroupId"
select="$tgroupId"/>
              <xsl:with-param name="startCol"
select="preceding-sibling::col[(_at_)colname =
current()/@namest]/@number"/>
              <xsl:with-param name="endCol"
select="preceding-sibling::col[(_at_)colname =
current()/@nameend]/@number"/>
            </xsl:call-template>
          </xsl:attribute>
          <xsl:attribute name="align">
            <xsl:choose>
              <xsl:when
test="string-length(@align)"><xsl:value-of
select="@align"/></xsl:when>
              <xsl:otherwise><xsl:value-of
select="preceding-sibling::col[(_at_)colname =
current()/@nameend]/@align"/></xsl:otherwise>
            </xsl:choose>
          </xsl:attribute>
        </col>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:for-each>
</xsl:variable>

<xsl:variable name="spanspecs"
select="exsl:node-set($spanspecs-rtf)"/>

<xsl:template name="calculateWidth">
  <xsl:param name="tgroupId" select="0"/>
  <xsl:param name="startCol" select="0"/>
  <xsl:param name="endCol" select="0"/>
  <xsl:param name="totalWidth" select="0"/>
  <xsl:choose>
    <xsl:when test="$startCol &lt;= $endCol">
      <xsl:call-template name="calculateWidth">
        <xsl:with-param name="tgroupId"
select="$tgroupId"/>
        <xsl:with-param name="startCol"
select="$startCol + 1"/>
        <xsl:with-param name="endCol"
select="$endCol"/>
        <xsl:with-param name="totalWidth">
          <xsl:for-each select="$colspecs">
            <xsl:for-each select="table/tgroup[(_at_)id =
$tgroupId]">
              <xsl:value-of select="col[(_at_)number =
$startCol]/@width + $totalWidth"/>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$totalWidth"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="getBorders">
  <xsl:param name="frame" select="''"/>
  <xsl:choose>
    <xsl:when test="$frame = 'ALL'">t b l
r</xsl:when>
    <xsl:when test="$frame = 'TOP'">t</xsl:when>
    <xsl:when test="$frame = 'TOPBOT'">t
b</xsl:when>
    <xsl:when test="$frame = 'BOTTOM'">b</xsl:when>
    <xsl:when test="$frame = 'SIDES'">l r</xsl:when>

=== message truncated ===


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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





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