File: table.xsl

package info (click to toggle)
docbook2x 0.8.8-17
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 4,724 kB
  • sloc: xml: 16,229; sh: 3,674; perl: 3,461; ansic: 639; makefile: 409; sed: 11
file content (199 lines) | stat: -rw-r--r-- 6,121 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?xml version='1.0'?>
<!-- vim: sw=2 sta et
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
                xmlns="http://docbook2x.sourceforge.net/xmlns/Texi-XML"
                exclude-result-prefixes="doc"
                version='1.0'
                xml:lang="en">

<!-- ********************************************************************
     $Id: table.xsl,v 1.17 2004/08/22 22:46:07 stevecheng Exp $
     ********************************************************************

     (C) 2000-2004 Steve Cheng <stevecheng@users.sourceforge.net>

     This file is part of the docbook2X XSLT stylesheets for
     converting DocBook to Texinfo.

     See ../../COPYING for the copyright status of this software.

     ******************************************************************** -->

<doc:reference xmlns="">
<title>Table support</title>
</doc:reference>

<!-- ==================================================================== -->

<xsl:template match="tgroup">
  <xsl:call-template name="anchor" />
  <multitable cols="{@cols}">
    <xsl:apply-templates select="colspec" />
    <tbody>
      <xsl:apply-templates select="thead" />
      <xsl:apply-templates select="tbody" />
      <xsl:apply-templates select="tfoot" />
    </tbody>
  </multitable>
</xsl:template>

<xsl:template match="colspec">
  <colspec>
    <xsl:attribute name="colwidth">
      <xsl:call-template name="get-proportional-colwidth" />
    </xsl:attribute>

    <xsl:attribute name="colnum">
      <xsl:value-of select="@colnum" />
    </xsl:attribute>
  </colspec>
</xsl:template>
    
<xsl:template match="spanspec">
  <spanspec spanname="{@spanname}"
            namest="{@namest}"
            nameend="{@nameend}" />
</xsl:template>

<xsl:template match="thead|tfoot|tbody">
  <xsl:apply-templates />
</xsl:template>

<!-- FIXME: Complain loudly -->
<xsl:template match="thead/colspec">
</xsl:template>

<xsl:template match="tfoot/colspec">
</xsl:template>


<xsl:template match="row">
  <row>
    <xsl:apply-templates />
  </row>
</xsl:template>

<xsl:template match="entry">
  <entry>
    <xsl:if test="@colname">
      <xsl:attribute name="colname">
        <xsl:value-of select="@colname" />
      </xsl:attribute>
    </xsl:if>
    
     <xsl:if test="@spanname">
      <xsl:attribute name="spanname">
        <xsl:value-of select="@spanname" />
      </xsl:attribute>
    </xsl:if>
    
    <xsl:if test="@namest">
      <xsl:attribute name="namest">
        <xsl:value-of select="@namest" />
      </xsl:attribute>
    </xsl:if>

    <xsl:if test="@nameend">
      <xsl:attribute name="nameend">
        <xsl:value-of select="@nameend" />
      </xsl:attribute>
    </xsl:if>

    <xsl:apply-templates mode="coerce-into-inline" />
  </entry>
</xsl:template>

<!-- ==================================================================== -->

<doc:template name="get-proportional-colwidth" xmlns="">
  <refpurpose>
    Get the proportional width as specified in the given <sgmltag class="element">colspec</sgmltag>
  </refpurpose>

  <refdescription>
    <para>
      In CALS tables, the <sgmltag class="element">colspec</sgmltag> has
      the attribute <sgmltag class="attribute">colwidth</sgmltag>
      which can specify either absolute column widths, relative column widths,
      or a mixture of both measures.  Texinfo only supports relative column widths.
      This template coerces all absolute column widths into relative ones, 
      as follows:

      <variablelist>
        <varlistentry>
          <term>No width is specified</term>
          <listitem>
            <para>Then the column is assumed to have a relative column width of one.</para>
          </listitem>
        </varlistentry>
        
        <varlistentry>
          <term>Absolute widths</term>
          <listitem>
            <para>These are simply translated to a relative column width of one.</para>
          </listitem>
        </varlistentry>

        <varlistentry>
          <term>Mixture</term>
          <listitem>
            <para>These are of the form <literal><replaceable>P</replaceable>*+<replaceable>M</replaceable></literal>, where <replaceable>P</replaceable> is the relative column width, and <replaceable>M</replaceable> is an absolute column width.
The sign may also be minus instead of plus, with the obvious meaning.
This template drops the <replaceable>M</replaceable> part and its sign.
            </para>
          </listitem>
        </varlistentry>
      </variablelist>
    </para>
  </refdescription>

  <refparameter>
    <variablelist>
      <varlistentry>
        <term><parameter>colspec</parameter></term>
        <listitem><para>
          A node-set that is the <sgmltag class="element">colspec</sgmltag>
          element to determine widths for.
        </para></listitem>
      </varlistentry>
    </variablelist>
  </refparameter>
</doc:template>
          
<xsl:template name="get-proportional-colwidth">
  <xsl:param name="colspec" select="." />
  <xsl:variable name="colwidth" select="$colspec/@colwidth" />

  <xsl:choose>
    <xsl:when test="$colwidth = ''">
      <xsl:value-of select="1" />
    </xsl:when>

    <xsl:when test="not(contains($colwidth,'*'))">
      <xsl:call-template name="user-message">
        <xsl:with-param name="node" select="$colspec" />
          <xsl:with-param name="key">absolute table column widths not supported</xsl:with-param>
      </xsl:call-template>
      <xsl:value-of select="1" />
    </xsl:when>

    <xsl:when test="$colwidth = '*'">
      <xsl:value-of select="1" />
    </xsl:when>

    <xsl:otherwise>
      <xsl:if test="contains($colwidth,'+') or contains($colwidth,'-')">
        <xsl:call-template name="user-message">
          <xsl:with-param name="node" select="$colspec" />
          <xsl:with-param name="key">absolute table column widths not supported</xsl:with-param>
        </xsl:call-template>
      </xsl:if>
      <xsl:value-of select="substring-before($colwidth,'*')" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>