lfs-xref.xsl 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2. <!--
  3. $LastChangedBy$
  4. $Date$
  5. -->
  6. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns:xlink="http://www.w3.org/1999/xlink"
  8. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  9. exclude-result-prefixes="xlink"
  10. version="1.0">
  11. <!-- This stylesheet fixes English punctuation in xref links
  12. (as was requested by the publisher) via adding @role propagation
  13. in xref tags.
  14. This hack may not work with xref flavours not used in the book.
  15. For other languages, just remove the xref @role attributes
  16. in the book XML sources and/or comment-out the inclusion of
  17. this file in lfs-pdf.xsl -->
  18. <!-- xref:
  19. Added role variable and use it when calling mode xref-to.-->
  20. <!-- The original template is in {docbook-xsl}/fo/xref.xsl -->
  21. <xsl:template match="xref" name="xref">
  22. <xsl:param name="xhref" select="@xlink:href"/>
  23. <!-- is the @xlink:href a local idref link? -->
  24. <xsl:param name="xlink.idref">
  25. <xsl:if test="starts-with($xhref,'#')
  26. and (not(contains($xhref,'&#40;'))
  27. or starts-with($xhref, '#xpointer&#40;id&#40;'))">
  28. <xsl:call-template name="xpointer.idref">
  29. <xsl:with-param name="xpointer" select="$xhref"/>
  30. </xsl:call-template>
  31. </xsl:if>
  32. </xsl:param>
  33. <xsl:param name="xlink.targets" select="key('id',$xlink.idref)"/>
  34. <xsl:param name="linkend.targets" select="key('id',@linkend)"/>
  35. <xsl:param name="target" select="($xlink.targets | $linkend.targets)[1]"/>
  36. <xsl:param name="refelem" select="local-name($target)"/>
  37. <!-- Added role variable -->
  38. <xsl:variable name="role" select="@role"/>
  39. <xsl:variable name="xrefstyle">
  40. <xsl:choose>
  41. <xsl:when test="@role and not(@xrefstyle)
  42. and $use.role.as.xrefstyle != 0">
  43. <xsl:value-of select="@role"/>
  44. </xsl:when>
  45. <xsl:otherwise>
  46. <xsl:value-of select="@xrefstyle"/>
  47. </xsl:otherwise>
  48. </xsl:choose>
  49. </xsl:variable>
  50. <xsl:variable name="content">
  51. <fo:inline xsl:use-attribute-sets="xref.properties">
  52. <xsl:choose>
  53. <xsl:when test="@endterm">
  54. <xsl:variable name="etargets" select="key('id',@endterm)"/>
  55. <xsl:variable name="etarget" select="$etargets[1]"/>
  56. <xsl:choose>
  57. <xsl:when test="count($etarget) = 0">
  58. <xsl:message>
  59. <xsl:value-of select="count($etargets)"/>
  60. <xsl:text>Endterm points to nonexistent ID: </xsl:text>
  61. <xsl:value-of select="@endterm"/>
  62. </xsl:message>
  63. <xsl:text>???</xsl:text>
  64. </xsl:when>
  65. <xsl:otherwise>
  66. <xsl:apply-templates select="$etarget" mode="endterm"/>
  67. </xsl:otherwise>
  68. </xsl:choose>
  69. </xsl:when>
  70. <xsl:when test="$target/@xreflabel">
  71. <xsl:call-template name="xref.xreflabel">
  72. <xsl:with-param name="target" select="$target"/>
  73. </xsl:call-template>
  74. </xsl:when>
  75. <xsl:when test="$target">
  76. <xsl:if test="not(parent::citation)">
  77. <xsl:apply-templates select="$target" mode="xref-to-prefix"/>
  78. </xsl:if>
  79. <xsl:apply-templates select="$target" mode="xref-to">
  80. <xsl:with-param name="referrer" select="."/>
  81. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  82. <!-- Propagate role -->
  83. <xsl:with-param name="role" select="$role"/>
  84. </xsl:apply-templates>
  85. <xsl:if test="not(parent::citation)">
  86. <xsl:apply-templates select="$target" mode="xref-to-suffix"/>
  87. </xsl:if>
  88. </xsl:when>
  89. <xsl:otherwise>
  90. <xsl:message>
  91. <xsl:text>ERROR: xref linking to </xsl:text>
  92. <xsl:value-of select="@linkend|@xlink:href"/>
  93. <xsl:text> has no generated link text.</xsl:text>
  94. </xsl:message>
  95. <xsl:text>???</xsl:text>
  96. </xsl:otherwise>
  97. </xsl:choose>
  98. </fo:inline>
  99. </xsl:variable>
  100. <!-- Convert it into an active link -->
  101. <xsl:call-template name="simple.xlink">
  102. <xsl:with-param name="content" select="$content"/>
  103. </xsl:call-template>
  104. <!-- Add standard page reference? -->
  105. <xsl:choose>
  106. <xsl:when test="not($target)">
  107. <!-- page numbers only for local targets -->
  108. </xsl:when>
  109. <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')
  110. and contains($xrefstyle, 'nopage')">
  111. <!-- negative xrefstyle in instance turns it off -->
  112. </xsl:when>
  113. <!-- positive xrefstyle already handles it -->
  114. <xsl:when test="not(starts-with(normalize-space($xrefstyle), 'select:')
  115. and (contains($xrefstyle, 'page')
  116. or contains($xrefstyle, 'Page')))
  117. and ( $insert.xref.page.number = 'yes'
  118. or $insert.xref.page.number = '1')
  119. or local-name($target) = 'para'">
  120. <xsl:apply-templates select="$target" mode="page.citation">
  121. <xsl:with-param name="id" select="$target/@id|$target/@xml:id"/>
  122. </xsl:apply-templates>
  123. </xsl:when>
  124. </xsl:choose>
  125. </xsl:template>
  126. <!-- sect* mode xref-to:
  127. Propagate role to mode object.xref.markup (see ../lfs-common.xsl) -->
  128. <!-- The original template is in {docbook-xsl}/fo/xref.xsl -->
  129. <xsl:template match="section|simplesect|sect1|sect2|sect3|sect4|sect5
  130. |refsect1|refsect2|refsect3|refsection" mode="xref-to">
  131. <xsl:param name="referrer"/>
  132. <xsl:param name="xrefstyle"/>
  133. <xsl:param name="verbose" select="1"/>
  134. <xsl:param name="role"/>
  135. <xsl:apply-templates select="." mode="object.xref.markup">
  136. <xsl:with-param name="purpose" select="'xref'"/>
  137. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  138. <xsl:with-param name="referrer" select="$referrer"/>
  139. <xsl:with-param name="verbose" select="$verbose"/>
  140. <xsl:with-param name="role" select="$role"/>
  141. </xsl:apply-templates>
  142. </xsl:template>
  143. <!-- insert.title.markup:
  144. Apply the role value. -->
  145. <!-- The original template is in {docbook-xsl}/fo/xref.xsl -->
  146. <xsl:template match="*" mode="insert.title.markup">
  147. <xsl:param name="purpose"/>
  148. <xsl:param name="xrefstyle"/>
  149. <xsl:param name="title"/>
  150. <xsl:param name="role"/>
  151. <xsl:choose>
  152. <xsl:when test="$purpose = 'xref' and titleabbrev">
  153. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  154. </xsl:when>
  155. <xsl:otherwise>
  156. <xsl:copy-of select="$title"/>
  157. <xsl:value-of select="$role"/>
  158. </xsl:otherwise>
  159. </xsl:choose>
  160. </xsl:template>
  161. </xsl:stylesheet>