targets.xsl 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  4. exclude-result-prefixes="doc"
  5. version='1.0'>
  6. <!-- ********************************************************************
  7. $Id$
  8. ********************************************************************
  9. This file is part of the XSL DocBook Stylesheet distribution.
  10. See ../README or http://docbook.sf.net/release/xsl/current/ for
  11. copyright and other information.
  12. ******************************************************************** -->
  13. <!-- ==================================================================== -->
  14. <!-- cross reference target collection -->
  15. <doc:mode mode="collect.targets" xmlns="">
  16. <refpurpose>Collects information for potential cross reference targets</refpurpose>
  17. <refdescription id="collect.targets-desc">
  18. <para>Processing the root element in the
  19. <literal role="mode">collect.targets</literal> mode produces
  20. a set of target database elements that can be used by
  21. the olink mechanism to resolve external cross references.
  22. The collection process is controlled by the <literal>
  23. collect.xref.targets</literal> parameter, which can be
  24. <literal>yes</literal> to collect targets and process
  25. the document for output, <literal>only</literal> to
  26. only collect the targets, and <literal>no</literal>
  27. (default) to not collect the targets and only process the document.
  28. </para>
  29. <para>
  30. A <literal>targets.filename</literal> parameter must be
  31. specified to receive the output if
  32. <literal>collect.xref.targets</literal> is
  33. set to <literal>yes</literal> so as to
  34. redirect the target data to a file separate from the
  35. document output.
  36. </para>
  37. </refdescription>
  38. </doc:mode>
  39. <!-- ============================================================ -->
  40. <xsl:template match="*" mode="collect.targets">
  41. <xsl:choose>
  42. <xsl:when test="$collect.xref.targets = 'yes' and $targets.filename = ''">
  43. <xsl:message>
  44. Must specify a $targets.filename parameter when
  45. $collect.xref.targets is set to 'yes'.
  46. The xref targets were not collected.
  47. </xsl:message>
  48. </xsl:when>
  49. <xsl:otherwise>
  50. <xsl:choose>
  51. <xsl:when test="$targets.filename">
  52. <xsl:call-template name="write.chunk">
  53. <xsl:with-param name="filename" select="$targets.filename"/>
  54. <xsl:with-param name="method" select="'xml'"/>
  55. <xsl:with-param name="encoding" select="'utf-8'"/>
  56. <xsl:with-param name="omit-xml-declaration" select="'yes'"/>
  57. <xsl:with-param name="doctype-public" select="''"/>
  58. <xsl:with-param name="doctype-system" select="''"/>
  59. <xsl:with-param name="indent" select="'no'"/>
  60. <xsl:with-param name="quiet" select="0"/>
  61. <xsl:with-param name="content">
  62. <xsl:apply-templates select="." mode="olink.mode"/>
  63. </xsl:with-param>
  64. </xsl:call-template>
  65. </xsl:when>
  66. <xsl:otherwise>
  67. <!-- Else write to standard output -->
  68. <xsl:apply-templates select="." mode="olink.mode"/>
  69. </xsl:otherwise>
  70. </xsl:choose>
  71. </xsl:otherwise>
  72. </xsl:choose>
  73. </xsl:template>
  74. <xsl:template name="olink.href.target">
  75. <xsl:param name="nd" select="."/>
  76. <xsl:value-of select="$olink.base.uri"/>
  77. <xsl:call-template name="href.target">
  78. <xsl:with-param name="object" select="$nd"/>
  79. <xsl:with-param name="context" select="NOTANODE"/>
  80. </xsl:call-template>
  81. </xsl:template>
  82. <!-- Templates for extracting cross reference information
  83. from a document for use in an xref database.
  84. -->
  85. <xsl:template name="attrs">
  86. <xsl:param name="nd" select="."/>
  87. <xsl:attribute name="element">
  88. <xsl:value-of select="local-name(.)"/>
  89. </xsl:attribute>
  90. <xsl:attribute name="href">
  91. <xsl:call-template name="olink.href.target">
  92. <xsl:with-param name="nd" select="$nd"/>
  93. </xsl:call-template>
  94. </xsl:attribute>
  95. <xsl:variable name="num">
  96. <xsl:apply-templates select="$nd" mode="label.markup">
  97. <xsl:with-param name="verbose" select="0"/>
  98. </xsl:apply-templates>
  99. </xsl:variable>
  100. <xsl:if test="$num">
  101. <xsl:attribute name="number">
  102. <xsl:value-of select="$num"/>
  103. </xsl:attribute>
  104. </xsl:if>
  105. <xsl:choose>
  106. <xsl:when test="$nd/@id">
  107. <xsl:attribute name="targetptr">
  108. <xsl:value-of select="$nd/@id"/>
  109. </xsl:attribute>
  110. </xsl:when>
  111. <xsl:when test="$nd/@xml:id">
  112. <xsl:attribute name="targetptr">
  113. <xsl:value-of select="$nd/@xml:id"/>
  114. </xsl:attribute>
  115. </xsl:when>
  116. </xsl:choose>
  117. <xsl:if test="$nd/@lang">
  118. <xsl:attribute name="lang">
  119. <xsl:value-of select="$nd/@lang"/>
  120. </xsl:attribute>
  121. </xsl:if>
  122. </xsl:template>
  123. <xsl:template name="div">
  124. <xsl:param name="nd" select="."/>
  125. <div>
  126. <xsl:call-template name="attrs">
  127. <xsl:with-param name="nd" select="$nd"/>
  128. </xsl:call-template>
  129. <ttl>
  130. <xsl:apply-templates select="$nd" mode="title.markup">
  131. <xsl:with-param name="verbose" select="0"/>
  132. </xsl:apply-templates>
  133. </ttl>
  134. <xreftext>
  135. <xsl:choose>
  136. <xsl:when test="$nd/@xreflabel">
  137. <xsl:call-template name="xref.xreflabel">
  138. <xsl:with-param name="target" select="$nd"/>
  139. </xsl:call-template>
  140. </xsl:when>
  141. <xsl:otherwise>
  142. <xsl:apply-templates select="$nd" mode="xref-to">
  143. <xsl:with-param name="verbose" select="0"/>
  144. </xsl:apply-templates>
  145. </xsl:otherwise>
  146. </xsl:choose>
  147. </xreftext>
  148. <xsl:apply-templates mode="olink.mode"/>
  149. </div>
  150. </xsl:template>
  151. <xsl:template name="obj">
  152. <xsl:param name="nd" select="."/>
  153. <obj>
  154. <xsl:call-template name="attrs">
  155. <xsl:with-param name="nd" select="$nd"/>
  156. </xsl:call-template>
  157. <ttl>
  158. <xsl:apply-templates select="$nd" mode="title.markup">
  159. <xsl:with-param name="verbose" select="0"/>
  160. </xsl:apply-templates>
  161. </ttl>
  162. <xreftext>
  163. <xsl:choose>
  164. <xsl:when test="$nd/@xreflabel">
  165. <xsl:call-template name="xref.xreflabel">
  166. <xsl:with-param name="target" select="$nd"/>
  167. </xsl:call-template>
  168. </xsl:when>
  169. <xsl:otherwise>
  170. <xsl:apply-templates select="$nd" mode="xref-to">
  171. <xsl:with-param name="verbose" select="0"/>
  172. </xsl:apply-templates>
  173. </xsl:otherwise>
  174. </xsl:choose>
  175. </xreftext>
  176. </obj>
  177. </xsl:template>
  178. <xsl:template match="text()|processing-instruction()|comment()"
  179. mode="olink.mode">
  180. <!-- nop -->
  181. </xsl:template>
  182. <!--
  183. <xsl:template match="*" mode="olink.mode">
  184. </xsl:template>
  185. -->
  186. <xsl:template match="set" mode="olink.mode">
  187. <xsl:call-template name="div"/>
  188. </xsl:template>
  189. <xsl:template match="book" mode="olink.mode">
  190. <xsl:call-template name="div"/>
  191. </xsl:template>
  192. <xsl:template match="preface|chapter|appendix" mode="olink.mode">
  193. <xsl:call-template name="div"/>
  194. </xsl:template>
  195. <xsl:template match="part|reference" mode="olink.mode">
  196. <xsl:call-template name="div"/>
  197. </xsl:template>
  198. <xsl:template match="article" mode="olink.mode">
  199. <xsl:call-template name="div"/>
  200. </xsl:template>
  201. <xsl:template match="bibliography|bibliodiv" mode="olink.mode">
  202. <xsl:call-template name="div"/>
  203. </xsl:template>
  204. <xsl:template match="biblioentry|bibliomixed" mode="olink.mode">
  205. <xsl:call-template name="obj"/>
  206. </xsl:template>
  207. <xsl:template match="refentry" mode="olink.mode">
  208. <xsl:call-template name="div"/>
  209. </xsl:template>
  210. <xsl:template match="section|sect1|sect2|sect3|sect4|sect5" mode="olink.mode">
  211. <xsl:call-template name="div"/>
  212. </xsl:template>
  213. <xsl:template match="refsection|refsect1|refsect2|refsect3" mode="olink.mode">
  214. <xsl:call-template name="div"/>
  215. </xsl:template>
  216. <xsl:template match="figure|example|table" mode="olink.mode">
  217. <xsl:call-template name="obj"/>
  218. <xsl:apply-templates mode="olink.mode"/>
  219. </xsl:template>
  220. <xsl:template match="equation[title or info/title]" mode="olink.mode">
  221. <xsl:call-template name="obj"/>
  222. </xsl:template>
  223. <xsl:template match="qandaset|qandaentry" mode="olink.mode">
  224. <xsl:call-template name="div"/>
  225. </xsl:template>
  226. <xsl:template match="*" mode="olink.mode">
  227. <xsl:if test="@id or @xml:id">
  228. <xsl:call-template name="obj"/>
  229. </xsl:if>
  230. <xsl:apply-templates mode="olink.mode"/>
  231. </xsl:template>
  232. </xsl:stylesheet>