This repository has been archived by the owner on Nov 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_content.opf.xsl
executable file
·197 lines (171 loc) · 6.83 KB
/
make_content.opf.xsl
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
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Fabrication content.opf à partir de fichiers Pages -->
<!-- Pour intégration dans archive ePub -->
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sfa="http://developer.apple.com/namespaces/sfa"
xmlns:sf="http://developer.apple.com/namespaces/sf"
xmlns:sl="http://developer.apple.com/namespaces/sl"
xmlns="http://www.idpf.org/2007/opf"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl"
exclude-result-prefixes="xsi sfa sf sl">
<xsl:template name="make_content.opf" match="/">
<exsl:document href="{$maindir}/content.opf" version="1.0"
indent="yes">
<package version="2.0" unique-identifier="ID">
<xsl:apply-templates select="//sf:metadata"/>
<xsl:call-template name="manifest"/>
<xsl:call-template name="spine"/>
</package>
</exsl:document>
</xsl:template>
<xsl:template match="sf:metadata">
<xsl:variable name="pubinfo" select="preceding-sibling::sl:publication-info"/>
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:opf="http://www.idpf.org/2007/opf">
<xsl:choose>
<xsl:when test="$title='undefined'">
<dc:title><xsl:value-of select="//sf:metadata/sf:title/sf:string/@sfa:string"/></dc:title>
</xsl:when>
<xsl:otherwise>
<dc:title><xsl:value-of select="$title"/></dc:title>
</xsl:otherwise>
</xsl:choose>
<dc:language xsi:type="dcterms:RFC3066">
<xsl:value-of select="$pubinfo/sl:language/sl:string/@sfa:string"/>
</dc:language>
<dc:identifier id="ID" opf:scheme="ISBN">
<xsl:value-of select="$identifier"/>
</dc:identifier>
<xsl:for-each select="sf:keywords/sf:string">
<dc:subject><xsl:value-of select="@sfa:string"/></dc:subject>
</xsl:for-each>
<dc:description><xsl:value-of select="sf:comment/sf:string/@sfa:string"/></dc:description>
<!-- <dc:relation>http://publie.net</dc:relation> -->
<xsl:choose>
<xsl:when test="$author='undefined'">
<xsl:for-each select="sf:authors/sf:string">
<dc:creator opf:role="aut"><xsl:value-of select="@sfa:string"/></dc:creator>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<dc:creator opf:role="aut"><xsl:value-of select="$author"/></dc:creator>
</xsl:otherwise>
</xsl:choose>
<dc:publisher><xsl:value-of select="$publisher"/></dc:publisher>
<dc:date xsi:type="dcterms:W3CDTF"><xsl:value-of select="substring($pubinfo/sl:SLLastModifiedDateProperty/sl:date/@sf:val,1,10)"/></dc:date>
<dc:rights><xsl:value-of select="sf:copyright/sf:string/@sfa:string"/></dc:rights>
</metadata>
</xsl:template>
<xsl:template name="manifest">
<manifest>
<item id="cover" media-type="application/xhtml+xml" href="cover.html"/>
<item id="toc" media-type="application/xhtml+xml" href="toc.html"/>
<xsl:choose>
<xsl:when test="not(//sf:p[child::sf:toc-bookmark])">
<item id="main" media-type="application/xhtml+xml" href="{$basename}.html"/>
</xsl:when>
<xsl:otherwise>
<item id="intro" media-type="application/xhtml+xml" href="intro.html"/>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="//sf:p[child::sf:toc-bookmark]">
<item id="{sf:toc-bookmark/@sf:name}" media-type="application/xhtml+xml" href="{sf:toc-bookmark/@sf:name}.html"/>
</xsl:for-each>
<item id="footnotes" media-type="application/xhtml+xml" href="footnotes.html"/>
<item id="coverfile" media-type="image/png" href="cover.png"/>
<item id="css" media-type="text/css" href="{$basename}.css"/>
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
<xsl:for-each select="//sf:attachment">
<xsl:variable name="imgSrc" select="sf:media/sf:content//sf:data/@sf:path"/>
<xsl:variable name="imgMedia">
<xsl:choose>
<xsl:when test="contains($imgSrc,'.jpg') or contains($imgSrc,'.JPG') or contains($imgSrc,'.jpeg')">
<xsl:text>image/jpeg</xsl:text>
</xsl:when>
<xsl:when test="contains($imgSrc,'.gif')">
<xsl:text>image/gif</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>image/png</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$imgSrc != ''">
<xsl:choose>
<xsl:when test="contains($imgSrc,'.pict') or contains(@src,'.pdf')">
<item id="{@sfa:ID}" media-type="{$imgMedia}" href="{$imgSrc}.png"/>
</xsl:when>
<xsl:otherwise>
<item id="{@sfa:ID}" media-type="{$imgMedia}" href="{$imgSrc}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="//sf:image-media">
<xsl:variable name="imgSrc" select="sf:filtered-image/sf:unfiltered/sf:data/@sf:path"/>
<xsl:variable name="imgMedia">
<xsl:choose>
<xsl:when test="contains($imgSrc,'.jpg') or contains($imgSrc,'.JPG') or contains($imgSrc,'.jpeg')">
<xsl:text>image/jpeg</xsl:text>
</xsl:when>
<xsl:when test="contains($imgSrc,'.gif')">
<xsl:text>image/gif</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>image/png</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$imgSrc != ''">
<xsl:choose>
<xsl:when test="contains($imgSrc,'.pict') or contains(@src,'.pdf')">
<item id="img{position()}" media-type="{$imgMedia}" href="{$imgSrc}.png"/>
</xsl:when>
<xsl:otherwise>
<item id="img{position()}" media-type="{$imgMedia}" href="{$imgSrc}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</manifest>
</xsl:template>
<xsl:template name="spine">
<spine toc="ncx">
<itemref idref="cover"/>
<itemref idref="toc"/>
<xsl:choose>
<xsl:when test="not(//sf:p[child::sf:toc-bookmark])">
<itemref idref="main"/>
</xsl:when>
<xsl:otherwise>
<itemref idref="intro"/>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="//sf:p[child::sf:toc-bookmark]">
<itemref idref="{sf:toc-bookmark/@sf:name}"/>
</xsl:for-each>
<itemref idref="footnotes"/>
</spine>
<guide>
<reference type="cover" title="Cover" href="cover.html" />
<reference type="toc" title="Table of Contents" href="toc.html" />
<xsl:choose>
<xsl:when test="not(//sf:p[child::sf:toc-bookmark])">
<reference type="text" href="{$basename}.html"/>
</xsl:when>
<xsl:otherwise>
<reference type="text" href="intro.html"/>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="//sf:p[child::sf:toc-bookmark]">
<reference type="text" href="{sf:toc-bookmark/@sf:name}.html"/>
</xsl:for-each>
<reference type="glossary" title="Footnotes" href="footnotes.html" />
</guide>
</xsl:template>
</xsl:transform>