lfs-xref.xsl 5.5 KB

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