xep.xsl 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  4. xmlns:rx="http://www.renderx.com/XSL/Extensions"
  5. version='1.0'>
  6. <!-- ********************************************************************
  7. $Id: xep.xsl 9293 2012-04-19 18:42:11Z bobstayton $
  8. ********************************************************************
  9. (c) Stephane Bline Peregrine Systems 2001
  10. Implementation of xep extensions:
  11. * Pdf bookmarks (based on the XEP 2.5 implementation)
  12. * Document information (XEP 2.5 meta information extensions)
  13. ******************************************************************** -->
  14. <!-- FIXME: Norm, I changed things so that the top-level element (book or set)
  15. does not appear in the TOC. Is this the right thing? -->
  16. <xsl:template name="xep-document-information">
  17. <rx:meta-info>
  18. <xsl:variable name="authors"
  19. select="(//author|//editor|//corpauthor|//authorgroup)[1]"/>
  20. <xsl:if test="$authors">
  21. <xsl:variable name="author">
  22. <xsl:choose>
  23. <xsl:when test="$authors[self::authorgroup]">
  24. <xsl:call-template name="person.name.list">
  25. <xsl:with-param name="person.list"
  26. select="$authors/*[self::author|self::corpauthor|
  27. self::othercredit|self::editor]"/>
  28. </xsl:call-template>
  29. </xsl:when>
  30. <xsl:when test="$authors[self::corpauthor]">
  31. <xsl:value-of select="$authors"/>
  32. </xsl:when>
  33. <xsl:when test="$authors[orgname]">
  34. <xsl:value-of select="$authors/orgname"/>
  35. </xsl:when>
  36. <xsl:otherwise>
  37. <xsl:call-template name="person.name">
  38. <xsl:with-param name="node" select="$authors"/>
  39. </xsl:call-template>
  40. </xsl:otherwise>
  41. </xsl:choose>
  42. </xsl:variable>
  43. <xsl:element name="rx:meta-field">
  44. <xsl:attribute name="name">author</xsl:attribute>
  45. <xsl:attribute name="value">
  46. <xsl:value-of select="normalize-space($author)"/>
  47. </xsl:attribute>
  48. </xsl:element>
  49. </xsl:if>
  50. <xsl:variable name="title">
  51. <xsl:apply-templates select="/*[1]" mode="label.markup"/>
  52. <xsl:apply-templates select="/*[1]" mode="title.markup"/>
  53. </xsl:variable>
  54. <xsl:element name="rx:meta-field">
  55. <xsl:attribute name="name">creator</xsl:attribute>
  56. <xsl:attribute name="value">
  57. <xsl:text>DocBook </xsl:text>
  58. <xsl:value-of select="$DistroTitle"/>
  59. <xsl:text> V</xsl:text>
  60. <xsl:value-of select="$VERSION"/>
  61. </xsl:attribute>
  62. </xsl:element>
  63. <xsl:element name="rx:meta-field">
  64. <xsl:attribute name="name">title</xsl:attribute>
  65. <xsl:attribute name="value">
  66. <xsl:value-of select="normalize-space($title)"/>
  67. </xsl:attribute>
  68. </xsl:element>
  69. <xsl:if test="//keyword">
  70. <xsl:element name="rx:meta-field">
  71. <xsl:attribute name="name">keywords</xsl:attribute>
  72. <xsl:attribute name="value">
  73. <xsl:for-each select="//keyword">
  74. <xsl:value-of select="normalize-space(.)"/>
  75. <xsl:if test="position() != last()">
  76. <xsl:text>, </xsl:text>
  77. </xsl:if>
  78. </xsl:for-each>
  79. </xsl:attribute>
  80. </xsl:element>
  81. </xsl:if>
  82. <xsl:if test="//subjectterm">
  83. <xsl:element name="rx:meta-field">
  84. <xsl:attribute name="name">subject</xsl:attribute>
  85. <xsl:attribute name="value">
  86. <xsl:for-each select="//subjectterm">
  87. <xsl:value-of select="normalize-space(.)"/>
  88. <xsl:if test="position() != last()">
  89. <xsl:text>, </xsl:text>
  90. </xsl:if>
  91. </xsl:for-each>
  92. </xsl:attribute>
  93. </xsl:element>
  94. </xsl:if>
  95. </rx:meta-info>
  96. </xsl:template>
  97. <!-- ********************************************************************
  98. Pdf bookmarks
  99. ******************************************************************** -->
  100. <xsl:template match="*" mode="xep.outline">
  101. <xsl:apply-templates select="*" mode="xep.outline"/>
  102. </xsl:template>
  103. <xsl:template match="set|book|part|reference|preface|chapter|appendix|article
  104. |glossary|bibliography|index|setindex|topic
  105. |refentry|refsynopsisdiv
  106. |refsect1|refsect2|refsect3|refsection
  107. |sect1|sect2|sect3|sect4|sect5|section"
  108. mode="xep.outline">
  109. <xsl:variable name="id">
  110. <xsl:call-template name="object.id"/>
  111. </xsl:variable>
  112. <xsl:variable name="bookmark-label">
  113. <xsl:apply-templates select="." mode="object.title.markup"/>
  114. </xsl:variable>
  115. <!-- Put the root element bookmark at the same level as its children -->
  116. <!-- If the object is a set or book, generate a bookmark for the toc -->
  117. <xsl:choose>
  118. <xsl:when test="self::index and $generate.index = 0"/>
  119. <xsl:when test="parent::*">
  120. <rx:bookmark internal-destination="{$id}">
  121. <rx:bookmark-label>
  122. <xsl:value-of select="normalize-space($bookmark-label)"/>
  123. </rx:bookmark-label>
  124. <xsl:apply-templates select="*" mode="xep.outline"/>
  125. </rx:bookmark>
  126. </xsl:when>
  127. <xsl:otherwise>
  128. <xsl:if test="$bookmark-label != ''">
  129. <rx:bookmark internal-destination="{$id}">
  130. <rx:bookmark-label>
  131. <xsl:value-of select="normalize-space($bookmark-label)"/>
  132. </rx:bookmark-label>
  133. </rx:bookmark>
  134. </xsl:if>
  135. <xsl:variable name="toc.params">
  136. <xsl:call-template name="find.path.params">
  137. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  138. </xsl:call-template>
  139. </xsl:variable>
  140. <xsl:if test="contains($toc.params, 'toc')
  141. and set|book|part|reference|section|sect1|refentry
  142. |article|topic|bibliography|glossary|chapter
  143. |appendix">
  144. <rx:bookmark internal-destination="toc...{$id}">
  145. <rx:bookmark-label>
  146. <xsl:call-template name="gentext">
  147. <xsl:with-param name="key" select="'TableofContents'"/>
  148. </xsl:call-template>
  149. </rx:bookmark-label>
  150. </rx:bookmark>
  151. </xsl:if>
  152. <xsl:apply-templates select="*" mode="xep.outline"/>
  153. </xsl:otherwise>
  154. </xsl:choose>
  155. </xsl:template>
  156. <xsl:template name="xep-pis">
  157. <xsl:if test="$crop.marks != 0">
  158. <xsl:processing-instruction name="xep-pdf-crop-mark-width"><xsl:value-of select="$crop.mark.width"/></xsl:processing-instruction>
  159. <xsl:processing-instruction name="xep-pdf-crop-offset"><xsl:value-of select="$crop.mark.offset"/></xsl:processing-instruction>
  160. <xsl:processing-instruction name="xep-pdf-bleed"><xsl:value-of select="$crop.mark.bleed"/></xsl:processing-instruction>
  161. </xsl:if>
  162. <xsl:call-template name="user-xep-pis"/>
  163. </xsl:template>
  164. <!-- Placeholder for user defined PIs -->
  165. <xsl:template name="user-xep-pis"/>
  166. </xsl:stylesheet>