xep.xsl 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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$
  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" select="(//author|//editor|//corpauthor|//authorgroup)[1]"/>
  19. <xsl:if test="$authors">
  20. <xsl:variable name="author">
  21. <xsl:choose>
  22. <xsl:when test="$authors[self::authorgroup]">
  23. <xsl:call-template name="person.name.list">
  24. <xsl:with-param name="person.list"
  25. select="$authors/*[self::author|self::corpauthor|
  26. self::othercredit|self::editor]"/>
  27. </xsl:call-template>
  28. </xsl:when>
  29. <xsl:when test="$authors[self::corpauthor]">
  30. <xsl:value-of select="$authors"/>
  31. </xsl:when>
  32. <xsl:otherwise>
  33. <xsl:call-template name="person.name">
  34. <xsl:with-param name="node" select="$authors"/>
  35. </xsl:call-template>
  36. </xsl:otherwise>
  37. </xsl:choose>
  38. </xsl:variable>
  39. <xsl:element name="rx:meta-field">
  40. <xsl:attribute name="name">author</xsl:attribute>
  41. <xsl:attribute name="value">
  42. <xsl:value-of select="normalize-space($author)"/>
  43. </xsl:attribute>
  44. </xsl:element>
  45. </xsl:if>
  46. <xsl:variable name="title">
  47. <xsl:apply-templates select="/*[1]" mode="label.markup"/>
  48. <xsl:apply-templates select="/*[1]" mode="title.markup"/>
  49. </xsl:variable>
  50. <xsl:element name="rx:meta-field">
  51. <xsl:attribute name="name">creator</xsl:attribute>
  52. <xsl:attribute name="value">
  53. <xsl:text>DocBook </xsl:text>
  54. <xsl:value-of select="$DistroTitle"/>
  55. <xsl:text> V</xsl:text>
  56. <xsl:value-of select="$VERSION"/>
  57. </xsl:attribute>
  58. </xsl:element>
  59. <xsl:element name="rx:meta-field">
  60. <xsl:attribute name="name">title</xsl:attribute>
  61. <xsl:attribute name="value">
  62. <xsl:value-of select="normalize-space($title)"/>
  63. </xsl:attribute>
  64. </xsl:element>
  65. <xsl:if test="//keyword">
  66. <xsl:element name="rx:meta-field">
  67. <xsl:attribute name="name">keywords</xsl:attribute>
  68. <xsl:attribute name="value">
  69. <xsl:for-each select="//keyword">
  70. <xsl:value-of select="normalize-space(.)"/>
  71. <xsl:if test="position() != last()">
  72. <xsl:text>, </xsl:text>
  73. </xsl:if>
  74. </xsl:for-each>
  75. </xsl:attribute>
  76. </xsl:element>
  77. </xsl:if>
  78. <xsl:if test="//subjectterm">
  79. <xsl:element name="rx:meta-field">
  80. <xsl:attribute name="name">subject</xsl:attribute>
  81. <xsl:attribute name="value">
  82. <xsl:for-each select="//subjectterm">
  83. <xsl:value-of select="normalize-space(.)"/>
  84. <xsl:if test="position() != last()">
  85. <xsl:text>, </xsl:text>
  86. </xsl:if>
  87. </xsl:for-each>
  88. </xsl:attribute>
  89. </xsl:element>
  90. </xsl:if>
  91. </rx:meta-info>
  92. </xsl:template>
  93. <!-- ********************************************************************
  94. Pdf bookmarks
  95. ******************************************************************** -->
  96. <xsl:template match="*" mode="xep.outline">
  97. <xsl:apply-templates select="*" mode="xep.outline"/>
  98. </xsl:template>
  99. <xsl:template match="set|book|part|reference|preface|chapter|appendix|article
  100. |glossary|bibliography|index|setindex
  101. |refentry|refsynopsisdiv
  102. |refsect1|refsect2|refsect3|refsection
  103. |sect1|sect2|sect3|sect4|sect5|section"
  104. mode="xep.outline">
  105. <xsl:variable name="id">
  106. <xsl:call-template name="object.id"/>
  107. </xsl:variable>
  108. <xsl:variable name="bookmark-label">
  109. <xsl:apply-templates select="." mode="object.title.markup"/>
  110. </xsl:variable>
  111. <!-- Put the root element bookmark at the same level as its children -->
  112. <!-- If the object is a set or book, generate a bookmark for the toc -->
  113. <xsl:choose>
  114. <xsl:when test="parent::*">
  115. <rx:bookmark internal-destination="{$id}">
  116. <rx:bookmark-label>
  117. <xsl:value-of select="normalize-space($bookmark-label)"/>
  118. </rx:bookmark-label>
  119. <xsl:apply-templates select="*" mode="xep.outline"/>
  120. </rx:bookmark>
  121. </xsl:when>
  122. <xsl:otherwise>
  123. <xsl:if test="$bookmark-label != ''">
  124. <rx:bookmark internal-destination="{$id}">
  125. <rx:bookmark-label>
  126. <xsl:value-of select="normalize-space($bookmark-label)"/>
  127. </rx:bookmark-label>
  128. </rx:bookmark>
  129. </xsl:if>
  130. <xsl:variable name="toc.params">
  131. <xsl:call-template name="find.path.params">
  132. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  133. </xsl:call-template>
  134. </xsl:variable>
  135. <xsl:if test="contains($toc.params, 'toc')
  136. and set|book|part|reference|section|sect1|refentry
  137. |article|bibliography|glossary|chapter
  138. |appendix">
  139. <rx:bookmark internal-destination="toc...{$id}">
  140. <rx:bookmark-label>
  141. <xsl:call-template name="gentext">
  142. <xsl:with-param name="key" select="'TableofContents'"/>
  143. </xsl:call-template>
  144. </rx:bookmark-label>
  145. </rx:bookmark>
  146. </xsl:if>
  147. <xsl:apply-templates select="*" mode="xep.outline"/>
  148. </xsl:otherwise>
  149. </xsl:choose>
  150. </xsl:template>
  151. <xsl:template name="xep-pis">
  152. <xsl:if test="$crop.marks != 0">
  153. <xsl:processing-instruction name="xep-pdf-crop-mark-width"><xsl:value-of select="$crop.mark.width"/></xsl:processing-instruction>
  154. <xsl:processing-instruction name="xep-pdf-crop-offset"><xsl:value-of select="$crop.mark.offset"/></xsl:processing-instruction>
  155. <xsl:processing-instruction name="xep-pdf-bleed"><xsl:value-of select="$crop.mark.bleed"/></xsl:processing-instruction>
  156. </xsl:if>
  157. <xsl:call-template name="user-xep-pis"/>
  158. </xsl:template>
  159. <!-- Placeholder for user defined PIs -->
  160. <xsl:template name="user-xep-pis"/>
  161. </xsl:stylesheet>