| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514 | <?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"                xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"                exclude-result-prefixes="doc"                version="1.0"><!-- ********************************************************************     $Id$     ********************************************************************     This file is part of the XSL DocBook Stylesheet distribution.     See ../README or http://docbook.sf.net/release/xsl/current/ for     copyright and other information.     ******************************************************************** --><!-- ==================================================================== --><xsl:template name="blank.spans">  <xsl:param name="cols" select="1"/>  <xsl:if test="$cols > 0">    <xsl:text>0:</xsl:text>    <xsl:call-template name="blank.spans">      <xsl:with-param name="cols" select="$cols - 1"/>    </xsl:call-template>  </xsl:if></xsl:template><xsl:template name="calculate.following.spans">  <xsl:param name="colspan" select="1"/>  <xsl:param name="spans" select="''"/>  <xsl:choose>    <xsl:when test="$colspan > 0">      <xsl:call-template name="calculate.following.spans">        <xsl:with-param name="colspan" select="$colspan - 1"/>        <xsl:with-param name="spans" select="substring-after($spans,':')"/>      </xsl:call-template>    </xsl:when>    <xsl:otherwise>      <xsl:value-of select="$spans"/>    </xsl:otherwise>  </xsl:choose></xsl:template><xsl:template name="finaltd">  <xsl:param name="spans"/>  <xsl:param name="col" select="0"/>  <xsl:if test="$spans != ''">    <xsl:choose>      <xsl:when test="starts-with($spans,'0:')">        <xsl:call-template name="empty.table.cell">          <xsl:with-param name="colnum" select="$col"/>        </xsl:call-template>      </xsl:when>      <xsl:otherwise></xsl:otherwise>    </xsl:choose>    <xsl:call-template name="finaltd">      <xsl:with-param name="spans" select="substring-after($spans,':')"/>      <xsl:with-param name="col" select="$col+1"/>    </xsl:call-template>  </xsl:if></xsl:template><xsl:template name="sfinaltd">  <xsl:param name="spans"/>  <xsl:if test="$spans != ''">    <xsl:choose>      <xsl:when test="starts-with($spans,'0:')">0:</xsl:when>      <xsl:otherwise>        <xsl:value-of select="substring-before($spans,':')-1"/>        <xsl:text>:</xsl:text>      </xsl:otherwise>    </xsl:choose>    <xsl:call-template name="sfinaltd">      <xsl:with-param name="spans" select="substring-after($spans,':')"/>    </xsl:call-template>  </xsl:if></xsl:template><xsl:template name="entry.colnum">  <xsl:param name="entry" select="."/>  <xsl:choose>    <xsl:when test="$entry/@spanname">      <xsl:variable name="spanname" select="$entry/@spanname"/>      <xsl:variable name="spanspec"                    select="($entry/ancestor::tgroup/spanspec[@spanname=$spanname]                             |$entry/ancestor::entrytbl/spanspec[@spanname=$spanname])[last()]"/>      <xsl:variable name="colspec"                    select="($entry/ancestor::tgroup/colspec[@colname=$spanspec/@namest]                             |$entry/ancestor::entrytbl/colspec[@colname=$spanspec/@namest])[last()]"/>      <xsl:call-template name="colspec.colnum">        <xsl:with-param name="colspec" select="$colspec"/>      </xsl:call-template>    </xsl:when>    <xsl:when test="$entry/@colname">      <xsl:variable name="colname" select="$entry/@colname"/>      <xsl:variable name="colspec"                    select="($entry/ancestor::tgroup/colspec[@colname=$colname]                             |$entry/ancestor::entrytbl/colspec[@colname=$colname])[last()]"/>      <xsl:call-template name="colspec.colnum">        <xsl:with-param name="colspec" select="$colspec"/>      </xsl:call-template>    </xsl:when>    <xsl:when test="$entry/@namest">      <xsl:variable name="namest" select="$entry/@namest"/>      <xsl:variable name="colspec"                    select="($entry/ancestor::tgroup/colspec[@colname=$namest]                             |$entry/ancestor::entrytbl/colspec[@colname=$namest])[last()]"/>      <xsl:call-template name="colspec.colnum">        <xsl:with-param name="colspec" select="$colspec"/>      </xsl:call-template>    </xsl:when>    <!-- no idea, return 0 -->    <xsl:otherwise>0</xsl:otherwise>  </xsl:choose></xsl:template><doc:template name="entry.colnum" xmlns=""><refpurpose>Determine the column number in which a given entry occurs</refpurpose><refdescription id="entry.colnum-desc"><para>If an <tag>entry</tag> has a<tag class="attribute">colname</tag> or<tag class="attribute">namest</tag> attribute, this templatewill determine the number of the column in which the entry should occur.For other <tag>entry</tag>s, nothing is returned.</para></refdescription><refparameter id="entry.colnum-params"><variablelist><varlistentry><term>entry</term><listitem><para>The <tag>entry</tag>-element which is to be tested.</para></listitem></varlistentry></variablelist></refparameter><refreturn id="entry.colnum-returns"><para>This template returns the column number if it can be determined,or 0 (the empty string)</para></refreturn></doc:template><xsl:template name="colspec.colnum">  <xsl:param name="colspec" select="."/>  <xsl:choose>    <xsl:when test="$colspec/@colnum">      <xsl:value-of select="$colspec/@colnum"/>    </xsl:when>    <xsl:when test="$colspec/preceding-sibling::colspec">      <xsl:variable name="prec.colspec.colnum">        <xsl:call-template name="colspec.colnum">          <xsl:with-param name="colspec"                          select="$colspec/preceding-sibling::colspec[1]"/>        </xsl:call-template>      </xsl:variable>      <xsl:value-of select="$prec.colspec.colnum + 1"/>    </xsl:when>    <xsl:otherwise>1</xsl:otherwise>  </xsl:choose></xsl:template><xsl:template name="calculate.colspan">  <xsl:param name="entry" select="."/>  <xsl:variable name="spanname" select="$entry/@spanname"/>  <xsl:variable name="spanspec"                select="($entry/ancestor::tgroup/spanspec[@spanname=$spanname]                         |$entry/ancestor::entrytbl/spanspec[@spanname=$spanname])[last()]"/>  <xsl:variable name="namest">    <xsl:choose>      <xsl:when test="@spanname">        <xsl:value-of select="$spanspec/@namest"/>      </xsl:when>      <xsl:otherwise>        <xsl:value-of select="$entry/@namest"/>      </xsl:otherwise>    </xsl:choose>  </xsl:variable>  <xsl:variable name="nameend">    <xsl:choose>      <xsl:when test="@spanname">        <xsl:value-of select="$spanspec/@nameend"/>      </xsl:when>      <xsl:otherwise>        <xsl:value-of select="$entry/@nameend"/>      </xsl:otherwise>    </xsl:choose>  </xsl:variable>  <xsl:variable name="scol">    <xsl:call-template name="colspec.colnum">      <xsl:with-param name="colspec"                      select="($entry/ancestor::tgroup/colspec[@colname=$namest]                               |$entry/ancestor::entrytbl/colspec[@colname=$namest])[last()]"/>    </xsl:call-template>  </xsl:variable>  <xsl:variable name="ecol">    <xsl:call-template name="colspec.colnum">      <xsl:with-param name="colspec"                      select="($entry/ancestor::tgroup/colspec[@colname=$nameend]                               |$entry/ancestor::entrytbl/colspec[@colname=$nameend])[last()]"/>    </xsl:call-template>  </xsl:variable>  <xsl:choose>    <xsl:when test="$namest != '' and $nameend != ''">      <xsl:choose>        <xsl:when test="number($ecol) >= number($scol)">          <xsl:value-of select="number($ecol) - number($scol) + 1"/>        </xsl:when>        <xsl:otherwise>          <xsl:value-of select="number($scol) - number($ecol) + 1"/>        </xsl:otherwise>      </xsl:choose>    </xsl:when>    <xsl:otherwise>1</xsl:otherwise>  </xsl:choose></xsl:template><xsl:template name="calculate.rowsep">  <xsl:param name="entry" select="."/>  <xsl:param name="colnum" select="0"/>  <xsl:call-template name="inherited.table.attribute">    <xsl:with-param name="entry" select="$entry"/>    <xsl:with-param name="colnum" select="$colnum"/>    <xsl:with-param name="attribute" select="'rowsep'"/>  </xsl:call-template></xsl:template><xsl:template name="calculate.colsep">  <xsl:param name="entry" select="."/>  <xsl:param name="colnum" select="0"/>  <xsl:call-template name="inherited.table.attribute">    <xsl:with-param name="entry" select="$entry"/>    <xsl:with-param name="colnum" select="$colnum"/>    <xsl:with-param name="attribute" select="'colsep'"/>  </xsl:call-template></xsl:template><xsl:template name="inherited.table.attribute">  <xsl:param name="entry" select="."/>  <xsl:param name="row" select="$entry/ancestor-or-self::row[1]"/>  <xsl:param name="colnum" select="0"/>  <xsl:param name="attribute" select="'colsep'"/>  <xsl:variable name="tgroup" select="$row/parent::*/parent::tgroup[1]"/>  <xsl:variable name="tbody" select="$row/parent::*[1]"/>  <xsl:variable name="table" select="($tgroup/ancestor::table                                     |$tgroup/ancestor::informaltable				     |$entry/ancestor::entrytbl)[last()]"/>  <xsl:variable name="entry.value">    <xsl:call-template name="get-attribute">      <xsl:with-param name="element" select="$entry"/>      <xsl:with-param name="attribute" select="$attribute"/>    </xsl:call-template>  </xsl:variable>  <xsl:variable name="row.value">    <xsl:call-template name="get-attribute">      <xsl:with-param name="element" select="$row"/>      <xsl:with-param name="attribute" select="$attribute"/>    </xsl:call-template>  </xsl:variable>  <xsl:variable name="span.value">    <xsl:if test="$entry/@spanname">      <xsl:variable name="spanname" select="$entry/@spanname"/>      <xsl:variable name="spanspec"                    select="$tgroup/spanspec[@spanname=$spanname]"/>      <xsl:variable name="span.colspec"                    select="$tgroup/colspec[@colname=$spanspec/@namest]"/>      <xsl:variable name="spanspec.value">        <xsl:call-template name="get-attribute">          <xsl:with-param name="element" select="$spanspec"/>          <xsl:with-param name="attribute" select="$attribute"/>        </xsl:call-template>      </xsl:variable>      <xsl:variable name="scolspec.value">        <xsl:call-template name="get-attribute">          <xsl:with-param name="element" select="$span.colspec"/>          <xsl:with-param name="attribute" select="$attribute"/>        </xsl:call-template>      </xsl:variable>      <xsl:choose>        <xsl:when test="$spanspec.value != ''">          <xsl:value-of select="$spanspec.value"/>        </xsl:when>        <xsl:when test="$scolspec.value != ''">          <xsl:value-of select="$scolspec.value"/>        </xsl:when>        <xsl:otherwise></xsl:otherwise>      </xsl:choose>    </xsl:if>  </xsl:variable>  <xsl:variable name="namest.value">    <xsl:if test="$entry/@namest">      <xsl:variable name="namest" select="$entry/@namest"/>      <xsl:variable name="colspec"                    select="$tgroup/colspec[@colname=$namest]"/>      <xsl:variable name="inner.namest.value">        <xsl:call-template name="get-attribute">          <xsl:with-param name="element" select="$colspec"/>          <xsl:with-param name="attribute" select="$attribute"/>        </xsl:call-template>      </xsl:variable>      <xsl:choose>        <xsl:when test="$inner.namest.value">          <xsl:value-of select="$inner.namest.value"/>        </xsl:when>        <xsl:otherwise></xsl:otherwise>      </xsl:choose>    </xsl:if>  </xsl:variable>  <xsl:variable name="tgroup.value">    <xsl:call-template name="get-attribute">      <xsl:with-param name="element" select="$tgroup"/>      <xsl:with-param name="attribute" select="$attribute"/>    </xsl:call-template>  </xsl:variable>  <xsl:variable name="tbody.value">    <xsl:call-template name="get-attribute">      <xsl:with-param name="element" select="$tbody"/>      <xsl:with-param name="attribute" select="$attribute"/>    </xsl:call-template>  </xsl:variable>  <xsl:variable name="table.value">    <xsl:call-template name="get-attribute">      <xsl:with-param name="element" select="$table"/>      <xsl:with-param name="attribute" select="$attribute"/>    </xsl:call-template>  </xsl:variable>  <xsl:variable name="default.value">    <!-- This section used to say that rowsep and colsep have defaults based -->    <!-- on the frame setting. Further reflection and closer examination of the -->    <!-- CALS spec reveals I was mistaken. The default is "1" for rowsep and colsep. -->    <!-- For everything else, the default is the tgroup value -->    <xsl:choose>      <xsl:when test="$tgroup.value != ''">        <xsl:value-of select="$tgroup.value"/>      </xsl:when>      <xsl:when test="$attribute = 'rowsep'">1</xsl:when>      <xsl:when test="$attribute = 'colsep'">1</xsl:when>      <xsl:otherwise><!-- empty --></xsl:otherwise>    </xsl:choose>  </xsl:variable>  <xsl:variable name="calc.colvalue">    <xsl:if test="$colnum > 0">      <xsl:call-template name="colnum.colspec">        <xsl:with-param name="colnum" select="$colnum"/>        <xsl:with-param name="attribute" select="$attribute"/>      </xsl:call-template>    </xsl:if>  </xsl:variable>  <xsl:choose>    <xsl:when test="$entry.value != ''">      <xsl:value-of select="$entry.value"/>    </xsl:when>    <xsl:when test="$row.value != ''">      <xsl:value-of select="$row.value"/>    </xsl:when>    <xsl:when test="$span.value != ''">      <xsl:value-of select="$span.value"/>    </xsl:when>    <xsl:when test="$namest.value != ''">      <xsl:value-of select="$namest.value"/>    </xsl:when>    <xsl:when test="$calc.colvalue != ''">      <xsl:value-of select="$calc.colvalue"/>    </xsl:when>    <xsl:when test="$tbody.value != ''">      <xsl:value-of select="$tbody.value"/>    </xsl:when>    <xsl:when test="$tgroup.value != ''">      <xsl:value-of select="$tgroup.value"/>    </xsl:when>    <xsl:when test="$table.value != ''">      <xsl:value-of select="$table.value"/>    </xsl:when>    <xsl:otherwise>      <xsl:value-of select="$default.value"/>    </xsl:otherwise>  </xsl:choose></xsl:template><xsl:template name="colnum.colspec">  <xsl:param name="colnum" select="0"/>  <xsl:param name="attribute" select="'colname'"/>  <xsl:param name="colspec.ancestor"              select="(ancestor::tgroup|ancestor::entrytbl)	             [position() = last()]"/>  <xsl:param name="colspecs" select="$colspec.ancestor/colspec"/>  <xsl:param name="count" select="1"/>  <xsl:choose>    <xsl:when test="not($colspecs) or $count > $colnum">      <!-- nop -->    </xsl:when>    <xsl:when test="$colspecs[1]/@colnum">      <xsl:choose>        <xsl:when test="$colspecs[1]/@colnum = $colnum">          <xsl:call-template name="get-attribute">            <xsl:with-param name="element" select="$colspecs[1]"/>            <xsl:with-param name="attribute" select="$attribute"/>          </xsl:call-template>        </xsl:when>        <xsl:otherwise>          <xsl:call-template name="colnum.colspec">            <xsl:with-param name="colnum" select="$colnum"/>            <xsl:with-param name="attribute" select="$attribute"/>            <xsl:with-param name="colspecs"                            select="$colspecs[position()>1]"/>            <xsl:with-param name="count"                            select="$colspecs[1]/@colnum+1"/>          </xsl:call-template>        </xsl:otherwise>      </xsl:choose>    </xsl:when>    <xsl:otherwise>      <xsl:choose>        <xsl:when test="$count = $colnum">          <xsl:call-template name="get-attribute">            <xsl:with-param name="element" select="$colspecs[1]"/>            <xsl:with-param name="attribute" select="$attribute"/>          </xsl:call-template>        </xsl:when>        <xsl:otherwise>          <xsl:call-template name="colnum.colspec">            <xsl:with-param name="colnum" select="$colnum"/>            <xsl:with-param name="attribute" select="$attribute"/>            <xsl:with-param name="colspecs"                            select="$colspecs[position()>1]"/>            <xsl:with-param name="count" select="$count+1"/>          </xsl:call-template>        </xsl:otherwise>      </xsl:choose>    </xsl:otherwise>  </xsl:choose></xsl:template><xsl:template name="get-attribute">  <xsl:param name="element" select="."/>  <xsl:param name="attribute" select="''"/>  <xsl:for-each select="$element/@*">    <xsl:if test="local-name(.) = $attribute">      <xsl:value-of select="."/>    </xsl:if>  </xsl:for-each></xsl:template><xsl:template name="consume-row">  <xsl:param name="spans"/>  <xsl:if test="contains($spans,':')">    <xsl:value-of select="substring-before($spans,':') - 1"/>    <xsl:text>:</xsl:text>    <xsl:call-template name="consume-row">      <xsl:with-param name="spans" select="substring-after($spans,':')"/>    </xsl:call-template>  </xsl:if></xsl:template><!-- Returns the table style for the context element --><xsl:template name="tabstyle">  <xsl:param name="node" select="."/>  <xsl:variable name="tgroup" select="$node/tgroup[1] |                                       $node/ancestor-or-self::tgroup[1]"/>  <xsl:variable name="table"                 select="($node/ancestor-or-self::table |                          $node/ancestor-or-self::informaltable)[1]"/>  <xsl:variable name="tabstyle">    <xsl:choose>      <xsl:when test="$table/@tabstyle != ''">        <xsl:value-of select="normalize-space($table/@tabstyle)"/>      </xsl:when>      <xsl:when test="$tgroup/@tgroupstyle != ''">        <xsl:value-of select="normalize-space($tgroup/@tgroupstyle)"/>      </xsl:when>      <xsl:otherwise>      </xsl:otherwise>    </xsl:choose>  </xsl:variable>  <xsl:value-of select="$tabstyle"/></xsl:template></xsl:stylesheet>
 |