lfs-xref.xsl 6.8 KB

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