Statistics
| Revision:

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

History | View | Annotate | Download (39.7 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:dc="http://purl.org/dc/elements/1.1/" 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 ncx" xpath-default-namespace="http://www.tei-c.org/ns/1.0">
3
  <xsl:import href="../html5/tei.xsl"/>
4
  <xsl:import href="../epub/epub-common.xsl"/>
5
  <xsl:import href="../epub/epub-preflight.xsl"/>
6
  <xsl:output method="xml" encoding="utf-8" doctype-system="" indent="no"/>
7
  <xsl:key match="tei:graphic[not(ancestor::teix:egXML)]" use="1" name="G"/>
8
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
9
    <desc>
10
      <p>
11
	TEI stylesheet for making ePub output. A lot learnt from
12
	http://www.hxa.name/articles/content/epub-guide_hxa7241_2007.xhtml and
13
	the stylesheets of the NZETC.
14
      </p>
15
      <p>This software is dual-licensed:
16

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

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

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

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

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

    
35
This software is provided by the copyright holders and contributors
36
"as is" and any express or implied warranties, including, but not
37
limited to, the implied warranties of merchantability and fitness for
38
a particular purpose are disclaimed. In no event shall the copyright
39
holder or contributors be liable for any direct, indirect, incidental,
40
special, exemplary, or consequential damages (including, but not
41
limited to, procurement of substitute goods or services; loss of use,
42
data, or profits; or business interruption) however caused and on any
43
theory of liability, whether in contract, strict liability, or tort
44
(including negligence or otherwise) arising in any way out of the use
45
of this software, even if advised of the possibility of such damage.
46
</p>
47
      <p>Author: See AUTHORS</p>
48
      <p>Id: $Id: tei-to-epub3.xsl 10057 2012-01-21 16:57:14Z rahtz $</p>
49
      <p>Copyright: 2008, TEI Consortium</p>
50
    </desc>
51
  </doc>
52
  <xsl:param name="opfPackageVersion">3.0</xsl:param>
53
  <xsl:param name="STDOUT">false</xsl:param>
54
  <xsl:param name="autoHead">true</xsl:param>
55
  <xsl:param name="autoToc">true</xsl:param>
56
  <xsl:param name="bottomNavigationPanel">false</xsl:param>
57
  <xsl:param name="coverimage"/>
58
  <xsl:param name="createanttask">false</xsl:param>
59
  <xsl:param name="cssFile">../tei.css</xsl:param>
60
  <xsl:param name="cssODDFile">../odd.css</xsl:param>
61
  <xsl:param name="cssPrintFile">../epub-print.css</xsl:param>
62
  <xsl:param name="debug">false</xsl:param>
63
  <xsl:param name="directory">.</xsl:param>
64
  <xsl:param name="doctypePublic"/>
65
  <xsl:param name="doctypeSystem"/>
66
  <xsl:param name="fixgraphicsurl">false</xsl:param>
67
  <xsl:param name="inputDir">.</xsl:param>
68
  <xsl:param name="institution"/>
69
  <xsl:param name="linkPanel">false</xsl:param>
70
  <xsl:param name="odd">false</xsl:param>
71
  <xsl:param name="outputDir"><xsl:value-of select="$directory"/>/OPS</xsl:param>
72
  <xsl:param name="outputMethod">xml</xsl:param>
73
  <xsl:param name="outputSuffix">.xhtml</xsl:param>
74
  <xsl:param name="outputTarget">epub3</xsl:param>
75
  <xsl:param name="publisher"/>
76
  <xsl:param name="splitLevel">0</xsl:param>
77
  <xsl:param name="subject"/>
78
  <xsl:param name="tocDepth">5</xsl:param>
79
  <xsl:param name="tocFront">true</xsl:param>
80
  <xsl:param name="topNavigationPanel">false</xsl:param>
81
  <xsl:param name="uid"/>
82
  <xsl:param name="useHeaderFrontMatter">false</xsl:param>
83
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
84
    <desc>(extensible) wrapper for root element</desc>
85
  </doc>
86
  <xsl:template match="/">
87
    <xsl:call-template name="processTEI"/>
88
  </xsl:template>
89
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
90
    <desc>[epub] Override of top-level template. This does most of
91
  the work: performing the normal transformation, fixing the links to graphics files so that they are
92
  all relative, creating the extra output files, etc</desc>
93
  </doc>
94
  <xsl:template name="processTEI">
95
    <xsl:variable name="stage1">
96
      <xsl:apply-templates mode="preflight"/>
97
    </xsl:variable>
98
    <xsl:for-each select="$stage1">
99
      <xsl:call-template name="processTEIHook"/>
100
      <xsl:variable name="coverImageOutside">
101
        <xsl:choose>
102
          <xsl:when test="/tei:TEI/tei:text/tei:front/tei:titlePage[@facs]">
103
            <xsl:for-each select="/tei:TEI/tei:text/tei:front/tei:titlePage[@facs][1]">
104
              <xsl:for-each select="id(substring(@facs,2))">
105
                <xsl:choose>
106
                  <xsl:when test="count(tei:graphic)=1">
107
                    <xsl:value-of select="tei:graphic/@url"/>
108
                  </xsl:when>
109
                  <xsl:otherwise>
110
                    <xsl:value-of select="tei:graphic[2]/@url"/>
111
                  </xsl:otherwise>
112
                </xsl:choose>
113
              </xsl:for-each>
114
            </xsl:for-each>
115
          </xsl:when>
116
          <xsl:when test="not($coverimage='')">
117
            <xsl:value-of select="$coverimage"/>
118
          </xsl:when>
119
        </xsl:choose>
120
      </xsl:variable>
121
      <xsl:variable name="coverImageInside">
122
        <xsl:choose>
123
          <xsl:when test="/tei:TEI/tei:text/tei:front/tei:titlePage[@facs]">
124
            <xsl:for-each select="/tei:TEI/tei:text/tei:front/tei:titlePage[@facs][1]">
125
              <xsl:for-each select="id(substring(@facs,2))">
126
                <xsl:value-of select="tei:graphic[1]/@url"/>
127
              </xsl:for-each>
128
            </xsl:for-each>
129
          </xsl:when>
130
          <xsl:when test="not($coverimage='')">
131
            <xsl:value-of select="$coverimage"/>
132
          </xsl:when>
133
        </xsl:choose>
134
      </xsl:variable>
135
      <xsl:choose>
136
        <xsl:when test="$splitLevel='-1'">
137
          <xsl:apply-templates/>
138
        </xsl:when>
139
        <xsl:otherwise>
140
          <xsl:apply-templates mode="split"/>
141
        </xsl:otherwise>
142
      </xsl:choose>
143
      <xsl:for-each select="*">
144
        <xsl:variable name="TOC">
145
          <TOC xmlns="http://www.w3.org/1999/xhtml">
146
            <xsl:call-template name="mainTOC"/>
147
          </TOC>
148
        </xsl:variable>
149
        <!--
150
	    <xsl:result-document href="/tmp/TOC">
151
	    <xsl:copy-of select="$TOC"/>
152
	    </xsl:result-document>
153
-->
154
        <xsl:for-each select="tokenize($javascriptFiles,',')">
155
          <xsl:variable name="file" select="normalize-space(.)"/>
156
          <xsl:variable name="name" select="tokenize($file,'/')[last()]"/>
157
          <xsl:if test="$verbose='true'">
158
            <xsl:message>write Javascript file <xsl:value-of select="$name"/></xsl:message>
159
          </xsl:if>
160
          <xsl:result-document method="text" href="{concat($directory,'/OPS/',$name)}">
161
            <xsl:for-each select="unparsed-text($file)">
162
              <xsl:copy-of select="."/>
163
            </xsl:for-each>
164
          </xsl:result-document>
165
        </xsl:for-each>
166
        <xsl:if test="$verbose='true'">
167
          <xsl:message>write file OPS/stylesheet.css</xsl:message>
168
        </xsl:if>
169
        <xsl:result-document method="text" href="{concat($directory,'/OPS/stylesheet.css')}">
170
          <xsl:if test="not($cssFile='')">
171
            <xsl:if test="$verbose='true'">
172
              <xsl:message>reading file <xsl:value-of select="$cssFile"/></xsl:message>
173
            </xsl:if>
174
            <xsl:for-each select="tokenize(unparsed-text($cssFile),     '\r?\n')">
175
              <xsl:call-template name="purgeCSS"/>
176
            </xsl:for-each>
177
          </xsl:if>
178
          <xsl:if test="not($cssSecondaryFile='')">
179
            <xsl:if test="$verbose='true'">
180
              <xsl:message>reading secondary file <xsl:value-of select="$cssSecondaryFile"/></xsl:message>
181
            </xsl:if>
182
            <xsl:for-each select="tokenize(unparsed-text($cssSecondaryFile),       '\r?\n')">
183
              <xsl:call-template name="purgeCSS"/>
184
            </xsl:for-each>
185
          </xsl:if>
186
          <xsl:if test="$odd='true'">
187
            <xsl:if test="$verbose='true'">
188
              <xsl:message>reading file <xsl:value-of select="$cssODDFile"/></xsl:message>
189
            </xsl:if>
190
            <xsl:for-each select="tokenize(unparsed-text($cssODDFile),         '\r?\n')">
191
              <xsl:call-template name="purgeCSS"/>
192
            </xsl:for-each>
193
          </xsl:if>
194
          <xsl:if test="$odd='true'">
195
            <xsl:if test="$verbose='true'">
196
              <xsl:message>reading file <xsl:value-of select="$cssODDFile"/></xsl:message>
197
            </xsl:if>
198
            <xsl:for-each select="tokenize(unparsed-text($cssODDFile),         '\r?\n')">
199
              <xsl:call-template name="purgeCSS"/>
200
            </xsl:for-each>
201
          </xsl:if>
202
          <xsl:if test="$filePerPage='true'">
203
            <xsl:text>body { width: </xsl:text>
204
            <xsl:value-of select="$viewPortWidth"/>
205
            <xsl:text>px;
206
 height: </xsl:text>
207
            <xsl:value-of select="$viewPortHeight"/>
208
            <xsl:text>px;
209
}
210
img.fullpage {
211
position: absolute;
212
height: </xsl:text>
213
            <xsl:value-of select="$viewPortHeight"/>
214
            <xsl:text>px; left:0px; top:0px;}
215
</xsl:text>
216
          </xsl:if>
217
        </xsl:result-document>
218
        <xsl:if test="$verbose='true'">
219
          <xsl:message>write file OPS/print.css</xsl:message>
220
        </xsl:if>
221
        <xsl:result-document method="text" href="{concat($directory,'/OPS/print.css')}">
222
          <xsl:if test="$verbose='true'">
223
            <xsl:message>reading file <xsl:value-of select="$cssPrintFile"/></xsl:message>
224
          </xsl:if>
225
          <xsl:for-each select="tokenize(unparsed-text($cssPrintFile),     '\r?\n')">
226
            <xsl:call-template name="purgeCSS"/>
227
          </xsl:for-each>
228
        </xsl:result-document>
229
        <xsl:if test="$verbose='true'">
230
          <xsl:message>write file mimetype</xsl:message>
231
        </xsl:if>
232
        <xsl:result-document method="text" href="{concat($directory,'/mimetype')}">
233
          <xsl:value-of select="$epubMimetype"/>
234
        </xsl:result-document>
235
        <xsl:if test="$verbose='true'">
236
          <xsl:message>write file META-INF/container.xml</xsl:message>
237
        </xsl:if>
238
        <xsl:result-document method="xml" href="{concat($directory,'/META-INF/container.xml')}">
239
          <container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
240
            <rootfiles>
241
              <rootfile full-path="OPS/package.opf" media-type="application/oebps-package+xml"/>
242
            </rootfiles>
243
          </container>
244
        </xsl:result-document>
245
        <xsl:if test="$verbose='true'">
246
          <xsl:message>write file OPS/package.opf</xsl:message>
247
        </xsl:if>
248
	<xsl:variable name="A">
249
	  <xsl:call-template name="generateAuthor"/>
250
	</xsl:variable>
251
	<xsl:variable name="printA">
252
	  <xsl:analyze-string select="$A" regex="([^,]+), ([^,]+), (.+)">
253
	    <xsl:matching-substring>
254
	      <xsl:value-of select="regex-group(1)"/>
255
	      <xsl:text>, </xsl:text>
256
	      <xsl:value-of select="regex-group(2)"/>
257
	    </xsl:matching-substring>
258
	    <xsl:non-matching-substring>
259
	      <xsl:value-of select="."/>
260
	    </xsl:non-matching-substring>
261
	  </xsl:analyze-string>
262
	</xsl:variable>	
263
        <xsl:result-document
264
	    href="{concat($directory,'/OPS/package.opf')}"
265
	    method="xml" indent="yes">
266
          <package xmlns="http://www.idpf.org/2007/opf" unique-identifier="pub-id" version="{$opfPackageVersion}">
267
	    <xsl:call-template name="opfmetadata">
268
	      <xsl:with-param name="author" select="$A"/>
269
	      <xsl:with-param name="printAuthor" select="$printA"/>
270
	      <xsl:with-param name="coverImageOutside" select="$coverImageOutside"/>
271
	    </xsl:call-template>
272
            <manifest>
273
              <!-- deal with intricacies of overlay files -->
274
              <xsl:variable name="TL" select="key('Timeline',1)"/>
275
              <xsl:if test="$mediaoverlay='true' and key('Timeline',1)">
276
                <xsl:if test="$verbose='true'">
277
                  <xsl:message>write file SMIL files</xsl:message>
278
                </xsl:if>
279
                <xsl:for-each select="key('Timeline',1)">
280
                  <xsl:variable name="TLnumber">
281
                    <xsl:number level="any"/>
282
                  </xsl:variable>
283
                  <xsl:variable name="audio">
284
                    <xsl:text>media/audio</xsl:text>
285
                    <xsl:number level="any"/>
286
                    <xsl:text>.</xsl:text>
287
                    <xsl:value-of select="tokenize(@corresp,'\.')[last()]"/>
288
                  </xsl:variable>
289
                  <item id="timeline-audio{$TLnumber}" href="{$audio}">
290
                    <xsl:attribute name="media-type">
291
                      <xsl:choose>
292
                        <xsl:when test="contains($audio,'.m4a')">audio/m4a</xsl:when>
293
                        <xsl:otherwise>audio/m4a</xsl:otherwise>
294
                      </xsl:choose>
295
                    </xsl:attribute>
296
                  </item>
297
                  <xsl:for-each select="key('PB',1)">
298
                    <xsl:variable name="page">
299
                      <xsl:value-of select="generate-id()"/>
300
                    </xsl:variable>
301
                    <xsl:variable name="target">
302
                      <xsl:apply-templates select="." mode="ident"/>
303
                    </xsl:variable>
304
                    <xsl:if test="count(key('objectOnPage',$page))&gt;0">
305
                      <item id="{$target}-audio" href="{$target}-overlay.smil" media-type="application/smil+xml"/>
306
                      <xsl:result-document href="{concat($directory,'/OPS/',$target,'-overlay.smil')}" method="xml">
307
                        <smil xmlns="http://www.w3.org/ns/SMIL" version="3.0" profile="http://www.ipdf.org/epub/30/profile/content/">
308
                          <body>
309
                            <xsl:for-each select="key('objectOnPage',$page)">
310
                              <xsl:variable name="object" select="@xml:id"/>
311
                              <xsl:for-each select="$TL">
312
                                <xsl:for-each select="key('Object',$object)">
313
                                  <par id="{@xml:id}">
314
                                    <text src="{$target}.xhtml{@corresp}"/>
315
                                    <audio src="{$audio}" clipBegin="{@from}{../@unit}" clipEnd="{@to}{../@unit}"/>
316
                                  </par>
317
                                </xsl:for-each>
318
                              </xsl:for-each>
319
                            </xsl:for-each>
320
                          </body>
321
                        </smil>
322
                      </xsl:result-document>
323
                    </xsl:if>
324
                  </xsl:for-each>
325
                </xsl:for-each>
326
              </xsl:if>
327
              <xsl:if test="not($coverImageOutside='')">
328
                <item href="{$coverImageOutside}" id="cover-image" media-type="image/jpeg"/>
329
              </xsl:if>
330
              <xsl:if test="not($coverimage='') and not($coverimage=$coverImageOutside)">
331
                <item href="{$coverimage}" id="cover-image-extra" media-type="image/jpeg"/>
332
              </xsl:if>
333
              <xsl:for-each select="tokenize($javascriptFiles,',')">
334
                <xsl:variable name="name" select="tokenize(normalize-space(.),'/')[last()]"/>
335
                <item href="{$name}" id="javascript{position()}" media-type="text/javascript"/>
336
              </xsl:for-each>
337
              <item id="css" href="stylesheet.css" media-type="text/css"/>
338
              <item id="print.css" href="print.css" media-type="text/css"/>
339
              <item href="titlepage.xhtml" id="titlepage" media-type="application/xhtml+xml"/>
340
              <xsl:if test="$filePerPage='true'">
341
                <item href="titlepageverso.xhtml" id="titlepageverso" media-type="application/xhtml+xml"/>
342
              </xsl:if>
343
              <xsl:for-each select="tei:text/tei:front/tei:titlePage">
344
                <xsl:variable name="N" select="position()"/>
345
                <item href="titlepage{$N}.xhtml" id="titlepage{$N}" media-type="application/xhtml+xml"/>
346
              </xsl:for-each>
347
              <item href="titlepageback.xhtml" id="titlepageback" media-type="application/xhtml+xml"/>
348
              <item id="toc" properties="nav" href="toc.xhtml" media-type="application/xhtml+xml"/>
349
              <item id="start" href="index.xhtml" media-type="application/xhtml+xml"/>
350
              <xsl:choose>
351
                <xsl:when test="$filePerPage='true'">
352
                  <xsl:for-each select="key('PB',1)">
353
                    <xsl:variable name="target">
354
                      <xsl:apply-templates select="." mode="ident"/>
355
                    </xsl:variable>
356
                    <xsl:if test="@facs">
357
                      <xsl:variable name="facstarget">
358
                        <xsl:apply-templates select="." mode="ident"/>
359
                        <xsl:text>-facs.xhtml</xsl:text>
360
                      </xsl:variable>
361
                      <item href="{$facstarget}" media-type="application/xhtml+xml">
362
                        <xsl:attribute name="id">
363
                          <xsl:text>pagefacs</xsl:text>
364
                          <xsl:number level="any"/>
365
                        </xsl:attribute>
366
                      </item>
367
                    </xsl:if>
368
                    <item href="{$target}.xhtml" media-type="application/xhtml+xml">
369
                      <xsl:if test="$mediaoverlay='true'">
370
                        <xsl:attribute name="media-overlay">
371
                          <xsl:value-of select="$target"/>
372
                          <xsl:text>-audio</xsl:text>
373
                        </xsl:attribute>
374
                      </xsl:if>
375
                      <xsl:attribute name="id">
376
                        <xsl:text>page</xsl:text>
377
                        <xsl:number level="any"/>
378
                      </xsl:attribute>
379
                    </item>
380
                  </xsl:for-each>
381
                </xsl:when>
382
                <xsl:otherwise>
383
                  <xsl:for-each select="$TOC/html:TOC/html:ul/html:li">
384
                    <xsl:choose>
385
                      <xsl:when test="not(html:a)"/>
386
                      <xsl:when test="starts-with(html:a/@href,'#')"/>
387
                      <xsl:otherwise>
388
                        <item href="{html:a[1]/@href}" media-type="application/xhtml+xml">
389
                          <xsl:attribute name="id">
390
                            <xsl:text>section</xsl:text>
391
                            <xsl:number count="html:li" level="any"/>
392
                          </xsl:attribute>
393
                        </item>
394
                      </xsl:otherwise>
395
                    </xsl:choose>
396
                    <xsl:if test="html:ul">
397
                      <xsl:for-each select="html:ul//html:li[html:a          and          not(contains(html:a/@href,'#'))]">
398
                        <item href="{html:a[1]/@href}" media-type="application/xhtml+xml">
399
                          <xsl:attribute name="id">
400
                            <xsl:text>section</xsl:text>
401
                            <xsl:number count="html:li" level="any"/>
402
                          </xsl:attribute>
403
                        </item>
404
                      </xsl:for-each>
405
                    </xsl:if>
406
                  </xsl:for-each>
407
                </xsl:otherwise>
408
              </xsl:choose>
409
              <!-- images -->
410
              <xsl:for-each select="key('GRAPHICS',1)">
411
                <xsl:variable name="img" select="@url|@facs"/>
412
                <xsl:if test="not($img=$coverImageOutside)">
413
                  <xsl:variable name="ID">
414
                    <xsl:number level="any"/>
415
                  </xsl:variable>
416
                  <xsl:variable name="mimetype">
417
                    <xsl:choose>
418
                      <xsl:when test="@mimeType != ''">
419
                        <xsl:value-of select="@mimeType"/>
420
                      </xsl:when>
421
                      <xsl:when test="contains($img,'.gif')">image/gif</xsl:when>
422
                      <xsl:when test="contains($img,'.png')">image/png</xsl:when>
423
                      <xsl:when test="contains($img,'.mpeg')">video/mpeg4</xsl:when>
424
                      <xsl:when test="contains($img,'.mp4')">video/mpeg4</xsl:when>
425
                      <xsl:when test="contains($img,'.m4v')">video/mpeg4</xsl:when>
426
                      <xsl:otherwise>image/jpeg</xsl:otherwise>
427
                    </xsl:choose>
428
                  </xsl:variable>
429
                  <item href="{$img}" id="image-{$ID}" media-type="{$mimetype}"/>
430
                </xsl:if>
431
              </xsl:for-each>
432
              <!-- page images -->
433
              <xsl:for-each select="key('PBGRAPHICS',1)">
434
                <xsl:variable name="img" select="@facs"/>
435
                <xsl:variable name="ID">
436
                  <xsl:number level="any"/>
437
                </xsl:variable>
438
                <xsl:variable name="mimetype">
439
                  <xsl:choose>
440
                    <xsl:when test="@mimeType != ''">
441
                      <xsl:value-of select="@mimeType"/>
442
                    </xsl:when>
443
                    <xsl:when test="contains($img,'.gif')">image/gif</xsl:when>
444
                    <xsl:when test="contains($img,'.png')">image/png</xsl:when>
445
                    <xsl:otherwise>image/jpeg</xsl:otherwise>
446
                  </xsl:choose>
447
                </xsl:variable>
448
                <item href="{$img}" id="pbimage-{$ID}" media-type="{$mimetype}"/>
449
              </xsl:for-each>
450
              <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
451
              <xsl:call-template name="epubManifestHook"/>
452
            </manifest>
453
            <spine toc="ncx">
454
              <itemref idref="titlepage" linear="yes"/>
455
              <xsl:if test="$filePerPage='true'">
456
                <itemref idref="titlepageverso" linear="yes"/>
457
              </xsl:if>
458
              <xsl:for-each select="tei:text/tei:front/tei:titlePage">
459
                <xsl:variable name="N" select="position()"/>
460
                <itemref idref="titlepage{$N}" linear="yes"/>
461
              </xsl:for-each>
462
              <itemref idref="start" linear="yes"/>
463
              <xsl:choose>
464
                <xsl:when test="$filePerPage='true'">
465
                  <xsl:for-each select="key('PB',1)">
466
                    <xsl:if test="@facs">
467
                      <itemref>
468
                        <xsl:attribute name="idref">
469
                          <xsl:text>pagefacs</xsl:text>
470
                          <xsl:number level="any"/>
471
                        </xsl:attribute>
472
                        <xsl:attribute name="linear">yes</xsl:attribute>
473
                      </itemref>
474
                    </xsl:if>
475
                    <itemref>
476
                      <xsl:attribute name="idref">
477
                        <xsl:text>page</xsl:text>
478
                        <xsl:number level="any"/>
479
                      </xsl:attribute>
480
                      <xsl:attribute name="linear">yes</xsl:attribute>
481
                    </itemref>
482
                  </xsl:for-each>
483
                </xsl:when>
484
                <xsl:otherwise>
485
                  <xsl:for-each select="$TOC/html:TOC/html:ul/html:li">
486
                    <xsl:choose>
487
                      <xsl:when test="not(html:a)"/>
488
                      <xsl:when test="starts-with(html:a/@href,'#')"/>
489
                      <xsl:otherwise>
490
                        <itemref>
491
                          <xsl:attribute name="idref">
492
                            <xsl:text>section</xsl:text>
493
                            <xsl:number count="html:li" level="any"/>
494
                          </xsl:attribute>
495
                          <xsl:attribute name="linear">yes</xsl:attribute>
496
                        </itemref>
497
                      </xsl:otherwise>
498
                    </xsl:choose>
499
                    <xsl:if test="html:ul">
500
                      <xsl:for-each select="html:ul//html:li[html:a and not(contains(html:a/@href,'#'))]">
501
                        <itemref>
502
                          <xsl:attribute name="idref">
503
                            <xsl:text>section</xsl:text>
504
                            <xsl:number count="html:li" level="any"/>
505
                          </xsl:attribute>
506
                          <xsl:attribute name="linear">yes</xsl:attribute>
507
                        </itemref>
508
                      </xsl:for-each>
509
                    </xsl:if>
510
                  </xsl:for-each>
511
                </xsl:otherwise>
512
              </xsl:choose>
513
              <itemref idref="titlepageback">
514
                <xsl:attribute name="linear">
515
                  <xsl:choose>
516
                    <xsl:when test="$filePerPage='true'">yes</xsl:when>
517
                    <xsl:otherwise>no</xsl:otherwise>
518
                  </xsl:choose>
519
                </xsl:attribute>
520
              </itemref>
521
              <xsl:call-template name="epubSpineHook"/>
522
            </spine>
523
            <guide>
524
              <reference type="text" href="titlepage.xhtml" title="Cover"/>
525
              <reference type="text" title="Start" href="index.xhtml"/>
526
              <xsl:choose>
527
                <xsl:when test="$filePerPage='true'">
528
		</xsl:when>
529
                <xsl:otherwise>
530
                  <xsl:for-each select="$TOC/html:TOC/html:ul/html:li">
531
                    <xsl:if test="html:a">
532
                      <reference type="text" href="{html:a[1]/@href}">
533
                        <xsl:attribute name="title">
534
                          <xsl:value-of select="normalize-space(html:a[1])"/>
535
                        </xsl:attribute>
536
                      </reference>
537
                    </xsl:if>
538
                    <xsl:if test="contains(parent::html:ul/@class,'group')">
539
                      <xsl:for-each select="html:ul//html:li">
540
                        <xsl:choose>
541
                          <xsl:when test="not(html:a)"/>
542
                          <xsl:when test="contains(html:a/@href,'#')"/>
543
                          <xsl:otherwise>
544
                            <reference type="text" href="{html:a/@href}">
545
                              <xsl:attribute name="title">
546
                                <xsl:value-of select="normalize-space(html:a[1])"/>
547
                              </xsl:attribute>
548
                            </reference>
549
                          </xsl:otherwise>
550
                        </xsl:choose>
551
                      </xsl:for-each>
552
                    </xsl:if>
553
                  </xsl:for-each>
554
                </xsl:otherwise>
555
              </xsl:choose>
556
              <reference href="titlepageback.xhtml" type="text" title="About this book"/>
557
            </guide>
558
          </package>
559
        </xsl:result-document>
560
        <xsl:if test="$verbose='true'">
561
          <xsl:message>write file OPS/titlepage.xhtml</xsl:message>
562
        </xsl:if>
563
        <xsl:result-document href="{concat($directory,'/OPS/titlepage.xhtml')}" method="xml">
564
          <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
565
            <head>
566
              <xsl:call-template name="metaHTML">
567
                <xsl:with-param name="title">Title page</xsl:with-param>
568
              </xsl:call-template>
569
              <meta name="calibre:cover" content="true"/>
570
              <title>Title page</title>
571
              <style type="text/css" title="override_css">
572
		@page {padding: 0pt; margin:0pt}
573
		body { text-align: center; padding:0pt; margin: 0pt; }
574
	      </style>
575
            </head>
576
            <body>
577
              <xsl:choose>
578
                <xsl:when test="$coverImageInside=''">
579
                  <div>
580
                    <xsl:attribute name="style">
581
		      font-family: serif; 
582
		      height:860;          
583
		      font-size:30pt; 
584
		      font-weight: bold;
585
		      padding-top: 15pt;
586
		      margin: 12pt;
587
		      border: solid red 1pt; 
588
		      text-align:center;
589
		    </xsl:attribute>
590
                    <xsl:call-template name="generateTitle"/>
591
                  </div>
592
                </xsl:when>
593
                <xsl:otherwise>
594
                  <div>
595
                    <img width="1200" height="1700" alt="cover picture" src="{$coverImageInside}"/>
596
                  </div>
597
                </xsl:otherwise>
598
              </xsl:choose>
599
            </body>
600
          </html>
601
        </xsl:result-document>
602
        <xsl:for-each select="tei:text/tei:front/tei:titlePage">
603
          <xsl:variable name="N" select="position()"/>
604
          <xsl:if test="$verbose='true'">
605
            <xsl:message>write file OPS/titlepage<xsl:value-of select="$N"/>.xhtml</xsl:message>
606
          </xsl:if>
607
          <xsl:result-document href="{concat($directory,'/OPS/titlepage',$N,'.xhtml')}" method="xml">
608
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
609
              <head>
610
                <xsl:call-template name="metaHTML">
611
                  <xsl:with-param name="title">Title page</xsl:with-param>
612
                </xsl:call-template>
613
                <xsl:call-template name="linkCSS">
614
		  <xsl:with-param
615
		      name="file">stylesheet.css</xsl:with-param>
616
		</xsl:call-template>
617
                <title>Title page</title>
618
              </head>
619
              <body>
620
                <div class="titlePage">
621
                  <xsl:apply-templates/>
622
                </div>
623
              </body>
624
            </html>
625
          </xsl:result-document>
626
        </xsl:for-each>
627
        <xsl:if test="$filePerPage='true'">
628
          <xsl:if test="$verbose='true'">
629
            <xsl:message>write file OPS/titlepageverso.xhtml</xsl:message>
630
          </xsl:if>
631
          <xsl:result-document href="{concat($directory,'/OPS/titlepageverso.xhtml')}" method="xml">
632
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
633
              <head>
634
                <xsl:call-template name="metaHTML">
635
                  <xsl:with-param name="title">title page verso</xsl:with-param>
636
                </xsl:call-template>
637
                <title>title page verso</title>
638
              </head>
639
              <body>
640
                <p/>
641
              </body>
642
            </html>
643
          </xsl:result-document>
644
        </xsl:if>
645
        <xsl:if test="$verbose='true'">
646
          <xsl:message>write file OPS/titlepageback.xhtml</xsl:message>
647
        </xsl:if>
648
        <xsl:result-document href="{concat($directory,'/OPS/titlepageback.xhtml')}" method="xml">
649
          <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
650
            <head>
651
              <xsl:call-template name="metaHTML">
652
                <xsl:with-param name="title">About this book</xsl:with-param>
653
              </xsl:call-template>
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.xhtml"/>
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}.xhtml"/>
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.xhtml"/>
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.xhtml"/>
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="$filePerPage='true'">
746
          <xsl:if test="$verbose='true'">
