1 <xsl:stylesheet version="1.0"
2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:sfa="http://developer.apple.com/namespaces/sfa"
5 xmlns:sf="http://developer.apple.com/namespaces/sf"
6 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7 xmlns:appsl="http://developer.apple.com/namespaces/sl"
9 xmlns:dbk='http://docbook.org/ns/docbook'
10 xmlns:rnd='http://docbook.org/ns/docbook/roundtrip'
11 exclude-result-prefixes='sfa sf xsi appsl'>
13 <xsl:output method="xml" indent='yes'/>
15 <!-- ********************************************************************
16 $Id: pages2normalise.xsl 7637 2008-01-09 20:48:30Z balls $
17 ********************************************************************
19 This file is part of the XSL DocBook Stylesheet distribution.
20 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
21 and other information.
23 ******************************************************************** -->
25 <xsl:strip-space elements='*'/>
26 <xsl:preserve-space elements='sf:span'/>
28 <xsl:key name='styles'
29 match='sf:paragraphstyle[not(ancestor::appsl:section-prototypes)] |
30 sf:characterstyle[not(ancestor::appsl:section-prototypes)] |
32 use='@sf:ident|@sfa:ID'/>
38 <xsl:template match='appsl:document'>
40 <!-- TODO: headers and footers -->
41 <xsl:apply-templates select='sf:text-storage'/>
45 <xsl:template match='sf:p'>
47 <xsl:when test='sf:attachment-ref and
48 count(*) = count(sf:attachment-ref|sf:br|sf:selection-start|sf:selection-end)'>
49 <xsl:apply-templates/>
53 <xsl:variable name='style-name'>
54 <xsl:call-template name='rnd:find-style'/>
56 <xsl:if test='$style-name != "" and
57 $style-name != "para"'>
58 <xsl:attribute name='rnd:style'>
59 <xsl:value-of select='$style-name'/>
63 <xsl:apply-templates/>
69 <xsl:template match='sf:span'>
70 <xsl:variable name='style-name'
71 select='key("styles", @sf:style)/self::sf:characterstyle/@sf:name'/>
73 <xsl:variable name='char-style'>
74 <xsl:call-template name='rnd:find-style'>
75 <xsl:with-param name='char-style-name' select='$style-name'/>
80 <xsl:when test='$style-name = "attribute-name"'>
81 <xsl:if test='not(preceding-sibling::node()[not(self::text()) or (self::text() and normalize-space() != "")])'>
82 <xsl:attribute name='{.}'>
83 <xsl:apply-templates select='following-sibling::*[1][self::sf:span]'
88 <xsl:when test='$style-name = "attribute-value"'/>
89 <xsl:when test='$style-name = ""'>
90 <xsl:apply-templates/>
92 <xsl:when test='$char-style = "superscript" or
93 $char-style = "subscript"'>
94 <xsl:element name='{$char-style}'
95 namespace='http://docbook.org/ns/docbook'>
96 <xsl:apply-templates/>
102 <xsl:when test='$char-style = "emphasis-bold" or
103 $char-style = "emphasis-strong"'>
104 <xsl:attribute name='role'>bold</xsl:attribute>
106 <xsl:when test='$char-style != "" and
107 $char-style != "emphasis"'>
108 <xsl:attribute name='rnd:style'>
109 <xsl:value-of select='$char-style'/>
114 <xsl:apply-templates/>
120 <xsl:template match='*' mode='attribute'>
121 <xsl:variable name='style-name'
122 select='key("styles", @sf:style)/self::sf:characterstyle/@sf:name'/>
124 <xsl:if test='$style-name = "attribute-value"'>
125 <xsl:apply-templates/>
129 <xsl:template match='sf:br'/>
130 <xsl:template match='sf:lnbr|sf:crbr'>
131 <xsl:text>
</xsl:text>
133 <xsl:template match='sf:tab'>
134 <xsl:text> </xsl:text>
136 <xsl:template match='sf:link'>
137 <dbk:ulink url='{@href}'>
138 <xsl:apply-templates/>
142 <xsl:template match='sf:attachment-ref'>
143 <xsl:if test='@sf:kind = "tabular-attachment"'>
144 <xsl:apply-templates select='key("ids", @sfa:IDREF)'/>
148 <xsl:template match='sf:attachment[@sf:kind = "tabular-attachment"]'>
149 <xsl:variable name='model'
150 select='key("ids", sf:tabular-info/sf:tabular-model-ref/@sfa:IDREF)'/>
152 <xsl:variable name='num-cols' select='$model/sf:grid/@sf:numcols'/>
153 <xsl:variable name='num-rows' select='$model/sf:grid/@sf:numrows'/>
155 <xsl:variable name='border.top'
156 select='count($model/sf:grid/sf:horizontal-gridline-styles/*) = 0 or
157 not($model/sf:grid/sf:horizontal-gridline-styles/sf:style-run[@sf:gridline-index = "0"])'/>
158 <xsl:variable name='border.bottom'
159 select='count($model/sf:grid/sf:horizontal-gridline-styles/*) = 0 or
160 not($model/sf:grid/sf:horizontal-gridline-styles/sf:style-run[@sf:gridline-index = $num-rows - 1])'/>
161 <xsl:variable name='border.left'
162 select='count($model/sf:grid/sf:vertical-gridline-styles/*) = 0 or
163 not($model/sf:grid/sf:vertical-gridline-styles/sf:style-run[@sf:gridline-index = "0"])'/>
164 <xsl:variable name='border.right'
165 select='count($model/sf:grid/sf:vertical-gridline-styles/*) = 0 or
166 not($model/sf:grid/sf:vertical-gridline-styles/sf:style-run[@sf:gridline-index = $num-cols])'/>
169 <xsl:when test='not($num-rows) or $num-rows = ""'>
170 <xsl:message> cannot determine number of rows in table</xsl:message>
171 <xsl:comment> cannot determine number of rows in table </xsl:comment>
173 <xsl:when test='not($num-cols) or $num-cols = ""'>
174 <xsl:message> cannot determine number of columns in table</xsl:message>
175 <xsl:comment> cannot determine number of columns in table </xsl:comment>
181 <xsl:when test='$border.top and $border.bottom and
182 $border.left and $border.right'>
183 <xsl:attribute name='frame'>all</xsl:attribute>
185 <xsl:when test='$border.top and $border.bottom'>
186 <xsl:attribute name='frame'>topbot</xsl:attribute>
188 <xsl:when test='$border.left and $border.right'>
189 <xsl:attribute name='frame'>sides</xsl:attribute>
191 <xsl:when test='$border.top'>
192 <xsl:attribute name='frame'>top</xsl:attribute>
194 <xsl:when test='$border.bottom'>
195 <xsl:attribute name='frame'>bottom</xsl:attribute>
198 <dbk:tgroup cols='{$num-cols}'>
199 <xsl:apply-templates select='$model/sf:grid/sf:columns/sf:grid-column'
201 <xsl:if test='$model/@sf:num-header-rows != 0'>
203 <xsl:call-template name='rnd:make-table-rows'>
204 <xsl:with-param name='nodes'
205 select='$model/sf:grid/sf:datasource/sf:text-cell[@sf:row < $model/@sf:num-header-rows]'/>
206 <xsl:with-param name='num-rows'
207 select='$model/@sf:num-header-rows'/>
212 <xsl:call-template name='rnd:make-table-rows'>
213 <xsl:with-param name='nodes'
214 select='$model/sf:grid/sf:datasource/sf:text-cell[@sf:row >= $model/@sf:num-header-rows and
215 @sf:row < $num-rows - $model/@sf:num-footer-rows]'/>
216 <xsl:with-param name='num-rows' select='$num-rows - $model/@sf:num-header-rows - $model/@sf:num-footer-rows'/>
217 <xsl:with-param name='row' select='$model/@sf:num-header-rows'/>
220 <xsl:if test='$model/@sf:num-footer-rows != 0'>
222 <xsl:call-template name='rnd:make-table-rows'>
223 <xsl:with-param name='nodes'
224 select='$model/sf:grid/sf:datasource/sf:text-cell[@sf:row >= $num-rows - $model/@sf:num-footer-rows]'/>
225 <xsl:with-param name='num-rows'
226 select='$model/@sf:num-footer-rows'/>
227 <xsl:with-param name='row'
228 select='$num-rows - $model/@sf:num-footer-rows'/>
237 <xsl:template match='sf:grid-column' mode='rnd:colspec'>
238 <dbk:colspec colwidth='{@sf:width}'
239 colname='column-{count(preceding-sibling::sf:grid-column) + 1}'/>
241 <xsl:template name='rnd:make-table-rows'>
242 <xsl:param name='num-rows' select='0'/>
243 <xsl:param name='nodes' select='/..'/>
244 <xsl:param name='row' select='0'/>
247 <xsl:when test='not($nodes) and $num-rows != 0'>
248 <xsl:message>WARNING: insufficient table cells</xsl:message>
249 <xsl:comment> WARNING: insufficient table cells (num-rows <xsl:value-of select='$num-rows'/>, row <xsl:value-of select='$row'/>) </xsl:comment>
251 <xsl:when test='$nodes and $num-rows = 0'>
252 <xsl:message>WARNING: excess table cells</xsl:message>
253 <xsl:comment> WARNING: excess table cells (num-rows <xsl:value-of select='$num-rows'/>, row <xsl:value-of select='$row'/>) </xsl:comment>
255 <xsl:when test='not($nodes)'/>
256 <xsl:when test='$num-rows = 0'/>
260 <xsl:apply-templates select='$nodes[@sf:row = $row]'/>
262 <xsl:call-template name='rnd:make-table-rows'>
263 <xsl:with-param name='num-rows'
264 select='$num-rows - 1'/>
265 <xsl:with-param name='row'
267 <xsl:with-param name='nodes'
268 select='$nodes[@sf:row != $row]'/>
273 <xsl:template match='sf:text-cell'>
275 <!-- Does this cell have no bottom border? -->
276 <xsl:variable name='horiz'
277 select='ancestor::sf:grid/sf:horizontal-gridline-styles'/>
278 <xsl:if test='not($horiz/*) or
279 not($horiz/sf:style-run[@sf:gridline-index = current()/@sf:row + 1]/sf:vector-style-ref[@sf:start-index <= current()/@sf:col and @sf:stop-index >= current()/@sf:col])'>
280 <xsl:attribute name='rowsep'>1</xsl:attribute>
282 <!-- Does this cell have no right border? -->
283 <xsl:variable name='vert'
284 select='ancestor::sf:grid/sf:vertical-gridline-styles'/>
285 <xsl:if test='not($vert/*) or
286 not($vert/sf:style-run[@sf:gridline-index = current()/@sf:col + 1]/sf:vector-style-ref[@sf:start-index <= current()/@sf:row and @sf:stop-index >= current()/@sf:row])'>
287 <xsl:attribute name='colsep'>1</xsl:attribute>
291 <xsl:when test='sf:cell-text/@sfa:string'>
293 <xsl:apply-templates select='sf:cell-text/@sfa:string'/>
297 <xsl:apply-templates select='sf:cell-text/sf:cell-storage/sf:text-body/*'/>
302 <xsl:template match='sf:tableAttachmentTable |
304 <xsl:apply-templates/>
306 <xsl:template match='sf:tableModelPartitionSource |
307 sf:tableModelStyle-ref |
308 sf:tableModelVectors |
309 sf:tableCellArrayCellsByColumn |
310 sf:tableModelTableID'/>
312 <xsl:template match='sf:text-storage |
316 <xsl:apply-templates/>
319 <xsl:template match='sf:stylesheet|sf:stylesheet-ref |
321 sf:page-start|sf:br |
322 sf:selection-start|sf:selection-end |
327 <xsl:template match='*'>
328 <xsl:message>element "<xsl:value-of select='name()'/>" not handled</xsl:message>
331 <xsl:template name='rnd:find-style'>
332 <xsl:param name='ident' select='@sf:style'/>
333 <xsl:param name='para-style-name'
334 select='key("styles", $ident)/self::sf:paragraphstyle/@sf:name'/>
335 <xsl:param name='char-style-name'
336 select='key("styles", $ident)/self::sf:characterstyle/@sf:name'/>
339 <xsl:when test='$ident = "paragraph-style-default"'/>
340 <xsl:when test='$para-style-name != ""'>
341 <xsl:value-of select='$para-style-name'/>
343 <xsl:when test='key("styles", $ident)/self::sf:characterstyle/sf:property-map/sf:superscript/sf:number/@sfa:number = "1"'>superscript</xsl:when>
344 <xsl:when test='key("styles", $ident)/self::sf:characterstyle/sf:property-map/sf:subscript/sf:number/@sfa:number = "1"'>subscript</xsl:when>
345 <xsl:when test='$char-style-name != "" or
346 key("styles", $ident)/self::sf:characterstyle/sf:property-map/*'>
347 <xsl:value-of select='$char-style-name'/>