lrf.xsl 8.0 KB

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