747
            <xsl:message>write file META-INF/com.apple.ibooks.display-options.xml</xsl:message>
748
          </xsl:if>
749
          <xsl:result-document href="{concat($directory,'/META-INF/com.apple.ibooks.display-options.xml')}">
750
            <display_options xmlns="">
751
              <platform name="*">
752
                <option name="fixed-layout">true</option>
753
              </platform>
754
            </display_options>
755
          </xsl:result-document>
756
        </xsl:if>
757
        <xsl:if test="$debug='true'">
758
          <xsl:message>write file OPS/toc.html</xsl:message>
759
        </xsl:if>
760
        <xsl:result-document href="{concat($directory,'/OPS/toc.xhtml')}" method="xml" doctype-system="">
761
          <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
762
            <head>
763
              <title>
764
                <xsl:call-template name="generateSimpleTitle"/>
765
              </title>
766
                <xsl:call-template name="linkCSS">
767
		  <xsl:with-param
768
		      name="file">stylesheet.css</xsl:with-param>
769
		</xsl:call-template>
770
            </head>
771
            <body>
772
              <section class="TableOfContents">
773
                <header>
774
                  <h1>Contents</h1>
775
                </header>
776
                <nav xmlns:epub="http://www.idpf.org/2007/ops" epub:type="toc" id="toc">
