Fb2_2_Html_Basics.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:xlink="http://www.w3.org/1999/xlink">
  3. <!-- author -->
  4. <xsl:template name="author">
  5. <xsl:value-of select="fb:first-name"/>
  6. <xsl:text disable-output-escaping="no">&#032;</xsl:text>
  7. <xsl:value-of select="fb:middle-name"/>&#032;
  8. <xsl:text disable-output-escaping="no">&#032;</xsl:text>
  9. <xsl:value-of select="fb:last-name"/>
  10. <xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text>
  11. </xsl:template>
  12. <!-- secuence -->
  13. <xsl:template name="sequence">
  14. <LI/>
  15. <xsl:value-of select="@name"/>
  16. <xsl:if test="@number">
  17. <xsl:text disable-output-escaping="no">,&#032;#</xsl:text>
  18. <xsl:value-of select="@number"/>
  19. </xsl:if>
  20. <xsl:if test="fb:sequence">
  21. <UL>
  22. <xsl:for-each select="fb:sequence">
  23. <xsl:call-template name="sequence"/>
  24. </xsl:for-each>
  25. </UL>
  26. </xsl:if>
  27. <!-- <xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text> -->
  28. </xsl:template>
  29. <!-- toc template: body -->
  30. <xsl:template match="fb:body" mode="toc">
  31. <xsl:choose>
  32. <xsl:when test="not(@name) or @name != 'notes'"><xsl:apply-templates mode="toc" select="fb:section"/></xsl:when>
  33. <xsl:otherwise><br/><li><a href="#TOC_notes_{generate-id()}"><xsl:value-of select="$NotesTitle"/></a></li></xsl:otherwise>
  34. </xsl:choose>
  35. </xsl:template>
  36. <!-- toc template: section -->
  37. <xsl:template match="fb:section" mode="toc">
  38. <xsl:if test="fb:title | .//fb:section[count(ancestor::fb:section) &lt; $tocdepth]/fb:title">
  39. <li>
  40. <xsl:apply-templates select="fb:title" mode="toc"/>
  41. <xsl:if test="(.//fb:section/fb:title) and (count(ancestor::fb:section) &lt; $tocdepth or $tocdepth= 4)">
  42. <UL><xsl:apply-templates select="fb:section" mode="toc"/></UL>
  43. </xsl:if>
  44. </li>
  45. </xsl:if>
  46. </xsl:template>
  47. <!-- toc template: title -->
  48. <xsl:template match="fb:title" mode="toc">
  49. <a href="#TOC_{generate-id()}">
  50. <xsl:choose>
  51. <xsl:when test="$toccut &gt; 0">
  52. <xsl:value-of select="normalize-space(fb:p[1])"/>
  53. </xsl:when>
  54. <xsl:otherwise>
  55. <xsl:for-each select="fb:title/fb:p">
  56. <xsl:if test="position()>1"><xsl:text> </xsl:text></xsl:if>
  57. <xsl:value-of select="normalize-space(.)"/>
  58. </xsl:for-each>
  59. </xsl:otherwise>
  60. </xsl:choose>
  61. </a>
  62. </xsl:template>
  63. <!-- description -->
  64. <xsl:template match="fb:description">
  65. <xsl:apply-templates/>
  66. </xsl:template>
  67. <!-- section -->
  68. <xsl:template match="fb:section">
  69. <xsl:call-template name="preexisting_id"/>
  70. <xsl:apply-templates select="fb:title"/>
  71. <div><xsl:apply-templates select="fb:*[name()!='title']"/></div>
  72. </xsl:template>
  73. <!-- title -->
  74. <xsl:template match="fb:section/fb:title|fb:poem/fb:title">
  75. <xsl:choose>
  76. <xsl:when test="ancestor::fb:body/@name = 'notes' and not(following-sibling::fb:section)">
  77. <xsl:call-template name="preexisting_id"/>
  78. <xsl:for-each select="parent::fb:section">
  79. <xsl:call-template name="preexisting_id"/>
  80. </xsl:for-each><h1 align="center"><xsl:apply-templates/></h1>
  81. </xsl:when>
  82. <xsl:otherwise>
  83. <xsl:choose>
  84. <xsl:when test="count(ancestor::node()) &lt; 9">
  85. <xsl:element name="{concat('h',count(ancestor::node())-3)}">
  86. <xsl:attribute name="align">center</xsl:attribute>
  87. <a name="TOC_{generate-id()}"></a>
  88. <xsl:call-template name="preexisting_id"/>
  89. <xsl:apply-templates/>
  90. </xsl:element>
  91. </xsl:when>
  92. <xsl:otherwise>
  93. <xsl:element name="h6">
  94. <xsl:attribute name="align">center</xsl:attribute>
  95. <xsl:call-template name="preexisting_id"/>
  96. <xsl:apply-templates/>
  97. </xsl:element>
  98. </xsl:otherwise>
  99. </xsl:choose>
  100. </xsl:otherwise>
  101. </xsl:choose>
  102. </xsl:template>
  103. <!-- body/title -->
  104. <xsl:template match="fb:body/fb:title">
  105. <h1 align="center"><xsl:apply-templates/></h1>
  106. </xsl:template>
  107. <!-- title/p and the like -->
  108. <xsl:template match="fb:title/fb:p|fb:title-info/fb:book-title">
  109. <xsl:apply-templates/><xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text>
  110. </xsl:template>
  111. <!-- subtitle -->
  112. <xsl:template match="fb:subtitle">
  113. <xsl:call-template name="preexisting_id"/>
  114. <h3 align="center">
  115. <xsl:apply-templates/>
  116. </h3>
  117. </xsl:template>
  118. <!-- p -->
  119. <xsl:template match="fb:p"><xsl:call-template name="preexisting_id"/>&#160;&#160;&#160;&#160;&#160;&#160;<xsl:apply-templates/><xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text></xsl:template>
  120. <!-- strong -->
  121. <xsl:template match="fb:strong">
  122. <b><xsl:apply-templates/></b>
  123. </xsl:template>
  124. <!-- emphasis -->
  125. <xsl:template match="fb:emphasis">
  126. <i><xsl:apply-templates/></i>
  127. </xsl:template>
  128. <!-- style -->
  129. <xsl:template match="fb:style">
  130. <span class="{@name}"><xsl:apply-templates/></span>
  131. </xsl:template>
  132. <!-- empty-line -->
  133. <xsl:template match="fb:empty-line">
  134. &#160;<xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text>
  135. </xsl:template>
  136. <!-- link -->
  137. <xsl:template match="fb:a">
  138. <xsl:element name="a">
  139. <xsl:attribute name="href"><xsl:value-of select="@xlink:href"/></xsl:attribute>
  140. <xsl:attribute name="title">
  141. <xsl:choose>
  142. <xsl:when test="starts-with(@xlink:href,'#')"><xsl:value-of select="key('note-link',substring-after(@xlink:href,'#'))/fb:p"/></xsl:when>
  143. <xsl:otherwise><xsl:value-of select="key('note-link',@xlink:href)/fb:p"/></xsl:otherwise>
  144. </xsl:choose>
  145. </xsl:attribute>
  146. <xsl:choose>
  147. <xsl:when test="(@type) = 'note'">
  148. <sup>
  149. <xsl:apply-templates/>
  150. </sup>
  151. </xsl:when>
  152. <xsl:otherwise>
  153. <xsl:apply-templates/>
  154. </xsl:otherwise>
  155. </xsl:choose>
  156. </xsl:element>
  157. </xsl:template>
  158. <!-- annotation -->
  159. <xsl:template name="annotation">
  160. <xsl:call-template name="preexisting_id"/>
  161. <h3 align="center">Annotation</h3>
  162. <xsl:apply-templates/>
  163. </xsl:template>
  164. <!-- epigraph -->
  165. <xsl:template match="fb:epigraph">
  166. <div align="right">
  167. <xsl:call-template name="preexisting_id"/>
  168. <i><xsl:apply-templates/></i>
  169. </div>
  170. <xsl:if test="name(./following-sibling::node()) = 'epigraph'"><br/></xsl:if>
  171. <br/>
  172. </xsl:template>
  173. <!-- epigraph/text-author -->
  174. <xsl:template match="fb:epigraph/fb:text-author">
  175. <b><i><xsl:apply-templates/></i></b>
  176. </xsl:template>
  177. <!-- cite -->
  178. <xsl:template match="fb:cite">
  179. <blockquote><div align="justify">
  180. <xsl:call-template name="preexisting_id"/>
  181. <xsl:apply-templates/></div>
  182. </blockquote>
  183. </xsl:template>
  184. <!-- cite/text-author -->
  185. <xsl:template match="fb:text-author">
  186. <b><xsl:apply-templates/></b><br/>
  187. </xsl:template>
  188. <!-- date -->
  189. <xsl:template match="fb:date">
  190. <xsl:choose>
  191. <xsl:when test="not(@value)">
  192. &#160;&#160;&#160;<xsl:apply-templates/>
  193. <xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text>
  194. </xsl:when>
  195. <xsl:otherwise>
  196. &#160;&#160;&#160;<xsl:value-of select="@value"/>
  197. <xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text>
  198. </xsl:otherwise>
  199. </xsl:choose>
  200. </xsl:template>
  201. <!-- poem -->
  202. <xsl:template match="fb:poem">
  203. <xsl:call-template name="preexisting_id"/>
  204. <xsl:apply-templates/>
  205. </xsl:template>
  206. <!-- stanza -->
  207. <xsl:template match="fb:stanza">
  208. &#160;<xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text>
  209. <xsl:apply-templates/>
  210. &#160;<xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text>
  211. </xsl:template>
  212. <!-- v -->
  213. <xsl:template match="fb:v">
  214. <xsl:call-template name="preexisting_id"/>
  215. <i><xsl:apply-templates/></i><xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text>
  216. </xsl:template>
  217. <!-- image - inline -->
  218. <xsl:template match="fb:p/fb:image|fb:v/fb:image|fb:td/fb:image|fb:subtitle/fb:image">
  219. <xsl:if test="$saveimages &gt; 0">
  220. <img border="0">
  221. <xsl:choose>
  222. <xsl:when test="starts-with(@xlink:href,'#')">
  223. <xsl:attribute name="src"><xsl:value-of select="substring-after(@xlink:href,'#')"/></xsl:attribute>
  224. </xsl:when>
  225. <xsl:otherwise>
  226. <xsl:attribute name="src"><xsl:value-of select="@xlink:href"/></xsl:attribute>
  227. </xsl:otherwise>
  228. </xsl:choose>
  229. </img>
  230. </xsl:if>
  231. </xsl:template>
  232. <!-- image - block -->
  233. <xsl:template match="fb:image">
  234. <xsl:if test="$saveimages &gt; 0">
  235. <div align="center">
  236. <img border="1">
  237. <xsl:choose>
  238. <xsl:when test="starts-with(@xlink:href,'#')">
  239. <xsl:attribute name="src"><xsl:value-of select="substring-after(@xlink:href,'#')"/></xsl:attribute>
  240. </xsl:when>
  241. <xsl:otherwise>
  242. <xsl:attribute name="src"><xsl:value-of select="@xlink:href"/></xsl:attribute>
  243. </xsl:otherwise>
  244. </xsl:choose>
  245. </img>
  246. </div>
  247. </xsl:if>
  248. </xsl:template>
  249. <!-- we preserve used ID's and drop unused ones -->
  250. <xsl:template name="preexisting_id">
  251. <xsl:variable name="i" select="@id"/>
  252. <xsl:if test="@id and //fb:a[@xlink:href=concat('#',$i)]"><a name="{@id}"/></xsl:if>
  253. </xsl:template>
  254. <!-- book generator -->
  255. <xsl:template name="DocGen">
  256. <xsl:for-each select="fb:body">
  257. <xsl:if test="position()!=1">
  258. <hr/>
  259. </xsl:if>
  260. <xsl:choose>
  261. <xsl:when test="@name = 'notes'"><h1 align="center"><a name="#TOC_notes_{generate-id()}"/><xsl:value-of select="$NotesTitle"/></h1></xsl:when>
  262. <xsl:when test="@name"><h1 align="center"><xsl:value-of select="@name"/></h1></xsl:when>
  263. </xsl:choose>
  264. <!-- <xsl:apply-templates /> -->
  265. <xsl:apply-templates/>
  266. </xsl:for-each>
  267. </xsl:template>
  268. <xsl:template name="CSS_Style_Screen">
  269. A { color : #0002CC }
  270. A:HOVER { color : #BF0000 }
  271. BODY {font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; text-align : justify }
  272. H1{ font-size : 160%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize; border : 1px solid Black; background-color : #E7E7E7; text-transform : capitalize; margin-left : 0px; padding-left : 0.5em; }
  273. H2{ font-size : 130%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize; background-color : #EEEEEE; border : 1px solid Gray; text-transform : capitalize; padding-left : 1em; }
  274. H3{ font-size : 110%; font-style : normal; font-weight : bold; text-align : left; background-color : #F1F1F1; border : 1px solid Silver; text-transform : capitalize; padding-left : 1.5em;}
  275. H4{ font-size : 100%; font-style : normal; font-weight : bold; text-align : left padding-left : 0.5em; text-transform : capitalize; border : 1px solid Gray; background-color : #F4F4F4; padding-left : 2em;}
  276. H5{ font-size : 100%; font-style : italic; font-weight : bold; text-align : left; text-transform : capitalize;border : 1px solid Gray; background-color : #F4F4F4; padding-left : 2.5em;}
  277. H6{ font-size : 100%; font-style : italic; font-weight : normal; text-align : left; text-transform : capitalize;border : 1px solid Gray; background-color : #F4F4F4; padding-left : 2.5em;}
  278. SMALL{ font-size : 80% }
  279. BLOCKQUOTE{ margin : 0 1em 0.2em 4em }
  280. HR{ color : Black }
  281. UL{ padding-left : 1em; margin-left: 0}
  282. .epigraph{margin-right:5em; margin-left : 25%;}
  283. DIV{font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; text-align : justify}
  284. </xsl:template>
  285. <xsl:template name="CSS_Style_Print">
  286. A { color : #0002CC }
  287. A:HOVER { color : #BF0000 }
  288. BODY {font-family : "Times New Roman", Times, serif; text-align : justify }
  289. H1{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 160%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize }
  290. H2{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 130%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize }
  291. H3{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 110%; font-style : normal; font-weight : bold; text-align : left }
  292. H4{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 100%; font-style : normal; font-weight : bold; text-align : left }
  293. H5,H6{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 100%; font-style : italic; font-weight : normal; text-align : left; text-transform : uppercase }
  294. SMALL{ font-size : 80% }
  295. BLOCKQUOTE{ margin : 0 1em 0.2em 4em }
  296. HR{ color : Black }
  297. DIV{font-family : "Times New Roman", Times, serif; text-align : justify}
  298. </xsl:template>
  299. </xsl:stylesheet>