| 1 |
<?xml version="1.0"?> |
| 2 |
<xsl:stylesheet |
| 3 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 4 |
xmlns:c="calibre" |
| 5 |
xmlns:dc="http://purl.org/dc/elements/1.1/" |
| 6 |
xmlns:opf="http://www.idpf.org/2007/opf" |
| 7 |
xmlns:calibre="http://calibre.kovidgoyal.net/2009/metadata" |
| 8 |
extension-element-prefixes="c" |
| 9 |
xsl:version = "1.1" |
| 10 |
> |
| 11 |
<xsl:output method="xml" indent="yes"/> |
| 12 |
|
| 13 |
<xsl:template match="/"> |
| 14 |
<package xmlns="http://www.idpf.org/2007/opf" version="2.0"> |
| 15 |
<metadata> |
| 16 |
<xsl:call-template name="make-metadata"/> |
| 17 |
</metadata> |
| 18 |
<manifest> |
| 19 |
<xsl:call-template name="make-manifest"/> |
| 20 |
</manifest> |
| 21 |
<spine toc="ncx"> |
| 22 |
<xsl:call-template name="make-spine"/> |
| 23 |
</spine> |
| 24 |
</package> |
| 25 |
<xsl:call-template name="make-ncx"/> |
| 26 |
<xsl:call-template name="make-css"/> |
| 27 |
<xsl:for-each select="//Page"> |
| 28 |
<xsl:call-template name="make-page"/> |
| 29 |
</xsl:for-each> |
| 30 |
</xsl:template> |
| 31 |
|
| 32 |
<xsl:template name="make-css"> |
| 33 |
<xsl:for-each select="//TextStyle|//BlockStyle"> |
| 34 |
<c:styles/> |
| 35 |
</xsl:for-each> |
| 36 |
</xsl:template> |
| 37 |
|
| 38 |
<xsl:template name="make-page"> |
| 39 |
<xsl:variable name="pid" select="@objid"/> |
| 40 |
<xsl:document href="{$pid}.xhtml" method="xml" indent="yes"> |
| 41 |
<html> |
| 42 |
<head> |
| 43 |
<title><xsl:value-of select="//Title"/></title> |
| 44 |
<link rel="stylesheet" type="text/css" href="styles.css"/> |
| 45 |
</head> |
| 46 |
<body class="body"> |
| 47 |
<xsl:apply-templates /> |
| 48 |
</body> |
| 49 |
</html> |
| 50 |
</xsl:document> |
| 51 |
</xsl:template> |
| 52 |
|
| 53 |
<xsl:template match="RuledLine"> |
| 54 |
<c:ruled-line/> |
| 55 |
</xsl:template> |
| 56 |
|
| 57 |
<xsl:template match="TextBlock"> |
| 58 |
<c:text-block/> |
| 59 |
</xsl:template> |
| 60 |
|
| 61 |
<xsl:template match="ImageBlock"> |
| 62 |
<c:image-block/> |
| 63 |
</xsl:template> |
| 64 |
|
| 65 |
<xsl:template match="Canvas"> |
| 66 |
<c:canvas/> |
| 67 |
</xsl:template> |
| 68 |
|
| 69 |
<xsl:template name="make-metadata"> |
| 70 |
<xsl:for-each select='//BookInformation/Info/BookInfo'> |
| 71 |
<xsl:apply-templates select="Title"/> |
| 72 |
<xsl:apply-templates select="Author"/> |
| 73 |
<xsl:apply-templates select="Publisher"/> |
| 74 |
<xsl:apply-templates select="Category|Classification"/> |
| 75 |
</xsl:for-each> |
| 76 |
<xsl:for-each select='//BookInformation/Info/DocInfo'> |
| 77 |
<xsl:apply-templates select="Language"/> |
| 78 |
<xsl:apply-templates select="Producer"/> |
| 79 |
</xsl:for-each> |
| 80 |
</xsl:template> |
| 81 |
|
| 82 |
<xsl:template match="Title"> |
| 83 |
<xsl:element name="dc:title"> |
| 84 |
<xsl:if test="@reading and @reading != ''"> |
| 85 |
<xsl:attribute name="opf:file-as"><xsl:value-of select="@reading"/></xsl:attribute> |
| 86 |
</xsl:if> |
| 87 |
<xsl:value-of select="."/> |
| 88 |
</xsl:element> |
| 89 |
</xsl:template> |
| 90 |
|
| 91 |
<xsl:template match="Author"> |
| 92 |
<xsl:element name="dc:creator"> |
| 93 |
<xsl:attribute name="opf:role">aut</xsl:attribute> |
| 94 |
<xsl:if test="@reading and @reading != ''"> |
| 95 |
<xsl:attribute name="opf:file-as"><xsl:value-of select="@reading"/></xsl:attribute> |
| 96 |
</xsl:if> |
| 97 |
<xsl:value-of select="."/> |
| 98 |
</xsl:element> |
| 99 |
</xsl:template> |
| 100 |
|
| 101 |
<xsl:template match="Publisher"> |
| 102 |
<xsl:element name="dc:publisher"> |
| 103 |
<xsl:if test="@reading and @reading != ''"> |
| 104 |
<xsl:attribute name="opf:file-as"><xsl:value-of select="@reading"/></xsl:attribute> |
| 105 |
</xsl:if> |
| 106 |
<xsl:value-of select="."/> |
| 107 |
</xsl:element> |
| 108 |
</xsl:template> |
| 109 |
|
| 110 |
<xsl:template match="Producer"> |
| 111 |
<xsl:element name="dc:creator"> |
| 112 |
<xsl:attribute name="opf:role">bkp</xsl:attribute> |
| 113 |
<xsl:if test="@reading and @reading != ''"> |
| 114 |
<xsl:attribute name="opf:file-as"><xsl:value-of select="@reading"/></xsl:attribute> |
| 115 |
</xsl:if> |
| 116 |
<xsl:value-of select="."/> |
| 117 |
</xsl:element> |
| 118 |
</xsl:template> |
| 119 |
|
| 120 |
<xsl:template match="Language"> |
| 121 |
<xsl:element name="dc:language"> |
| 122 |
<xsl:value-of select="."/> |
| 123 |
</xsl:element> |
| 124 |
</xsl:template> |
| 125 |
|
| 126 |
<xsl:template match="Category|Classification"> |
| 127 |
<xsl:if test=".!=''"> |
| 128 |
<xsl:element name="dc:subject"> |
| 129 |
<xsl:value-of select="."/> |
| 130 |
</xsl:element> |
| 131 |
</xsl:if> |
| 132 |
</xsl:template> |
| 133 |
|
| 134 |
<xsl:template name="make-manifest"> |
| 135 |
<xsl:for-each select='//Page'> |
| 136 |
<xsl:element name="opf:item"> |
| 137 |
<xsl:attribute name="id"><xsl:value-of select="@objid"/></xsl:attribute> |
| 138 |
<xsl:attribute name="media-type"><xsl:text>application/xhtml+xml</xsl:text></xsl:attribute> |
| 139 |
<xsl:attribute name="href"><xsl:value-of select="@objid"/><xsl:text>.xhtml</xsl:text></xsl:attribute> |
| 140 |
</xsl:element> |
| 141 |
</xsl:for-each> |
| 142 |
<xsl:for-each select="//ImageStream"> |
| 143 |
<xsl:element name="opf:item"> |
| 144 |
<xsl:attribute name="id"><xsl:value-of select="@objid"/></xsl:attribute> |
| 145 |
<xsl:attribute name="media-type"><c:media-type/></xsl:attribute> |
| 146 |
<xsl:attribute name="href"><xsl:value-of select="@file"/></xsl:attribute> |
| 147 |
</xsl:element> |
| 148 |
</xsl:for-each> |
| 149 |
<xsl:for-each select="//RegistFont"> |
| 150 |
<xsl:element name="opf:item"> |
| 151 |
<xsl:attribute name="id"><xsl:value-of select="@objid"/></xsl:attribute> |
| 152 |
<xsl:attribute name="media-type"><c:media-type/></xsl:attribute> |
| 153 |
<xsl:attribute name="href"><xsl:value-of select="@file"/></xsl:attribute> |
| 154 |
</xsl:element> |
| 155 |
</xsl:for-each> |
| 156 |
<opf:item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" /> |
| 157 |
<opf:item id="styles" href="styles.css" media-type="text/css" /> |
| 158 |
|
| 159 |
</xsl:template> |
| 160 |
|
| 161 |
<xsl:template name="make-spine"> |
| 162 |
<xsl:for-each select='//Page'> |
| 163 |
<xsl:element name="opf:itemref"> |
| 164 |
<xsl:attribute name="idref"><xsl:value-of select="@objid"/></xsl:attribute> |
| 165 |
</xsl:element> |
| 166 |
</xsl:for-each> |
| 167 |
</xsl:template> |
| 168 |
|
| 169 |
<xsl:template match="*"> |
| 170 |
<xsl:message> |
| 171 |
<xsl:text>no match for element: "</xsl:text> |
| 172 |
<xsl:value-of select="name(.)"/> |
| 173 |
<xsl:text>" 
</xsl:text> |
| 174 |
</xsl:message> |
| 175 |
<xsl:apply-templates/> |
| 176 |
</xsl:template> |
| 177 |
|
| 178 |
|
| 179 |
<xsl:template name="make-ncx"> |
| 180 |
<xsl:document href="toc.ncx" method="xml" indent="yes"> |
| 181 |
<ncx version="2005-1" |
| 182 |
xmlns="http://www.daisy.org/z3986/2005/ncx/" |
| 183 |
xmlns:calibre="http://calibre.kovidgoyal.net/2009/metadata" |
| 184 |
> |
| 185 |
<head> |
| 186 |
<meta name="dtb:uid" content="uid"/> |
| 187 |
<meta name="dtb:depth" content="1"/> |
| 188 |
<meta name="dtb:generator" content="calibre"/> |
| 189 |
<meta name="dtb:totalPageCount" content="0"/> |
| 190 |
<meta name="dtb:maxPageNumber" content="0"/> |
| 191 |
</head> |
| 192 |
<docTitle><text>Table of Contents</text></docTitle> |
| 193 |
<navMap> |
| 194 |
<xsl:for-each select="//TOC/TocLabel"> |
| 195 |
<xsl:element name="navPoint"> |
| 196 |
<xsl:attribute name="id"><xsl:value-of select="count(preceding-sibling::*)"/></xsl:attribute> |
| 197 |
<xsl:attribute name="playOrder"><xsl:value-of select="count(preceding-sibling::*)+1"/></xsl:attribute> |
| 198 |
<navLabel><text><xsl:value-of select="."/></text></navLabel> |
| 199 |
<xsl:element name="content"> |
| 200 |
<xsl:attribute name="src"> |
| 201 |
<xsl:value-of select="@refpage"/>.xhtml#<xsl:value-of select="@refobj"/> |
| 202 |
</xsl:attribute> |
| 203 |
</xsl:element> |
| 204 |
</xsl:element> |
| 205 |
</xsl:for-each> |
| 206 |
</navMap> |
| 207 |
</ncx> |
| 208 |
</xsl:document> |
| 209 |
</xsl:template> |
| 210 |
</xsl:stylesheet> |