Debian Codegraph @

demo/legacypdf/xslfo/dita2fo-simpletable.xsl

raw symbols SCIP
1 <?xml version='1.0'?>
2 <!-- This file is part of the DITA Open Toolkit project hosted on
3 Sourceforge.net. See the accompanying license.txt file for
4 applicable licenses.-->
5 <!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->
6
7 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
8 xmlns:fo="http://www.w3.org/1999/XSL/Format"
9 version='1.0'>
10
11
12 <!-- simpletable support -->
13
14 <xsl:template match="*[contains(@class,' topic/simpletable ')]">
15 <fo:block space-before="12pt">
16 <fo:table xsl:use-attribute-sets="table.data frameall">
17 <xsl:call-template name="semtbl-colwidth"/>
18 <fo:table-body>
19 <xsl:call-template name="gen-dflt-data-hdr"/>
20 <xsl:apply-templates/>
21 </fo:table-body>
22 </fo:table>
23 </fo:block>
24 </xsl:template>
25
26 <!-- if cells have default spectitle values, copy these up to a first new hdr row -->
27 <xsl:template name="gen-dflt-data-hdr">
28 <xsl:if test="*/*[contains(@class,' topic/stentry ')]/@specentry">
29 <fo:table-row>
30 <xsl:for-each select="*[contains(@class,' topic/strow ')][1]/*">
31 <fo:table-cell start-indent="2pt" background-color="silver" padding="2pt" text-align=
32 "center" font-weight="bold" xsl:use-attribute-sets="frameall">
33 <xsl:attribute name="column-number"><xsl:number count="*"/></xsl:attribute>
34 <fo:block>
35 <xsl:value-of select="@specentry"/>
36 </fo:block>
37 </fo:table-cell>
38 </xsl:for-each>
39 </fo:table-row>
40 </xsl:if>
41 </xsl:template>
42
43
44
45 <xsl:template name="semtbl-colwidth">
46 <!-- Find the total number of relative units for the table. If @relcolwidth="1* 2* 2*",
47 the variable is set to 5. -->
48 <xsl:variable name="totalwidth">
49 <xsl:if test="@relcolwidth and not(@relcolwidth='')">
50 <xsl:call-template name="find-total-table-width"/>
51 </xsl:if>
52 </xsl:variable>
53 <!-- Find how much of the table each relative unit represents. If @relcolwidth is 1* 2* 2*,
54 there are 5 units. So, each unit takes up 100/5, or 20% of the table. Default to 0,
55 which the entries will ignore. -->
56 <!-- bad relcolwidth data will still generate "NaN" errors, however -->
57 <xsl:variable name="width-multiplier">
58 <xsl:choose>
59 <xsl:when test="@relcolwidth and not(@relcolwidth='')">
60 <xsl:value-of select="100 div $totalwidth"/>
61 </xsl:when>
62 <xsl:otherwise>0</xsl:otherwise>
63 </xsl:choose>
64 </xsl:variable>
65
66 <!-- specialize strow, so choicetable will work -->
67 <xsl:for-each select="*[contains(@class,' topic/strow ')][1]/*"><!-- use cells as counters; avoid recursion! -->
68 <!-- Determine which column this entry is in. -->
69 <xsl:variable name="thiscolnum"><xsl:value-of select="position()"/></xsl:variable>
70 <!--xsl:comment>Relwidth should be (<xsl:call-template name="get-proportional-width">
71 <xsl:with-param name="entry-num"><xsl:value-of select="$thiscolnum"/></xsl:with-param>
72 <xsl:with-param name="all-widths"><xsl:value-of select="../../@relcolwidth"/></xsl:with-param>
73 </xsl:call-template>)</xsl:comment-->
74 <fo:table-column>
75 <xsl:if test="../../@relcolwidth and not(../../@relcolwidth='')">
76 <!-- use relative width from called template, instead of old value with inches -->
77 <!--<xsl:attribute name="column-width">
78 <xsl:variable name="thispct">
79 <xsl:call-template name="get-current-entry-percentage">
80 <xsl:with-param name="multiplier"><xsl:value-of select="$width-multiplier"/></xsl:with-param>
81 <xsl:with-param name="entry-num"><xsl:value-of select="$thiscolnum"/></xsl:with-param>
82 </xsl:call-template>
83 </xsl:variable>
84 <xsl:value-of select="number(198 * $thispct div 100 div 36)"/>in<xsl:text/>
85 </xsl:attribute>-->
86 <xsl:attribute name="column-width">proportional-column-width(<xsl:call-template name="get-proportional-width">
87 <xsl:with-param name="entry-num"><xsl:value-of select="$thiscolnum"/></xsl:with-param>
88 <xsl:with-param name="all-widths"><xsl:value-of select="../../@relcolwidth"/></xsl:with-param>
89 </xsl:call-template>)</xsl:attribute>
90 </xsl:if>
91 </fo:table-column>
92 </xsl:for-each>
93 </xsl:template>
94
95 <!-- used to get relative column width for simpletables. If in the first entry, take
96 the first width. Otherwise, chop off a width, and proceed to the next value, until
97 getting to the proper one. -->
98 <xsl:template name="get-proportional-width">
99 <xsl:param name="entry-num">0</xsl:param>
100 <xsl:param name="all-widths"><xsl:value-of select="../@relcolwidth"/></xsl:param>
101 <xsl:choose>
102 <xsl:when test="$entry-num &lt;= 0"/>
103 <xsl:when test="$entry-num=1">
104 <xsl:value-of select="substring-before($all-widths,'*')"/>
105 </xsl:when>
106 <xsl:when test="not(contains($all-widths,' '))"/>
107 <xsl:otherwise>
108 <xsl:call-template name="get-proportional-width">
109 <xsl:with-param name="entry-num"><xsl:value-of select="$entry-num - 1"/></xsl:with-param>
110 <xsl:with-param name="all-widths"><xsl:value-of select="substring-after($all-widths,' ')"/></xsl:with-param>
111 </xsl:call-template>
112 </xsl:otherwise>
113 </xsl:choose>
114 </xsl:template>
115
116
117
118
119
120
121 <!-- Use @relcolwidth to find the total width of the table. That is, if the attribute is set
122 to 1* 2* 2* 1*, then the table is 6 units wide. -->
123 <xsl:template name="find-total-table-width">
124 <!-- Start with relcolwidth, and each recursive call will remove the first value -->
125 <xsl:param name="relcolwidth"><xsl:value-of select="@relcolwidth"/></xsl:param>
126 <!-- Determine the first value, which is the value before the first asterisk -->
127 <xsl:variable name="firstval">
128 <xsl:if test="contains($relcolwidth,'*')">
129 <xsl:value-of select="substring-before($relcolwidth,'*')"/>
130 </xsl:if>
131 </xsl:variable>
132 <!-- Begin processing if we were able to find a first value -->
133 <xsl:if test="string-length($firstval)>0">
134 <!-- Chop off the first value, and set morevals to the remainder -->
135 <xsl:variable name="morevals"><xsl:value-of select="substring-after($relcolwidth,' ')"/></xsl:variable>
136 <xsl:choose>
137 <!-- If there are additional values, call this template on the remainder.
138 Add the result of that call to the first value. -->
139 <xsl:when test="string-length($morevals)>0">
140 <xsl:variable name="nextval"> <!-- The total of the remaining values -->
141 <xsl:call-template name="find-total-table-width">
142 <xsl:with-param name="relcolwidth"><xsl:value-of select="$morevals"/></xsl:with-param>
143 </xsl:call-template>
144 </xsl:variable>
145 <xsl:value-of select="number($firstval)+number($nextval)"/>
146 </xsl:when>
147 <!-- If there are no more values, return the first (and only) value -->
148 <xsl:otherwise><xsl:value-of select="$firstval"/></xsl:otherwise>
149 </xsl:choose>
150 </xsl:if>
151 </xsl:template>
152
153 <!-- Find the width of the current cell. Multiplier is how much each unit of width is multiplied to total 100.
154 Entry-num is the current entry. Current-col is what column we are at when scanning @relcolwidth.
155 Relcolvalues is the unscanned part of @relcolwidth. -->
156 <xsl:template name="get-current-entry-percentage">
157 <xsl:param name="multiplier">1</xsl:param> <!-- Each relative unit is worth this many percentage points -->
158 <xsl:param name="entry-num"/> <!-- The entry number of the cell we are evaluating now -->
159 <xsl:param name="current-col">1</xsl:param> <!-- Position within the recursive call to evaluate @relcolwidth -->
160 <!-- relcolvalues begins with @relcolwidth. Each call to the template removes the first value. -->
161 <xsl:param name="relcolvalues"><xsl:value-of select="parent::*/parent::*/@relcolwidth"/></xsl:param>
162
163 <xsl:choose>
164 <!-- If the recursion has moved up to the proper cell, multiply $multiplier by the number of
165 relative units for this column. -->
166 <xsl:when test="$entry-num = $current-col">
167 <xsl:variable name="relcol"><xsl:value-of select="substring-before($relcolvalues,'*')"/></xsl:variable>
168 <xsl:value-of select="$relcol * $multiplier"/>
169 </xsl:when>
170 <!-- Otherwise, call this template again, removing the first value form @relcolwidth. Also add one
171 to $current-col. -->
172 <xsl:otherwise>
173 <xsl:call-template name="get-current-entry-percentage">
174 <xsl:with-param name="multiplier"><xsl:value-of select="$multiplier"/></xsl:with-param>
175 <xsl:with-param name="entry-num"><xsl:value-of select="$entry-num"/></xsl:with-param>
176 <xsl:with-param name="current-col"><xsl:value-of select="$current-col + 1"/></xsl:with-param>
177 <xsl:with-param name="relcolvalues"><xsl:value-of select="substring-after($relcolvalues,' ')"/></xsl:with-param>
178 </xsl:call-template>
179 </xsl:otherwise>
180 </xsl:choose>
181 </xsl:template>
182
183
184 <xsl:template match="*[contains(@class,' topic/sthead ')]">
185 <fo:table-row>
186 <xsl:apply-templates/>
187 </fo:table-row>
188 </xsl:template>
189
190
191 <xsl:template match="*[contains(@class,' topic/strow ')]">
192 <fo:table-row>
193 <xsl:apply-templates/>
194 </fo:table-row>
195 </xsl:template>
196
197
198 <!-- in the following two rules, the xsl:number needs to give the
199 sequence number of either the current semdh or sementry in the current
200 semrow OR semhdr. -->
201
202 <xsl:template match="*[contains(@class,' topic/sthead ')]/*[contains(@class,' topic/stentry ')]" priority="2">
203 <fo:table-cell start-indent="2pt" background-color="silver" padding="2pt" text-align=
204 "center" font-weight="bold" xsl:use-attribute-sets="frameall">
205 <xsl:attribute name="column-number"><xsl:number count="*"/></xsl:attribute>
206 <fo:block>
207 <xsl:attribute name="font-size">10pt</xsl:attribute>
208 <xsl:call-template name="get-title"/>
209 </fo:block>
210 </fo:table-cell>
211 </xsl:template>
212
213
214 <xsl:template match="*[contains(@class,' topic/stentry ')]">
215 <xsl:variable name="localkeycol">
216 <xsl:choose>
217 <xsl:when test="ancestor::*[contains(@class,' topic/simpletable ')]/@keycol">
218 <xsl:value-of select="ancestor::*[contains(@class,' topic/simpletable ')]/@keycol"/>
219 </xsl:when>
220 <xsl:otherwise>0</xsl:otherwise>
221 </xsl:choose>
222 </xsl:variable>
223 <xsl:variable name="thisnum"><xsl:number/></xsl:variable>
224 <xsl:variable name="thisrow"><xsl:number level="single" count="strow"/></xsl:variable>
225 <!--xsl:message>Keycol: <xsl:value-of select="$localkeycol"/> Number: <xsl:value-of select="$thisnum"/> Row: <xsl:value-of select="$thisrow"/></xsl:message-->
226 <xsl:choose>
227 <xsl:when test="$thisnum=$localkeycol">
228 <fo:table-cell start-indent="2pt" background-color="#fafafa" padding="2pt" xsl:use-attribute-sets="frameall">
229 <xsl:attribute name="column-number"><xsl:number count="*"/></xsl:attribute>
230 <fo:block font-weight="bold">
231 <xsl:attribute name="font-size">9pt</xsl:attribute>
232 <xsl:apply-templates/> <!-- don't use "apply-for-phrases" for editor -->
233 </fo:block>
234 </fo:table-cell>
235 </xsl:when>
236 <xsl:otherwise>
237 <fo:table-cell start-indent="2pt" background-color="#fafafa" padding="2pt" xsl:use-attribute-sets="frameall">
238 <xsl:attribute name="column-number"><xsl:number count="*"/></xsl:attribute>
239 <fo:block>
240 <xsl:attribute name="font-size">9pt</xsl:attribute>
241 <xsl:apply-templates/>
242 </fo:block>
243 </fo:table-cell>
244 </xsl:otherwise>
245 </xsl:choose>
246 </xsl:template>
247
248
249 <!-- end of simpletable section -->
250
251
252 </xsl:stylesheet>