777
                  <ol>
778
                    <xsl:for-each select="$TOC/html:TOC/html:ul/html:li">
779
                      <xsl:choose>
780
                        <xsl:when test="not(html:a)"/>
781
                        <xsl:when test="starts-with(html:a/@href,'#')"/>
782
                        <xsl:when test="contains(@class,'headless')"/>
783
                        <xsl:otherwise>
784
                          <li>
785
                            <a href="{html:a/@href}">
786
                              <xsl:value-of select="html:span[@class='headingNumber']"/>
787
                              <xsl:value-of select="normalize-space(html:a[1])"/>
788
                            </a>
789
                          </li>
790
                        </xsl:otherwise>
791
                      </xsl:choose>
792
                    </xsl:for-each>
793
                    <li>
794
                      <a href="titlepageback.xhtml">[About this book]</a>
795
                    </li>
796
                  </ol>
797
                </nav>
798
                <nav xmlns:epub="http://www.idpf.org/2007/ops" epub:type="landmarks" id="guide">
799
                  <h2>Guide</h2>
800
                  <ol>
801
                    <li>
802
                      <a epub:type="titlepage" href="titlepage.xhtml">[Title page]</a>
803
                    </li>
804
                    <li>
805
                      <a epub:type="bodymatter" href="index.xhtml">[The book]</a>
