Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / epub / tei-to-epub.xsl @ 187

History | View | Annotate | Download (42 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:smil="http://www.w3.org/ns/SMIL" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:iso="http://www.iso.org/ns/1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:teix="http://www.tei-c.org/ns/Examples" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/" version="2.0" exclude-result-prefixes="iso tei teix dc              html opf ncx smil">
3
  <xsl:import href="../xhtml2/tei.xsl"/>
4
  <xsl:import href="epub-common.xsl"/>
5
  <xsl:import href="epub-preflight.xsl"/>
6
  <xsl:output method="xml" encoding="utf-8" indent="no"/>
7
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
8
    <desc>
9
      <p>
10
	TEI stylesheet for making ePub output. A lot learnt from
11
	http://www.hxa.name/articles/content/epub-guide_hxa7241_2007.html and
12
	the stylesheets of the NZETC.
13
      </p>
14
      <p>This software is dual-licensed:
15

    
16
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
17
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
18

    
19
2. http://www.opensource.org/licenses/BSD-2-Clause
20
		
21
All rights reserved.
22

    
23
Redistribution and use in source and binary forms, with or without
24
modification, are permitted provided that the following conditions are
25
met:
26

    
27
* Redistributions of source code must retain the above copyright
28
notice, this list of conditions and the following disclaimer.
29

    
30
* Redistributions in binary form must reproduce the above copyright
31
notice, this list of conditions and the following disclaimer in the
32
documentation and/or other materials provided with the distribution.
33

    
34
This software is provided by the copyright holders and contributors
35
"as is" and any express or implied warranties, including, but not
36
limited to, the implied warranties of merchantability and fitness for
37
a particular purpose are disclaimed. In no event shall the copyright
38
holder or contributors be liable for any direct, indirect, incidental,
39
special, exemplary, or consequential damages (including, but not
40
limited to, procurement of substitute goods or services; loss of use,
41
data, or profits; or business interruption) however caused and on any
42
theory of liability, whether in contract, strict liability, or tort
43
(including negligence or otherwise) arising in any way out of the use
44
of this software, even if advised of the possibility of such damage.
45
</p>
46
      <p>Author: See AUTHORS</p>
47
      <p>Id: $Id: tei-to-epub.xsl 10057 2012-01-21 16:57:14Z rahtz $</p>
48
      <p>Copyright: 2008, TEI Consortium</p>
49
    </desc>
50
  </doc>
51
  <xsl:param name="STDOUT">false</xsl:param>
52
  <xsl:param name="autoHead">true</xsl:param>
53
  <xsl:param name="autoToc">true</xsl:param>
54
  <xsl:param name="bottomNavigationPanel">false</xsl:param>
55
  <xsl:param name="coverimage"/>
56
  <xsl:param name="createanttask">false</xsl:param>
57
  <xsl:param name="cssFile">../tei.css</xsl:param>
58
  <xsl:param name="cssODDFile">../odd.css</xsl:param>
59
  <xsl:param name="cssPrintFile">../epub-print.css</xsl:param>
60
  <xsl:param name="debug">false</xsl:param>
61
  <xsl:param name="directory">.</xsl:param>
62
  <xsl:param name="doctypePublic">-//W3C//DTD XHTML 1.1//EN</xsl:param>
63
  <xsl:param name="doctypeSystem">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</xsl:param>
64
  <xsl:param name="fixgraphicsurl">false</xsl:param>
65
  <xsl:param name="footnoteBackLink">true</xsl:param>
66
  <xsl:param name="inputDir">.</xsl:param>
67
  <xsl:param name="institution"/>
68
  <xsl:param name="linkPanel">false</xsl:param>
69
  <xsl:param name="odd">false</xsl:param>
70
  <xsl:param name="outputDir"><xsl:value-of select="$directory"/>/OPS</xsl:param>
71
  <xsl:param name="outputTarget">epub</xsl:param>
72
  <xsl:param name="publisher"/>
73
  <xsl:param name="splitLevel">0</xsl:param>
74
  <xsl:param name="subject"/>
75
  <xsl:param name="tocDepth">5</xsl:param>
76
  <xsl:param name="tocFront">true</xsl:param>
77
  <xsl:param name="topNavigationPanel">false</xsl:param>
78
  <xsl:param name="uid"/>
79
  <xsl:param name="useHeaderFrontMatter">false</xsl:param>
80
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
81
    <desc>(extensible) wrapper for root element</desc>
82
  </doc>
83
  <xsl:template match="/">
84
    <xsl:call-template name="processTEI"/>
85
  </xsl:template>
86
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
87
    <desc>[epub] Override of top-level template. This does most of
88
  the work: performing the normal transformation, fixing the links to graphics files so that they are
89
  all relative, creating the extra output files, etc</desc>
90
  </doc>
91
  <xsl:template name="processTEI">
92
    <xsl:variable name="stage1">
93
      <xsl:apply-templates mode="preflight"/>
94
    </xsl:variable>
95
    <xsl:for-each select="$stage1">
96
      <xsl:call-template name="processTEIHook"/>
97
      <xsl:variable name="coverImageOutside">
98
        <xsl:choose>
99
          <xsl:when test="/tei:TEI/tei:text/tei:front/tei:titlePage[@facs]">
100
            <xsl:for-each select="/tei:TEI/tei:text/tei:front/tei:titlePage[@facs][1]">
101
              <xsl:for-each select="id(substring(@facs,2))">
102
                <xsl:choose>
103
                  <xsl:when test="count(tei:graphic)=1">
104
                    <xsl:value-of select="tei:graphic/@url"/>
105
                  </xsl:when>
106
                  <xsl:otherwise>
107
                    <xsl:value-of select="tei:graphic[2]/@url"/>
108
                  </xsl:otherwise>
109
                </xsl:choose>
110
              </xsl:for-each>
111
            </xsl:for-each>
112
          </xsl:when>
113
          <xsl:when test="not($coverimage='')">
114
            <xsl:value-of select="$coverimage"/>
115
          </xsl:when>
116
        </xsl:choose>
117
      </xsl:variable>
118
      <xsl:variable name="coverImageInside">
119
        <xsl:choose>
120
          <xsl:when test="/tei:TEI/tei:text/tei:front/tei:titlePage[@facs]">
121
            <xsl:for-each select="/tei:TEI/tei:text/tei:front/tei:titlePage[@facs][1]">
122
              <xsl:for-each select="id(substring(@facs,2))">
123
                <xsl:value-of select="tei:graphic[1]/@url"/>
124
              </xsl:for-each>
125
            </xsl:for-each>
126
          </xsl:when>
127
          <xsl:when test="not($coverimage='')">
128
            <xsl:value-of select="$coverimage"/>
129
          </xsl:when>
130
        </xsl:choose>
131
      </xsl:variable>
132
      <xsl:choose>
133
        <xsl:when test="$splitLevel='-1'">
134
          <xsl:apply-templates/>
135
        </xsl:when>
136
        <xsl:otherwise>
137
          <xsl:apply-templates mode="split"/>
138
        </xsl:otherwise>
139
      </xsl:choose>
140
      <xsl:for-each select="*">
141
        <xsl:variable name="TOC">
142
          <TOC xmlns="http://www.w3.org/1999/xhtml">
143
            <xsl:call-template name="mainTOC"/>
144
          </TOC>
145
        </xsl:variable>
146
        <!--
147
	    <xsl:result-document href="/tmp/TOC">
148
	    <xsl:copy-of select="$TOC"/>
149
	    </xsl:result-document>
150
-->
151
        <xsl:for-each select="tokenize($javascriptFiles,',')">
152
          <xsl:variable name="file" select="normalize-space(.)"/>
153
          <xsl:variable name="name" select="tokenize($file,'/')[last()]"/>
154
          <xsl:if test="$verbose='true'">
155
            <xsl:message>write Javascript file <xsl:value-of select="$name"/></xsl:message>
156
          </xsl:if>
157
          <xsl:result-document method="text" href="{concat($directory,'/OPS/',$name)}">
158
            <xsl:for-each select="unparsed-text($file)">
159
              <xsl:copy-of select="."/>
160
            </xsl:for-each>
161
          </xsl:result-document>
162
        </xsl:for-each>
163
        <xsl:if test="$verbose='true'">
164
          <xsl:message>write file OPS/stylesheet.css</xsl:message>
165
        </xsl:if>
166
        <xsl:result-document method="text" href="{concat($directory,'/OPS/stylesheet.css')}">
167
          <xsl:if test="not($cssFile='')">
168
            <xsl:if test="$verbose='true'">
169
              <xsl:message>reading file <xsl:value-of select="$cssFile"/></xsl:message>
170
            </xsl:if>
171
            <xsl:for-each select="tokenize(unparsed-text($cssFile),     '\r?\n')">
172
              <xsl:call-template name="purgeCSS"/>
173
            </xsl:for-each>
174
          </xsl:if>
175
          <xsl:if test="not($cssSecondaryFile='')">
176
            <xsl:if test="$verbose='true'">
177
              <xsl:message>reading secondary file <xsl:value-of select="$cssSecondaryFile"/></xsl:message>
178
            </xsl:if>
179
            <xsl:for-each select="tokenize(unparsed-text($cssSecondaryFile),       '\r?\n')">
180
              <xsl:call-template name="purgeCSS"/>
181
            </xsl:for-each>
182
          </xsl:if>
183
          <xsl:if test="$odd='true'">
184
            <xsl:if test="$verbose='true'">
185
              <xsl:message>reading file <xsl:value-of select="$cssODDFile"/></xsl:message>
186
            </xsl:if>
187
            <xsl:for-each select="tokenize(unparsed-text($cssODDFile),         '\r?\n')">
188
              <xsl:call-template name="purgeCSS"/>
189
            </xsl:for-each>
190
          </xsl:if>
191
          <xsl:if test="$odd='true'">
192
            <xsl:if test="$verbose='true'">
193
              <xsl:message>reading file <xsl:value-of select="$cssODDFile"/></xsl:message>
194
            </xsl:if>
195
            <xsl:for-each select="tokenize(unparsed-text($cssODDFile),         '\r?\n')">
196
              <xsl:call-template name="purgeCSS"/>
197
            </xsl:for-each>
198
          </xsl:if>
199
          <xsl:if test="$filePerPage='true'">
200
            <xsl:text>body { width: </xsl:text>
201
            <xsl:value-of select="$viewPortWidth"/>
202
            <xsl:text>px;
203
 height: </xsl:text>
204
            <xsl:value-of select="$viewPortHeight"/>
205
            <xsl:text>px;
206
}
207
img.fullpage {
208
position: absolute;
209
height: </xsl:text>
210
            <xsl:value-of select="$viewPortHeight"/>
211
            <xsl:text>px; left:0px; top:0px;}
212
</xsl:text>
213
          </xsl:if>
214
        </xsl:result-document>
215
        <xsl:if test="$verbose='true'">
216
          <xsl:message>write file OPS/print.css</xsl:message>
217
        </xsl:if>
218
        <xsl:result-document method="text" href="{concat($directory,'/OPS/print.css')}">
219
          <xsl:if test="$verbose='true'">
220
            <xsl:message>reading file <xsl:value-of select="$cssPrintFile"/></xsl:message>
221
          </xsl:if>
222
          <xsl:for-each select="tokenize(unparsed-text($cssPrintFile),     '\r?\n')">
223
            <xsl:call-template name="purgeCSS"/>
224
          </xsl:for-each>
225
        </xsl:result-document>
226
        <xsl:if test="$verbose='true'">
227
          <xsl:message>write file mimetype</xsl:message>
228
        </xsl:if>
229
        <xsl:result-document method="text" href="{concat($directory,'/mimetype')}">
230
          <xsl:value-of select="$epubMimetype"/>
231
        </xsl:result-document>
232
        <xsl:if test="$verbose='true'">
233
          <xsl:message>write file META-INF/container.xml</xsl:message>
234
        </xsl:if>
235
        <xsl:result-document method="xml" href="{concat($directory,'/META-INF/container.xml')}">
236
          <container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
237
            <rootfiles>
238
              <rootfile full-path="OPS/content.opf" media-type="application/oebps-package+xml"/>
239
            </rootfiles>
240
          </container>
241
        </xsl:result-document>
242
        <xsl:if test="$verbose='true'">
243
          <xsl:message>write file OPS/content.opf</xsl:message>
244
        </xsl:if>
245
        <xsl:result-document href="{concat($directory,'/OPS/content.opf')}" method="xml">
246
	  <xsl:variable name="A">
247
	    <xsl:call-template name="generateAuthor"/>
248
	  </xsl:variable>
249
	<xsl:variable name="printA">
250
	  <xsl:analyze-string select="$A" regex="([^,]+), ([^,]+), (.+)">
251
	    <xsl:matching-substring>
252
	      <xsl:value-of select="regex-group(1)"/>
253
	      <xsl:text>, </xsl:text>
254
	      <xsl:value-of select="regex-group(2)"/>
255
	    </xsl:matching-substring>
256
	    <xsl:non-matching-substring>
257
	      <xsl:value-of select="."/>
258
	    </xsl:non-matching-substring>
259
	  </xsl:analyze-string>
260
	</xsl:variable>
261

    
262
          <package xmlns="http://www.idpf.org/2007/opf" unique-identifier="dcidid" version="2.0">
263
	    <xsl:call-template name="opfmetadata">
264
	      <xsl:with-param name="author" select="$A"/>
265
	      <xsl:with-param name="printAuthor" select="$printA"/>
266
	      <xsl:with-param name="coverImageOutside" select="$coverImageOutside"/>
267
	    </xsl:call-template>
268
            <manifest>
269
              <!-- deal with intricacies of overlay files -->
270
              <xsl:variable name="TL" select="key('Timeline',1)"/>
271
              <xsl:if test="$mediaoverlay='true' and        key('Timeline',1)">
272
                <xsl:if test="$verbose='true'">
273
                  <xsl:message>write file SMIL files</xsl:message>
274
                </xsl:if>
275
                <xsl:for-each select="key('Timeline',1)">
276
                  <xsl:variable name="TLnumber">
277
                    <xsl:number level="any"/>
278
                  </xsl:variable>
279
                  <xsl:variable name="audio">
280
                    <xsl:text>media/audio</xsl:text>
281
                    <xsl:number level="any"/>
282
                    <xsl:text>.</xsl:text>
283
                    <xsl:value-of select="tokenize(@corresp,'\.')[last()]"/>
284
                  </xsl:variable>
285
                  <item id="timeline-audio{$TLnumber}" href="{$audio}">
286
                    <xsl:attribute name="media-type">
287
                      <xsl:choose>
288
                        <xsl:when test="contains($audio,'.m4a')">audio/m4a</xsl:when>
289
                        <xsl:otherwise>audio/m4a</xsl:otherwise>
290
                      </xsl:choose>
291
                    </xsl:attribute>
292
                  </item>
293
                  <xsl:for-each select="key('PB',1)">
294
                    <xsl:variable name="page">
295
                      <xsl:value-of select="generate-id()"/>
296
                    </xsl:variable>
297
                    <xsl:variable name="target">
298
                      <xsl:apply-templates select="." mode="ident"/>
299
                    </xsl:variable>
300
                    <xsl:if test="count(key('objectOnPage',$page))&gt;0">
301
                      <item id="{$target}-audio" href="{$target}-overlay.smil" media-type="application/smil+xml"/>
302
                      <xsl:result-document href="{concat($directory,'/OPS/',$target,'-overlay.smil')}" method="xml">
303
                        <smil xmlns="http://www.w3.org/ns/SMIL" version="3.0" profile="http://www.ipdf.org/epub/30/profile/content/">
304
                          <body>
305
                            <xsl:for-each select="key('objectOnPage',$page)">
306
                              <xsl:variable name="object" select="@xml:id"/>
307
                              <xsl:for-each select="$TL">
308
                                <xsl:for-each select="key('Object',$object)">
309
                                  <par id="{@xml:id}">
310
                                    <text src="{$target}.html{@corresp}"/>
311
                                    <audio src="{$audio}" clipBegin="{@from}{../@unit}" clipEnd="{@to}{../@unit}"/>
312
                                  </par>
313
                                </xsl:for-each>
314
                              </xsl:for-each>
315
                            </xsl:for-each>
316
                          </body>
317
                        </smil>
318
                      </xsl:result-document>
319
                    </xsl:if>
320
                  </xsl:for-each>
321
                </xsl:for-each>
322
              </xsl:if>
323
              <xsl:if test="not($coverImageOutside='')">
324
                <item href="{$coverImageOutside}" id="cover-image" media-type="image/jpeg"/>
325
              </xsl:if>
326
              <xsl:if test="not($coverimage='') and not($coverimage=$coverImageOutside)">
327
                <item href="{$coverimage}" id="cover-image-extra" media-type="image/jpeg"/>
328
              </xsl:if>
329
              <xsl:for-each select="tokenize($javascriptFiles,',')">
330
                <xsl:variable name="name" select="tokenize(normalize-space(.),'/')[last()]"/>
331
                <item href="{$name}" id="javascript{position()}" media-type="text/javascript"/>
332
              </xsl:for-each>
333
              <item href="stylesheet.css" id="css" media-type="text/css"/>
334
              <item href="titlepage.html" id="titlepage" media-type="application/xhtml+xml"/>
335
              <xsl:if test="$filePerPage='true'">
336
                <item href="titlepageverso.html" id="titlepageverso" media-type="application/xhtml+xml"/>
337
              </xsl:if>
338
              <xsl:for-each select="tei:text/tei:front/tei:titlePage">
339
                <xsl:variable name="N" select="position()"/>
340
                <item href="titlepage{$N}.html" id="titlepage{$N}" media-type="application/xhtml+xml"/>
341
              </xsl:for-each>
342
              <item href="titlepageback.html" id="titlepageback" media-type="application/xhtml+xml"/>
343
              <item id="print.css" href="print.css" media-type="text/css"/>
344
              <item id="apt" href="page-template.xpgt" media-type="application/adobe-page-template+xml"/>
345
              <item id="start" href="index.html" media-type="application/xhtml+xml"/>
346
              <xsl:choose>
347
                <xsl:when test="$filePerPage='true'">
348
                  <xsl:for-each select="key('PB',1)">
349
                    <xsl:variable name="target">
350
                      <xsl:apply-templates select="." mode="ident"/>
351
                    </xsl:variable>
352
                    <xsl:if test="@facs">
353
                      <xsl:variable name="facstarget">
354
                        <xsl:apply-templates select="." mode="ident"/>
355
                        <xsl:text>-facs.html</xsl:text>
356
                      </xsl:variable>
357
                      <item href="{$facstarget}" media-type="application/xhtml+xml">
358
                        <xsl:attribute name="id">
359
                          <xsl:text>pagefacs</xsl:text>
360
                          <xsl:number level="any"/>
361
                        </xsl:attribute>
362
                      </item>
363
                    </xsl:if>
364
                    <item href="{$target}.html" media-type="application/xhtml+xml">
365
                      <xsl:if test="$mediaoverlay='true'">
366
                        <xsl:attribute name="media-overlay">
367
                          <xsl:value-of select="$target"/>
368
                          <xsl:text>-audio</xsl:text>
369
                        </xsl:attribute>
370
                      </xsl:if>
371
                      <xsl:attribute name="id">
372
                        <xsl:text>page</xsl:text>
373
                        <xsl:number level="any"/>
374
                      </xsl:attribute>
375
                    </item>
376
                  </xsl:for-each>
377
                </xsl:when>
378
                <xsl:otherwise>
379
                  <xsl:for-each select="$TOC/html:TOC/html:ul/html:li">
380
                    <xsl:choose>
381
                      <xsl:when test="not(html:a)"/>
382
                      <xsl:when test="starts-with(html:a/@href,'#')"/>
383
                      <xsl:otherwise>
384
                        <item href="{html:a[1]/@href}" media-type="application/xhtml+xml">
385
                          <xsl:attribute name="id">
386
                            <xsl:text>section</xsl:text>
387
                            <xsl:number count="html:li" level="any"/>
388
                          </xsl:attribute>
389
                        </item>
390
                      </xsl:otherwise>
391
                    </xsl:choose>
392
                    <xsl:if test="html:ul">
393
                      <xsl:for-each select="html:ul//html:li[html:a          and          not(contains(html:a/@href,'#'))]">
394
                        <item href="{html:a[1]/@href}" media-type="application/xhtml+xml">
395
                          <xsl:attribute name="id">
396
                            <xsl:text>section</xsl:text>
397
                            <xsl:number count="html:li" level="any"/>
398
                          </xsl:attribute>
399
                        </item>
400
                      </xsl:for-each>
401
                    </xsl:if>
402
                  </xsl:for-each>
403
                </xsl:otherwise>
404
              </xsl:choose>
405
              <!-- images -->
406
              <xsl:for-each select="key('GRAPHICS',1)">
407
                <xsl:variable name="img" select="@url|@facs"/>
408
                <xsl:if test="not($img=$coverImageOutside)">
409
                  <xsl:variable name="ID">
410
                    <xsl:number level="any"/>
411
                  </xsl:variable>
412
                  <xsl:variable name="mimetype">
413
                    <xsl:choose>
414
                      <xsl:when test="@mimeType != ''">
415
                        <xsl:value-of select="@mimeType"/>
416
                      </xsl:when>
417
                      <xsl:when test="contains($img,'.gif')">image/gif</xsl:when>
418
                      <xsl:when test="contains($img,'.png')">image/png</xsl:when>
419
                      <xsl:when test="contains($img,'.mpeg')">video/mpeg4</xsl:when>
420
                      <xsl:when test="contains($img,'.mp4')">video/mpeg4</xsl:when>
421
                      <xsl:when test="contains($img,'.m4v')">video/mpeg4</xsl:when>
422
                      <xsl:otherwise>image/jpeg</xsl:otherwise>
423
                    </xsl:choose>
424
                  </xsl:variable>
425
                  <item href="{$img}" id="image-{$ID}" media-type="{$mimetype}"/>
426
                </xsl:if>
427
              </xsl:for-each>
428
              <!-- page images -->
429
              <xsl:for-each select="key('PBGRAPHICS',1)">
430
                <xsl:variable name="img" select="@facs"/>
431
                <xsl:variable name="ID">
432
                  <xsl:number level="any"/>
433
                </xsl:variable>
434
                <xsl:variable name="mimetype">
435
                  <xsl:choose>
436
                    <xsl:when test="@mimeType != ''">
437
                      <xsl:value-of select="@mimeType"/>
438
                    </xsl:when>
439
                    <xsl:when test="contains($img,'.gif')">image/gif</xsl:when>
440
                    <xsl:when test="contains($img,'.png')">image/png</xsl:when>
441
                    <xsl:otherwise>image/jpeg</xsl:otherwise>
442
                  </xsl:choose>
443
                </xsl:variable>
444
                <item href="{$img}" id="pbimage-{$ID}" media-type="{$mimetype}"/>
445
              </xsl:for-each>
446
              <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
447
              <xsl:call-template name="epubManifestHook"/>
448
            </manifest>
449
            <spine toc="ncx">
450
              <itemref idref="titlepage" linear="yes"/>
451
              <xsl:if test="$filePerPage='true'">
452
                <itemref idref="titlepageverso" linear="yes"/>
453
              </xsl:if>
454
              <xsl:for-each select="tei:text/tei:front/tei:titlePage">
455
                <xsl:variable name="N" select="position()"/>
456
                <itemref idref="titlepage{$N}" linear="yes"/>
457
              </xsl:for-each>
458
              <itemref idref="start" linear="yes"/>
459
              <xsl:choose>
460
                <xsl:when test="$filePerPage='true'">
461
                  <xsl:for-each select="key('PB',1)">
462
                    <xsl:if test="@facs">
463
                      <itemref>
464
                        <xsl:attribute name="idref">
465
                          <xsl:text>pagefacs</xsl:text>
466
                          <xsl:number level="any"/>
467
                        </xsl:attribute>
468
                        <xsl:attribute name="linear">yes</xsl:attribute>
469
                      </itemref>
470
                    </xsl:if>
471
                    <itemref>
472
                      <xsl:attribute name="idref">
473
                        <xsl:text>page</xsl:text>
474
                        <xsl:number level="any"/>
475
                      </xsl:attribute>
476
                      <xsl:attribute name="linear">yes</xsl:attribute>
477
                    </itemref>
478
                  </xsl:for-each>
479
                </xsl:when>
480
                <xsl:otherwise>
481
                  <xsl:for-each select="$TOC/html:TOC/html:ul/html:li">
482
                    <xsl:choose>
483
                      <xsl:when test="not(html:a)"/>
484
                      <xsl:when test="starts-with(html:a/@href,'#')"/>
485
                      <xsl:otherwise>
486
                        <itemref>
487
                          <xsl:attribute name="idref">
488
                            <xsl:text>section</xsl:text>
489
                            <xsl:number count="html:li" level="any"/>
490
                          </xsl:attribute>
491
                          <xsl:attribute name="linear">yes</xsl:attribute>
492
                        </itemref>
493
                      </xsl:otherwise>
494
                    </xsl:choose>
495
                    <xsl:if test="html:ul">
496
                      <xsl:for-each select="html:ul//html:li[html:a and not(contains(html:a/@href,'#'))]">
497
                        <itemref>
498
                          <xsl:attribute name="idref">
499
                            <xsl:text>section</xsl:text>
500
                            <xsl:number count="html:li" level="any"/>
501
                          </xsl:attribute>
502
                          <xsl:attribute name="linear">yes</xsl:attribute>
503
                        </itemref>
504
                      </xsl:for-each>
505
                    </xsl:if>
506
                  </xsl:for-each>
507
                </xsl:otherwise>
508
              </xsl:choose>
509
              <itemref idref="titlepageback">
510
                <xsl:attribute name="linear">
511
                  <xsl:choose>
512
                    <xsl:when test="$filePerPage='true'">yes</xsl:when>
513
                    <xsl:otherwise>no</xsl:otherwise>
514
                  </xsl:choose>
515
                </xsl:attribute>
516
              </itemref>
517
              <xsl:call-template name="epubSpineHook"/>
518
            </spine>
519
            <guide>
520
              <reference type="text" href="titlepage.html" title="Cover"/>
521
              <reference type="text" title="Start" href="index.html"/>
522
              <xsl:choose>
523
                <xsl:when test="$filePerPage='true'">
524
		</xsl:when>
525
                <xsl:otherwise>
526
                  <xsl:for-each select="$TOC/html:TOC/html:ul/html:li">
527
                    <xsl:if test="html:a">
528
                      <reference type="text" href="{html:a[1]/@href}">
529
                        <xsl:attribute name="title">
530
                          <xsl:value-of select="normalize-space(html:a[1])"/>
531
                        </xsl:attribute>
532
                      </reference>
533
                    </xsl:if>
534
                    <xsl:if test="contains(parent::html:ul/@class,'group')">
535
                      <xsl:for-each select="html:ul//html:li">
536
                        <xsl:choose>
537
                          <xsl:when test="not(html:a)"/>
538
                          <xsl:when test="contains(html:a/@href,'#')"/>
539
                          <xsl:otherwise>
540
                            <reference type="text" href="{html:a/@href}">
541
                              <xsl:attribute name="title">
542
                                <xsl:value-of select="normalize-space(html:a[1])"/>
543
                              </xsl:attribute>
544
                            </reference>
545
                          </xsl:otherwise>
546
                        </xsl:choose>
547
                      </xsl:for-each>
548
                    </xsl:if>
549
                  </xsl:for-each>
550
                </xsl:otherwise>
551
              </xsl:choose>
552
              <reference href="titlepageback.html" type="text" title="About this book"/>
553
            </guide>
554
          </package>
555
        </xsl:result-document>
556
        <xsl:if test="$verbose='true'">
557
          <xsl:message>write file OPS/titlepage.html</xsl:message>
558
        </xsl:if>
559
        <xsl:result-document href="{concat($directory,'/OPS/titlepage.html')}" method="xml">
560
          <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
561
            <head>
562
              <xsl:call-template name="metaHTML">
563
                <xsl:with-param name="title">Title page</xsl:with-param>
564
              </xsl:call-template>
565
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
566
              <meta name="calibre:cover" content="true"/>
567
              <title>Title page</title>
568
              <style type="text/css" title="override_css">
569
		@page {padding: 0pt; margin:0pt}
570
		body { text-align: center; padding:0pt; margin: 0pt; }
571
	      </style>
572
            </head>
573
            <body>
574
              <xsl:choose>
575
                <xsl:when test="$coverImageInside=''">
576
                  <div>
577
                    <xsl:attribute name="style">
578
		      font-family: serif; 
579
		      height:860;          
580
		      font-size:30pt; 
581
		      font-weight: bold;
582
		      padding-top: 15pt;
583
		      margin: 12pt;
584
		      border: solid red 1pt; 
585
		      text-align:center;
586
		    </xsl:attribute>
587
                    <xsl:call-template name="generateTitle"/>
588
                  </div>
589
                </xsl:when>
590
                <xsl:otherwise>
591
                  <div>
592
                    <img width="1200" height="1700" alt="cover picture" src="{$coverImageInside}"/>
593
                  </div>
594
                </xsl:otherwise>
595
              </xsl:choose>
596
            </body>
597
          </html>
598
        </xsl:result-document>
599
        <xsl:for-each select="tei:text/tei:front/tei:titlePage">
600
          <xsl:variable name="N" select="position()"/>
601
          <xsl:if test="$verbose='true'">
602
            <xsl:message>write file OPS/titlepage<xsl:value-of select="$N"/>.html</xsl:message>
603
          </xsl:if>
604
          <xsl:result-document href="{concat($directory,'/OPS/titlepage',$N,'.html')}" method="xml">
605
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
606
              <head>
607
                <xsl:call-template name="metaHTML">
608
                  <xsl:with-param name="title">Title page</xsl:with-param>
609
                </xsl:call-template>
610
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
611
                <xsl:call-template name="linkCSS">
612
		  <xsl:with-param
613
		      name="file">stylesheet.css</xsl:with-param>
614
		</xsl:call-template>
615
                <title>Title page</title>
616
              </head>
617
              <body>
618
                <div class="titlePage">
619
                  <xsl:apply-templates/>
620
                </div>
621
              </body>
622
            </html>
623
          </xsl:result-document>
624
        </xsl:for-each>
625
        <xsl:if test="$filePerPage='true'">
626
          <xsl:if test="$verbose='true'">
627
            <xsl:message>write file OPS/titlepageverso.html</xsl:message>
628
          </xsl:if>
629
          <xsl:result-document href="{concat($directory,'/OPS/titlepageverso.html')}" method="xml">
630
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
631
              <head>
632
                <xsl:call-template name="metaHTML">
633
                  <xsl:with-param name="title">title page verso</xsl:with-param>
634
                </xsl:call-template>
635
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
636
                <title>title page verso</title>
637
              </head>
638
              <body>
639
                <p/>
640
              </body>
641
            </html>
642
          </xsl:result-document>
643
        </xsl:if>
644
        <xsl:if test="$verbose='true'">
645
          <xsl:message>write file OPS/titlepageback.html</xsl:message>
646
        </xsl:if>
647
        <xsl:result-document href="{concat($directory,'/OPS/titlepageback.html')}" method="xml">
648
          <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
649
            <head>
650
              <xsl:call-template name="metaHTML">
651
                <xsl:with-param name="title">About this book</xsl:with-param>
652
              </xsl:call-template>
653
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
654
              <title>About this book</title>
655
            </head>
656
            <body>
657
              <div style="text-align: left; font-size: larger">
658
                <h2>Information about this book</h2>
659
                <xsl:for-each select="/*/tei:teiHeader/tei:fileDesc">
660
                  <xsl:apply-templates mode="metadata"/>
661
                </xsl:for-each>
662
                <xsl:for-each select="/*/tei:teiHeader/tei:encodingDesc">
663
                  <xsl:apply-templates mode="metadata"/>
664
                </xsl:for-each>
665
              </div>
666
            </body>
667
          </html>
668
        </xsl:result-document>
669
        <xsl:if test="$verbose='true'">
670
          <xsl:message>write file OPS/toc.ncx</xsl:message>
671
        </xsl:if>
672
        <xsl:result-document href="{concat($directory,'/OPS/toc.ncx')}" method="xml">
673
          <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
674
            <head>
675
              <meta name="dtb:uid">
676
                <xsl:attribute name="content">
677
                  <xsl:call-template name="generateID"/>
678
                </xsl:attribute>
679
              </meta>
680
              <meta name="dtb:totalPageCount" content="0"/>
681
              <meta name="dtb:maxPageNumber" content="0"/>
682
            </head>
683
            <docTitle>
684
              <text>
685
                <xsl:call-template name="generateSimpleTitle"/>
686
              </text>
687
            </docTitle>
688
            <navMap>
689
              <xsl:variable name="navPoints">
690
                <navPoint>
691
                  <navLabel>
692
                    <text>[Cover]</text>
693
                  </navLabel>
694
                  <content src="titlepage.html"/>
695
                </navPoint>
696
                <xsl:for-each select="tei:text/tei:front/tei:titlePage[1]">
697
                  <xsl:variable name="N" select="position()"/>
698
                  <navPoint>
699
                    <navLabel>
700
                      <text>[Title page]</text>
701
                    </navLabel>
702
                    <content src="titlepage{$N}.html"/>
703
                  </navPoint>
704
                </xsl:for-each>
705
                <xsl:choose>
706
                  <xsl:when test="not($TOC/html:TOC/html:ul[@class='toc toc_body']/html:li)">
707
                    <xsl:for-each select="$TOC/html:TOC/html:ul[@class='toc toc_front']">
708
                      <xsl:apply-templates select="html:li"/>
709
                    </xsl:for-each>
710
                    <navPoint>
711
                      <navLabel>
712
                        <text>[The book]</text>
713
                      </navLabel>
714
                      <content src="index.html"/>
715
                    </navPoint>
716
                    <xsl:for-each select="$TOC/html:TOC/html:ul[contains(@class,'group')]">
717
                      <xsl:apply-templates select=".//html:li[not(contains(html:a/@href,'#'))]"/>
718
                    </xsl:for-each>
719
                    <xsl:for-each select="$TOC/html:TOC/html:ul[@class='toc toc_back']">
720
                      <xsl:apply-templates select="html:li"/>
721
                    </xsl:for-each>
722
                  </xsl:when>
723
                  <xsl:otherwise>
724
                    <xsl:for-each select="$TOC/html:TOC/html:ul">
725
                      <xsl:apply-templates select="html:li"/>
726
                    </xsl:for-each>
727
                  </xsl:otherwise>
728
                </xsl:choose>
729
                <navPoint>
730
                  <navLabel>
731
                    <text>[About this book]</text>
732
                  </navLabel>
733
                  <content src="titlepageback.html"/>
734
                </navPoint>
735
              </xsl:variable>
736
              <xsl:for-each select="$navPoints/ncx:navPoint">
737
                <xsl:variable name="pos" select="position()"/>
738
                <navPoint id="navPoint-{$pos}" playOrder="{$pos}">
739
                  <xsl:copy-of select="*"/>
740
                </navPoint>
741
              </xsl:for-each>
742
            </navMap>
743
          </ncx>
744
        </xsl:result-document>
745
        <xsl:if test="$verbose='true'">
746
          <xsl:message>write file OPS/page-template.xpgt</xsl:message>
747
        </xsl:if>
748
        <xsl:result-document method="xml" href="{concat($directory,'/OPS/page-template.xpgt')}">
749
          <ade:template xmlns="http://www.w3.org/1999/xhtml" xmlns:ade="http://ns.adobe.com/2006/ade" xmlns:fo="http://www.w3.org/1999/XSL/Format">
750
            <fo:layout-master-set>
751
              <fo:simple-page-master master-name="single_column">
752
                <fo:region-body margin-bottom="3pt" margin-top="0.5em" margin-left="3pt" margin-right="3pt"/>
753
              </fo:simple-page-master>
754
              <fo:simple-page-master master-name="single_column_head">
755
                <fo:region-before extent="8.3em"/>
756
                <fo:region-body margin-bottom="3pt" margin-top="6em" margin-left="3pt" margin-right="3pt"/>
757
              </fo:simple-page-master>
758
              <fo:simple-page-master master-name="two_column" margin-bottom="0.5em" margin-top="0.5em" margin-left="0.5em" margin-right="0.5em">
759
                <fo:region-body column-count="2" column-gap="10pt"/>
760
              </fo:simple-page-master>
761
              <fo:simple-page-master master-name="two_column_head" margin-bottom="0.5em" margin-left="0.5em" margin-right="0.5em">
762
                <fo:region-before extent="8.3em"/>
763
                <fo:region-body column-count="2" margin-top="6em" column-gap="10pt"/>
764
              </fo:simple-page-master>
765
              <fo:simple-page-master master-name="three_column" margin-bottom="0.5em" margin-top="0.5em" margin-left="0.5em" margin-right="0.5em">
766
                <fo:region-body column-count="3" column-gap="10pt"/>
767
              </fo:simple-page-master>
768
              <fo:simple-page-master master-name="three_column_head" margin-bottom="0.5em" margin-top="0.5em" margin-left="0.5em" margin-right="0.5em">
769
                <fo:region-before extent="8.3em"/>
770
                <fo:region-body column-count="3" margin-top="6em" column-gap="10pt"/>
771
              </fo:simple-page-master>
772
              <fo:page-sequence-master>
773
                <fo:repeatable-page-master-alternatives>
774
                  <fo:conditional-page-master-reference master-reference="three_column_head" page-position="first" ade:min-page-width="80em"/>
775
                  <fo:conditional-page-master-reference master-reference="three_column" ade:min-page-width="80em"/>
776
                  <fo:conditional-page-master-reference master-reference="two_column_head" page-position="first" ade:min-page-width="50em"/>
777
                  <fo:conditional-page-master-reference master-reference="two_column" ade:min-page-width="50em"/>
778
                  <fo:conditional-page-master-reference master-reference="single_column_head" page-position="first"/>
779
                  <fo:conditional-page-master-reference master-reference="single_column"/>
780
                </fo:repeatable-page-master-alternatives>
781
              </fo:page-sequence-master>
782
            </fo:layout-master-set>
783
            <ade:style>
784
              <ade:styling-rule selector=".title_box" display="adobe-other-region" adobe-region="xsl-region-before"/>
785
            </ade:style>
786
          </ade:template>
787
        </xsl:result-document>
788
        <xsl:if test="$filePerPage='true'">
789
          <xsl:if test="$verbose='true'">
790
            <xsl:message>write file META-INF/com.apple.ibooks.display-options.xml</xsl:message>
791
          </xsl:if>
792
          <xsl:result-document href="{concat($directory,'/META-INF/com.apple.ibooks.display-options.xml')}">
793
            <display_options xmlns="">
794
              <platform name="*">
795
                <option name="fixed-layout">true</option>
796
              </platform>
797
            </display_options>
798
          </xsl:result-document>
799
        </xsl:if>
800
      </xsl:for-each>
801
    </xsl:for-each>
802
  </xsl:template>
803
  <xsl:template match="html:li">
804
    <xsl:choose>
805
      <xsl:when test="not(html:a)"/>
806
      <xsl:when test="starts-with(html:a/@href,'#')"/>
807
      <xsl:when test="contains(@class,'headless')"/>
808
      <xsl:when test="html:a/@href=preceding-sibling::html:li/html:a/@href"/>
809
      <xsl:otherwise>
810
        <navPoint xmlns="http://www.daisy.org/z3986/2005/ncx/">
811
          <navLabel>
812
            <text>
813
              <xsl:value-of select="html:span[@class='headingNumber']"/>
814
              <xsl:value-of select="normalize-space(html:a[1])"/>
815
            </text>
816
          </navLabel>
817
          <content src="{html:a/@href}"/>
818
        </navPoint>
819
      </xsl:otherwise>
820
    </xsl:choose>
821
  </xsl:template>
822
  <xsl:template name="javascriptHook">
823
    <xsl:for-each select="tokenize($javascriptFiles,',')">
824
      <xsl:variable name="name" select="tokenize(normalize-space(.),'/')[last()]"/>
825
      <script type="text/javascript" src="{$name}">
826
        <xsl:comment>JS library</xsl:comment>
827
      </script>
828
    </xsl:for-each>
829
  </xsl:template>
830
  <xsl:template name="epubSpineHook"/>
831
  <xsl:template name="epubManifestHook"/>
832
  <xsl:template name="processTEIHook"/>
833
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
834
    <desc>[epub] Override addition of CSS links. We force a simple
835
      name of "stylesheet.css"
836
      </desc>
837
  </doc>
838
  <xsl:template name="includeCSS">
839
    <link xmlns="http://www.w3.org/1999/xhtml" href="stylesheet.css" rel="stylesheet" type="text/css"/>
840
    <xsl:if test="not($cssPrintFile='')">
841
      <link xmlns="http://www.w3.org/1999/xhtml" rel="stylesheet" media="print" type="text/css" href="print.css"/>
842
    </xsl:if>
843
    <link xmlns="http://www.w3.org/1999/xhtml" rel="stylesheet" type="application/vnd.adobe-page-template+xml" href="page-template.xpgt"/>
844
    <xsl:call-template name="generateLocalCSS"/>
845
  </xsl:template>
846

    
847
  <xsl:template name="opfmetadata">
848
    <xsl:param name="author"/>
849
    <xsl:param name="printAuthor"/>
850
    <xsl:param name="coverImageOutside"/>
851
    <metadata xmlns="http://www.idpf.org/2007/opf"
852
	      xmlns:dc="http://purl.org/dc/elements/1.1/" 
853
	      xmlns:dcterms="http://purl.org/dc/terms/" 
854
	      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
855
	      xmlns:opf="http://www.idpf.org/2007/opf">
856
      <dc:title>
857
	<xsl:call-template name="generateSimpleTitle"/>
858
      </dc:title>
859
      <dc:language xsi:type="dcterms:RFC3066">
860
	<xsl:call-template name="generateLanguage"/>
861
      </dc:language>
862
      <xsl:call-template name="generateSubject"/>
863
      <dc:identifier id="dcidid" opf:scheme="URI">
864
	<xsl:call-template name="generateID"/>
865
      </dc:identifier>
866
      <dc:description>
867
	<xsl:call-template name="generateSimpleTitle"/>
868
	<xsl:text> / </xsl:text>
869
	<xsl:value-of select="$author"/>
870
      </dc:description>
871
      <dc:creator>
872
	<xsl:choose>
873
	  <xsl:when test="$printAuthor=''">Anonymous/Unknown</xsl:when>
874
	  <xsl:otherwise>
875
	    <xsl:value-of select="$printAuthor"/>
876
	  </xsl:otherwise>
877
	</xsl:choose>
878
      </dc:creator>
879
      <dc:publisher>
880
	<xsl:call-template name="generatePublisher"/>
881
      </dc:publisher>
882
      <xsl:for-each select="tei:teiHeader/tei:profileDesc/tei:creation/tei:date[@notAfter]">
883
	<dc:date opf:event="creation">
884
	  <xsl:value-of select="@notAfter"/>
885
	</dc:date>
886
      </xsl:for-each>
887
      <xsl:for-each select="tei:teiHeader/tei:fileDesc/tei:sourceDesc//tei:date[@when][1]">
888
	<dc:date opf:event="original-publication">
889
	  <xsl:value-of select="@when"/>
890
	</dc:date>
891
      </xsl:for-each>
892
      <dc:date opf:event="epub-publication" xsi:type="dcterms:W3CDTF">
893
	<xsl:call-template name="generateDate"/>
894
      </dc:date>
895
      <dc:rights>
896
	<xsl:call-template name="generateLicence"/>
897
      </dc:rights>
898
      <xsl:if test="not($coverImageOutside='')">
899
	<meta name="cover" content="cover-image"/>
900
      </xsl:if>
901
    </metadata>
902
</xsl:template>
903

    
904
</xsl:stylesheet>