lfs-xref.xsl 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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="http://www.w3.org/1999/xhtml"
  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-chunked2.xsl -->
  18. <!-- xref:
  19. Added role variable and use it when calling mode xref-to.-->
  20. <!-- The original template is in {docbook-xsl}/xhtml/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,'#') and (not(contains($xhref,'('))
  26. or starts-with($xhref, '#xpointer(id('))">
  27. <xsl:call-template name="xpointer.idref">
  28. <xsl:with-param name="xpointer" select="$xhref"/>
  29. </xsl:call-template>
  30. </xsl:if>
  31. </xsl:param>
  32. <xsl:param name="xlink.targets" select="key('id',$xlink.idref)"/>
  33. <xsl:param name="linkend.targets" select="key('id',@linkend)"/>
  34. <xsl:param name="target" select="($xlink.targets | $linkend.targets)[1]"/>
  35. <!-- Added role variable -->
  36. <xsl:variable name="role" select="@role"/>
  37. <xsl:variable name="xrefstyle">
  38. <xsl:choose>
  39. <xsl:when test="@role and not(@xrefstyle) and $use.role.as.xrefstyle != 0">
  40. <xsl:value-of select="@role"/>
  41. </xsl:when>
  42. <xsl:otherwise>
  43. <xsl:value-of select="@xrefstyle"/>
  44. </xsl:otherwise>
  45. </xsl:choose>
  46. </xsl:variable>
  47. <xsl:call-template name="anchor"/>
  48. <xsl:variable name="content">
  49. <xsl:choose>
  50. <xsl:when test="@endterm">
  51. <xsl:variable name="etargets" select="key('id',@endterm)"/>
  52. <xsl:variable name="etarget" select="$etargets[1]"/>
  53. <xsl:choose>
  54. <xsl:when test="count($etarget) = 0">
  55. <xsl:message>
  56. <xsl:value-of select="count($etargets)"/>
  57. <xsl:text>Endterm points to nonexistent ID: </xsl:text>
  58. <xsl:value-of select="@endterm"/>
  59. </xsl:message>
  60. <xsl:text>???</xsl:text>
  61. </xsl:when>
  62. <xsl:otherwise>
  63. <xsl:apply-templates select="$etarget" mode="endterm"/>
  64. </xsl:otherwise>
  65. </xsl:choose>
  66. </xsl:when>
  67. <xsl:when test="$target/@xreflabel">
  68. <xsl:call-template name="xref.xreflabel">
  69. <xsl:with-param name="target" select="$target"/>
  70. </xsl:call-template>
  71. </xsl:when>
  72. <xsl:when test="$target">
  73. <xsl:if test="not(parent::citation)">
  74. <xsl:apply-templates select="$target" mode="xref-to-prefix"/>
  75. </xsl:if>
  76. <xsl:apply-templates select="$target" mode="xref-to">
  77. <xsl:with-param name="referrer" select="."/>
  78. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  79. <!-- Propagate role -->
  80. <xsl:with-param name="role" select="$role"/>
  81. </xsl:apply-templates>
  82. <xsl:if test="not(parent::citation)">
  83. <xsl:apply-templates select="$target" mode="xref-to-suffix"/>
  84. </xsl:if>
  85. </xsl:when>
  86. <xsl:otherwise>
  87. <xsl:message>
  88. <xsl:text>ERROR: xref linking to </xsl:text>
  89. <xsl:value-of select="@linkend|@xlink:href"/>
  90. <xsl:text> has no generated link text.</xsl:text>
  91. </xsl:message>
  92. <xsl:text>???</xsl:text>
  93. </xsl:otherwise>
  94. </xsl:choose>
  95. </xsl:variable>
  96. <xsl:call-template name="simple.xlink">
  97. <xsl:with-param name="content" select="$content"/>
  98. </xsl:call-template>
  99. </xsl:template>
  100. <!-- sect* mode xref-to:
  101. Propagate role to mode object.xref.markup (see ../lfs-common.xsl) -->
  102. <!-- The original template is in {docbook-xsl}/xhtml/xref.xsl -->
  103. <xsl:template match="section|simplesect|sect1|sect2|sect3|sect4|sect5|refsect1
  104. |refsect2|refsect3|refsection" mode="xref-to">
  105. <xsl:param name="referrer"/>
  106. <xsl:param name="xrefstyle"/>
  107. <xsl:param name="verbose" select="1"/>
  108. <xsl:param name="role"/>
  109. <xsl:apply-templates select="." mode="object.xref.markup">
  110. <xsl:with-param name="purpose" select="'xref'"/>
  111. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  112. <xsl:with-param name="referrer" select="$referrer"/>
  113. <xsl:with-param name="verbose" select="$verbose"/>
  114. <xsl:with-param name="role" select="$role"/>
  115. </xsl:apply-templates>
  116. </xsl:template>
  117. <!-- insert.title.markup:
  118. Apply the role value. -->
  119. <!-- The original template is in {docbook-xsl}/xhtml/xref.xsl -->
  120. <xsl:template match="*" mode="insert.title.markup">
  121. <xsl:param name="purpose"/>
  122. <xsl:param name="xrefstyle"/>
  123. <xsl:param name="title"/>
  124. <xsl:param name="role"/>
  125. <xsl:choose>
  126. <xsl:when test="$purpose = 'xref' and titleabbrev">
  127. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  128. </xsl:when>
  129. <xsl:otherwise>
  130. <xsl:copy-of select="$title"/>
  131. <xsl:value-of select="$role"/>
  132. </xsl:otherwise>
  133. </xsl:choose>
  134. </xsl:template>
  135. </xsl:stylesheet>