806
                    </li>
807
                    <li>
808
                      <a epub:type="colophon" href="titlepageback.xhtml">[About this book]</a>
809
                    </li>
810
                  </ol>
811
                </nav>
812
              </section>
813
            </body>
814
          </html>
815
        </xsl:result-document>
816

    
817
      </xsl:for-each>
818
    </xsl:for-each>
819
  </xsl:template>
820

    
821
  <xsl:template name="opfmetadata">
822
    <xsl:param name="author"/>
823
    <xsl:param name="printAuthor"/>
824
    <xsl:param name="coverImageOutside"/>
825
    <metadata xmlns="http://www.idpf.org/2007/opf"
826
	      xmlns:dc="http://purl.org/dc/elements/1.1/"
827
	      xmlns:dcterms="http://purl.org/dc/terms/" 
828
	      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
829
	      xmlns:opf="http://www.idpf.org/2007/opf">
830
      <dc:title id="title">
831
	<xsl:call-template name="generateSimpleTitle"/>
832
      </dc:title>
833
      <meta refines="#title" property="title-type">main</meta>
834
      <dc:creator id="creator">
835
	<xsl:value-of select="$printAuthor"/>
836
      </dc:creator>
837
      <meta refines="#creator" property="file-as">
838
	<xsl:value-of select="$author"/>
