summaryrefslogtreecommitdiffstats
blob: f47355500d287aafca28367010e8fb8633b2166c (plain)
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:sfa="http://developer.apple.com/namespaces/sfa"
  xmlns:sf="http://developer.apple.com/namespaces/sf"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:sl="http://developer.apple.com/namespaces/sl"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:doc='http://docbook.org/ns/docbook'
  xmlns:rnd='http://docbook.org/ns/docbook/roundtrip'
  exclude-result-prefixes='doc rnd xi'>

  <xsl:import href='dbk2wp.xsl'/>

  <xsl:output method="xml" indent='yes' encoding='ascii'/>

  <!-- ********************************************************************
       $Id: dbk2pages.xsl 7701 2008-02-22 06:07:31Z balls $
       ********************************************************************

       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:include href='../VERSION'/>
  <xsl:include href='param.xsl'/>

  <xsl:variable name='templatedoc' select='document($pages.template)'/>

  <!-- Find all tables in the document once,
          as we will be iterating over them in more than one place.
      -->
  <xsl:variable name='rnd:pages-tables'
    select='//doc:table|//doc:informaltable'/>

  <!-- Lookup style identifiers from their user-visible name -->
  <xsl:variable name='paragraph-styles'
		select='$templatedoc//sf:paragraphstyle'/>
  <xsl:variable name='character-styles'
		select='$templatedoc//sf:characterstyle'/>

  <xsl:template match="/" name='pages.top'>
    <xsl:param name='doc' select='/'/>

    <xsl:if test='not($pages.template)'>
      <xsl:message terminate='yes'>Please specify the template document with the "pages.template" parameter</xsl:message>
    </xsl:if>
    <xsl:if test='not($templatedoc)'>
      <xsl:message terminate='yes'>Unable to open template document "<xsl:value-of select='$pages.template'/>"</xsl:message>
    </xsl:if>

    <sl:document
      sfa:ID="SLPublicationModel-0"
      sl:version="72007061400"
      sl:generator="slingshot"
      sl:app_build_date="Sep 26 2007, 14:46:11">

      <xsl:apply-templates select='$templatedoc/sl:document/*[not(self::sf:text-storage)]'
        mode='doc:copy'/>

      <xsl:apply-templates select='$doc/*'
        mode='doc:toplevel'/>

      <xsl:apply-templates select='$templatedoc/sl:document/sf:text-storage/following-sibling::*'
        mode='doc:copy'/>
    </sl:document>
  </xsl:template>

  <xsl:template match='sf:calc-engine' mode='doc:copy'>
    <xsl:copy>
      <xsl:apply-templates select='@*' mode='doc:copy'/>

      <xsl:choose>
        <xsl:when test='not(sf:calc-engine-entities)'>
          <xsl:call-template name='rnd:pages-make-calc-engine-entities'/>
          <xsl:apply-templates mode='doc:copy'/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates mode='doc:copy'/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:copy>
  </xsl:template>
  <xsl:template name='rnd:pages-make-calc-engine-entities'
    match='sf:calc-engine-entities' mode='doc:copy'>
    <sf:calc-engine-entities>
      <xsl:choose>
        <xsl:when test='self::calc-engine-entities'>
          <xsl:apply-templates select='@*' mode='doc:copy'/>
          <xsl:apply-templates mode='doc:copy'/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name='sfa:ID'>
            <xsl:text>DocBookRoundtrip-1</xsl:text>
          </xsl:attribute>
        </xsl:otherwise>
      </xsl:choose>

      <xsl:for-each select='$rnd:pages-tables'>
        <xsl:variable name='num' select='position()'/>

        <xsl:variable name='num-cells'
          select='count(doc:tgroup/*/doc:row/doc:entry)'/>
        <xsl:variable name='num-rows' select='count(doc:tgroup/*/doc:row)'/>
        <xsl:variable name='num-cols' select='$num-cells div $num-rows'/>

        <sf:tabular-model sfa:ID='SFTTableModel-{$num}' sf:name='Unnamed Table'
          sfa:id=''
          sf:num-header-rows='{count(doc:tgroup/doc:thead/doc:row)}' sf:num-footer-rows='{count(doc:tgroup/doc:tfoot/doc:row)}'
          sf:num-header-columns='0' sf:name-is-visible='false' sf:grouping-enabled='false'>
          <sf:grid sfa:ID='SFTTableGrid-{$num}'
            sf:ocnt='{$num-cells}'
            sf:numcols='{$num-cols}'
            sf:numrows='{$num-rows}'
            sf:hiddennumcols='0' sf:hiddennumrows='0'>
            <sf:columns sf:count='{$num-cols}'>
              <xsl:apply-templates select='doc:tgroup/doc:colspec'
                mode='rnd:pages-table-colspec'/>
            </sf:columns>
            <sf:vertical-gridline-styles sf:array-size='0'/> <!-- TODO: borders -->
            <sf:rows sf:count='{$num-rows}'>
              <xsl:call-template name='rnd:pages-make-table-rowspecs'>
                <xsl:with-param name='number' select='$num-rows'/>
              </xsl:call-template>
            </sf:rows>
            <sf:horizontal-gridline-styles sf:array-size='0'/> <!-- TODO: borders -->
            <sf:datasource sfa:ID='SFTConcreteTableDataSource-{$num}'>
              <xsl:apply-templates select='doc:tgroup/doc:thead/doc:row'
                mode='rnd:pages-table-data'>
                <xsl:with-param name='start-row' select='0'/>
              </xsl:apply-templates>
              <xsl:apply-templates select='doc:tgroup/doc:tbody/doc:row'
                mode='rnd:pages-table-data'>
                <xsl:with-param name='start-row' select='count(doc:tgroup/doc:thead/doc:row)'/>
              </xsl:apply-templates>
              <xsl:apply-templates select='doc:tgroup/doc:tfoot/doc:row'
                mode='rnd:pages-table-data'>
                <xsl:with-param name='start-row' select='count(doc:tgroup/doc:thead/doc:row) + count(doc:tgroup/doc:tbody/doc:row)'/>
              </xsl:apply-templates>
            </sf:datasource>
            <sf:sort sfa:ID='DocBookPagesTableNSArray-{$num}'>
              <sf:sort-spec sfa:ID='SFTTableSortSpec-{$num}'
                sf:sort-col='0' sf:sort-order='true'/>
            </sf:sort>
            <sf:filterset sfa:ID='SFTTableFilterSet-{$num}'
              sf:type='0' sf:enabled='false' sf:spec-count='1'>
              <sf:filterspec sfa:ID='SFTTableFilterSpec-{$num}'
                sf:filtercol='0' sf:predicate='1' sf:keyscale='0' sf:key1=''/>
            </sf:filterset>
            <sf:cell-comment-mapping sfa:ID='DocBookPagesTableCellCommentNSMutableDictionary-{$num}'/>
            <sf:error_warning_mapping sfa:ID='DocBookPagesTableErrorWarningNSMutableDictionary-{$num}'/>
          </sf:grid>
        </sf:tabular-model>
      </xsl:for-each>
    </sf:calc-engine-entities>
  </xsl:template>

  <xsl:template match='doc:row' mode='rnd:pages-table-data'>
    <xsl:param name='start-row' select='0'/>
    <xsl:apply-templates mode='rnd:pages-table-data'>
      <xsl:with-param name='row'
        select='$start-row + count(preceding-sibling::doc:row)'/>
    </xsl:apply-templates>
  </xsl:template>
  <xsl:template match='doc:entry' mode='rnd:pages-table-data'>
    <xsl:param name='row' select='0'/>
    <sf:text-cell sf:flags='4' sf:col='{count(preceding-sibling::doc:entry)}' sf:row='{$row}'>
      <sf:cell-style-ref sfa:IDREF='SFTCellStyle-3'/>
      <sf:content-size sfa:w='60' sfa:h='25'/>
      <sf:cell-text>
        <xsl:choose>
          <xsl:when test='count(.//*) > 2'>
            <sf:cell-storage>
              <sf:stylesheet-ref sfa:IDREF="SFSStylesheet-1"/>
              <sf:text-body>
                <xsl:apply-templates/>
              </sf:text-body>
            </sf:cell-storage>
          </xsl:when>
          <xsl:otherwise>
            <xsl:attribute name='sfa:string'>
              <xsl:apply-templates mode='rnd:pages-table-text'/>
            </xsl:attribute>
          </xsl:otherwise>
        </xsl:choose>
      </sf:cell-text>
    </sf:text-cell>
  </xsl:template>

  <xsl:template name='rnd:pages-make-table-rowspecs'>
    <xsl:param name='number' select='0'/>

    <xsl:choose>
      <xsl:when test='$number &lt;= 0'/>
      <xsl:otherwise>
        <sf:grid-row sf:height='25' sf:fitting-height='25'/>
        <xsl:call-template name='rnd:pages-make-table-rowspecs'>
          <xsl:with-param name='number' select='$number - 1'/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match='doc:colspec' mode='rnd:pages-table-colspec'>
    <sf:grid-column sf:width='{@colwidth}' sf:preferred-width='{@colwidth}'
      sf:fitting-width='{@colwidth}'/>
  </xsl:template>

  <xsl:template name='doc:make-body'>
    <xsl:param name='content'>
      <xsl:apply-templates mode='doc:body'/>
    </xsl:param>

    <sf:text-storage sf:kind='body' sfa:ID='SFWPStorage-7'>
      <sf:stylesheet-ref sfa:IDREF='SFSStylesheet-1'/>

      <xsl:if test='$rnd:pages-tables'>
        <sf:attachments>
          <xsl:for-each select='$rnd:pages-tables'>
            <xsl:variable name='num' select='position()'/>

            <sf:attachment sfa:ID='SFTTableAttachment-{$num}'
              sfa:sfclass='' sf:kind='tabular-attachment'>
              <sf:tabular-info sfa:ID='SFTTableInfo-{$num}'>
                <sf:geometry sfa:ID='DocBookAffineGeometry-{$num}'
                  sf:sizesLocked='true'>
                  <sf:naturalSize sfa:w='480' sfa:h='126'/>
                  <sf:size sfa:w='480' sfa:h='126'/>
                  <sf:position sfa:x='0' sfa:y='0'/>
                </sf:geometry>
                <sf:style>
                  <sf:tabular-style-ref sfa:IDREF='SFTTableStyle-0'/>
                </sf:style>
                <sf:tabular-model-ref sfa:IDREF='SFTTableModel-{$num}'/>
              </sf:tabular-info>
              <sf:position sfa:x='0' sfa:y='0'/>
            </sf:attachment>

          </xsl:for-each>
        </sf:attachments>
      </xsl:if>

      <sf:text-body>
        <sf:page-start sf:page-index='0'/>
        <sf:container-hint sf:page-index="0" sf:cindex="0" sf:sindex="0" sf:lindex="0" sf:frame-x="56.692913055419922" sf:frame-y="56.692913055419922" sf:frame-w="481.61416625976562" sf:frame-h="714" sf:anchor-loc="0"/>

        <sf:section sf:name="Chapter 1" sf:style="section-style-0">
          <sf:layout sf:style="layout-style-20">
            <xsl:copy-of select='$content'/>
          </sf:layout>
        </sf:section>
      </sf:text-body>
    </sf:text-storage>
  </xsl:template>

  <xsl:template name='doc:make-subsection'>
    <xsl:param name='content'>
      <xsl:apply-templates mode='doc:body'/>
    </xsl:param>

    <xsl:copy-of select='$content'/>
  </xsl:template>

  <xsl:template name='doc:make-paragraph'>
    <xsl:param name='style' select='"unknown"'/>
    <xsl:param name='content'>
      <xsl:apply-templates mode='doc:body'/>
    </xsl:param>
    <xsl:param name='outline.level' select='0'/>
    <xsl:param name='attributes.node' select='.'/>

    <sf:p>
      <xsl:if test='$style != ""'>
	<xsl:attribute name='sf:style'>
          <xsl:call-template name='doc:lookup-paragraph-style'>
            <xsl:with-param name='style' select='$style'/>
          </xsl:call-template>
        </xsl:attribute>
      </xsl:if>

      <xsl:call-template name='attributes'>
        <xsl:with-param name='node' select='$attributes.node'/>
      </xsl:call-template>

      <xsl:copy-of select='$content'/>
      <sf:br/>
    </sf:p>
  </xsl:template>

  <xsl:template name='doc:make-phrase'>
    <xsl:param name='style' select='""'/>
    <xsl:param name='italic' select='0'/>
    <xsl:param name='bold' select='0'/>
    <xsl:param name='content'>
      <xsl:apply-templates mode='doc:phrase'/>
    </xsl:param>

    <!-- TODO: handle italic and bold parameters -->

    <xsl:choose>
      <xsl:when test='$style != ""'>
        <sf:span>
          <xsl:attribute name='sf:style'>
            <xsl:call-template name='doc:lookup-character-style'>
              <xsl:with-param name='style' select='$style'/>
            </xsl:call-template>
          </xsl:attribute>

          <xsl:copy-of select='$content'/>
        </sf:span>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy-of select='$content'/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name='doc:make-hyperlink'>
    <xsl:param name='target'/>
    <xsl:param name='content'>
      <xsl:apply-templates mode='doc:body'/>
    </xsl:param>

    <sf:link href='{$target}'>
      <sf:span>
        <xsl:attribute name='sf:style'>
          <xsl:call-template name='doc:lookup-character-style'>
            <xsl:with-param name='style'>email</xsl:with-param>
          </xsl:call-template>
        </xsl:attribute>
        <xsl:copy-of select='$content'/>
      </sf:span>
    </sf:link>
  </xsl:template>

  <xsl:template name='doc:make-table'>
    <xsl:param name='columns'/>
    <xsl:param name='content'>
      <xsl:apply-templates mode='doc:body'/>
    </xsl:param>

    <xsl:variable name='this' select='.'/>

    <sf:p>
      <xsl:attribute name='sf:style'>
        <xsl:call-template name='doc:lookup-paragraph-style'>
          <xsl:with-param name='style' select='"para"'/>
        </xsl:call-template>
      </xsl:attribute>

      <sf:attachment-ref sf:kind='tabular-attachment'>
        <xsl:attribute name='sfa:IDREF'>
          <xsl:text>SFTTableAttachment-</xsl:text>
          <xsl:for-each select='$rnd:pages-tables'>
            <xsl:if test='generate-id() = generate-id($this)'>
              <xsl:value-of select='position()'/>
            </xsl:if>
          </xsl:for-each>
        </xsl:attribute>
      </sf:attachment-ref>
      <sf:br/>
    </sf:p>
  </xsl:template>

  <xsl:template name='doc:make-column'>
    <xsl:param name='width' select='0'/>
  </xsl:template>

  <xsl:template name='doc:make-table-row'>
    <xsl:param name='content'>
      <xsl:apply-templates mode='doc:body'/>
    </xsl:param>
    <xsl:param name='is-header' select='false()'/>
  </xsl:template>

  <xsl:template name='doc:make-table-cell'>
    <xsl:param name='width' select='0'/>
    <xsl:param name='hidden' select='false()'/>
    <xsl:param name='rowspan' select='1'/>
    <xsl:param name='colspan' select='1'/>
    <xsl:param name='content'>
      <xsl:apply-templates mode='doc:body'/>
    </xsl:param>
  </xsl:template>

  <xsl:template name='doc:make-soft-break'>
    <sf:br/>
  </xsl:template>

  <xsl:template name='attributes'>
    <xsl:param name='node' select='.'/>

    <xsl:for-each select='$node/@*'>
      <sf:span>
	<xsl:attribute name='sf:style'>
	  <xsl:call-template name='doc:lookup-character-style'>
	    <xsl:with-param name='style'>attribute-name</xsl:with-param>
	  </xsl:call-template>
	</xsl:attribute>
	<xsl:value-of select='name()'/>
      </sf:span>
      <sf:span>
	<xsl:attribute name='sf:style'>
	  <xsl:call-template name='doc:lookup-character-style'>
	    <xsl:with-param name='style'>attribute-value</xsl:with-param>
	  </xsl:call-template>
	</xsl:attribute>
	<xsl:value-of select='.'/>
      </sf:span>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name='doc:lookup-paragraph-style'>
    <xsl:param name='style'/>

    <xsl:variable name='style.cooked'>
      <xsl:choose>
        <xsl:when test='$style = "Normal"'>para</xsl:when>
        <xsl:otherwise>
          <xsl:value-of select='$style'/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:if test='not($paragraph-styles[@sf:name = $style.cooked])'>
      <xsl:message>unable to find paragraph style "<xsl:value-of select='$style.cooked'/>"</xsl:message>
    </xsl:if>

    <xsl:value-of select='$paragraph-styles[@sf:name = $style.cooked]/@sf:ident'/>
  </xsl:template>
  <xsl:template name='doc:lookup-character-style'>
    <xsl:param name='style'/>

    <xsl:if test='not($character-styles[@sf:name = $style])'>
      <xsl:message>unable to find character style "<xsl:value-of select='$style'/>"</xsl:message>
    </xsl:if>

    <xsl:value-of select='$character-styles[@sf:name = $style]/@sf:ident'/>
  </xsl:template>
</xsl:stylesheet>