839
      </meta>
840
      <meta refines="#creator" property="role" scheme="marc:relators">aut</meta>
841
      <dc:language>
842
	<xsl:call-template name="generateLanguage"/>
843
      </dc:language>
844
      <xsl:call-template name="generateSubject"/>
845
      <dc:identifier id="pub-id">
846
	<xsl:call-template name="generateID"/>
847
      </dc:identifier>
848
      <meta refines="#pub-id" property="identifier-type" scheme="onix:codelist5">15</meta>
849
      <dc:description>
850
	<xsl:call-template name="generateSimpleTitle"/>
851
	<xsl:text> / </xsl:text>
852
	<xsl:value-of select="$author"/>
853
      </dc:description>
854
      <dc:publisher>
855
	<xsl:call-template name="generatePublisher"/>
856
      </dc:publisher>
857
      <xsl:for-each select="tei:teiHeader/tei:profileDesc/tei:creation/tei:date[@notAfter]">
858
	<dc:date id="creation">
859
	  <xsl:value-of select="@notAfter"/>
860
	</dc:date>
861
      </xsl:for-each>
862
      <xsl:for-each select="tei:teiHeader/tei:fileDesc/tei:sourceDesc//tei:date[@when][1]">
863
	<dc:date id="original-publication">
864
	  <xsl:value-of select="@when"/>
865
	</dc:date>
866
      </xsl:for-each>
867
      <dc:date id="epub-publication">
868
	<xsl:call-template name="generateDate"/>
869
      </dc:date>
870
      <dc:rights>
871
	<xsl:call-template name="generateLicence"/>
872
      </dc:rights>
873
      <xsl:if test="not($coverImageOutside='')">
874
	<meta name="cover" content="cover-image"/>
875
      </xsl:if>
876
      <meta property="dcterms:modified">
877
	<xsl:call-template name="generateRevDate"/>
878
      </meta>
879
    </metadata>
880
  </xsl:template>
881

    
882
  <xsl:template name="epubSpineHook"/>
883
  <xsl:template name="epubManifestHook"/>
884
  <xsl:template name="processTEIHook"/>
885
</xsl:stylesheet>