targets.xsl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. xmlns:exsl="http://exslt.org/common"
  5. exclude-result-prefixes="doc exsl"
  6. version='1.0'>
  7. <!-- ********************************************************************
  8. $Id: targets.xsl 9286 2012-04-19 10:10:58Z bobstayton $
  9. ********************************************************************
  10. This file is part of the XSL DocBook Stylesheet distribution.
  11. See ../README or http://docbook.sf.net/release/xsl/current/ for
  12. copyright and other information.
  13. ******************************************************************** -->
  14. <!-- ==================================================================== -->
  15. <!-- cross reference target collection -->
  16. <doc:mode mode="collect.targets" xmlns="">
  17. <refpurpose>Collects information for potential cross reference targets</refpurpose>
  18. <refdescription id="collect.targets-desc">
  19. <para>Processing the root element in the
  20. <literal role="mode">collect.targets</literal> mode produces
  21. a set of target database elements that can be used by
  22. the olink mechanism to resolve external cross references.
  23. The collection process is controlled by the <literal>
  24. collect.xref.targets</literal> parameter, which can be
  25. <literal>yes</literal> to collect targets and process
  26. the document for output, <literal>only</literal> to
  27. only collect the targets, and <literal>no</literal>
  28. (default) to not collect the targets and only process the document.
  29. </para>
  30. <para>
  31. A <literal>targets.filename</literal> parameter must be
  32. specified to receive the output if
  33. <literal>collect.xref.targets</literal> is
  34. set to <literal>yes</literal> so as to
  35. redirect the target data to a file separate from the
  36. document output.
  37. </para>
  38. </refdescription>
  39. </doc:mode>
  40. <!-- ============================================================ -->
  41. <xsl:template match="*" mode="collect.targets">
  42. <xsl:choose>
  43. <xsl:when test="$collect.xref.targets = 'yes' and $targets.filename = ''">
  44. <xsl:message>
  45. Must specify a $targets.filename parameter when
  46. $collect.xref.targets is set to 'yes'.
  47. The xref targets were not collected.
  48. </xsl:message>
  49. </xsl:when>
  50. <xsl:otherwise>
  51. <xsl:choose>
  52. <xsl:when test="$targets.filename">
  53. <xsl:call-template name="write.chunk">
  54. <xsl:with-param name="filename" select="$targets.filename"/>
  55. <xsl:with-param name="method" select="'xml'"/>
  56. <xsl:with-param name="encoding" select="'utf-8'"/>
  57. <xsl:with-param name="omit-xml-declaration" select="'yes'"/>
  58. <xsl:with-param name="doctype-public" select="''"/>
  59. <xsl:with-param name="doctype-system" select="''"/>
  60. <xsl:with-param name="indent" select="'no'"/>
  61. <xsl:with-param name="quiet" select="0"/>
  62. <xsl:with-param name="content">
  63. <xsl:apply-templates select="." mode="olink.mode"/>
  64. </xsl:with-param>
  65. </xsl:call-template>
  66. </xsl:when>
  67. <xsl:otherwise>
  68. <!-- Else write to standard output -->
  69. <xsl:apply-templates select="." mode="olink.mode"/>
  70. </xsl:otherwise>
  71. </xsl:choose>
  72. </xsl:otherwise>
  73. </xsl:choose>
  74. </xsl:template>
  75. <xsl:template name="olink.href.target">
  76. <xsl:param name="nd" select="."/>
  77. <xsl:value-of select="$olink.base.uri"/>
  78. <xsl:call-template name="href.target">
  79. <xsl:with-param name="object" select="$nd"/>
  80. <xsl:with-param name="context" select="NOTANODE"/>
  81. </xsl:call-template>
  82. </xsl:template>
  83. <!-- Templates for extracting cross reference information
  84. from a document for use in an xref database.
  85. -->
  86. <xsl:template name="attrs">
  87. <xsl:param name="nd" select="."/>
  88. <xsl:attribute name="element">
  89. <xsl:value-of select="local-name(.)"/>
  90. </xsl:attribute>
  91. <xsl:attribute name="href">
  92. <xsl:call-template name="olink.href.target">
  93. <xsl:with-param name="nd" select="$nd"/>
  94. </xsl:call-template>
  95. </xsl:attribute>
  96. <xsl:variable name="num">
  97. <xsl:apply-templates select="$nd" mode="label.markup">
  98. <xsl:with-param name="verbose" select="0"/>
  99. </xsl:apply-templates>
  100. </xsl:variable>
  101. <xsl:if test="$num">
  102. <xsl:attribute name="number">
  103. <xsl:value-of select="$num"/>
  104. </xsl:attribute>
  105. </xsl:if>
  106. <xsl:choose>
  107. <xsl:when test="$nd/@id">
  108. <xsl:attribute name="targetptr">
  109. <xsl:value-of select="$nd/@id"/>
  110. </xsl:attribute>
  111. </xsl:when>
  112. <xsl:when test="$nd/@xml:id">
  113. <xsl:attribute name="targetptr">
  114. <xsl:value-of select="$nd/@xml:id"/>
  115. </xsl:attribute>
  116. </xsl:when>
  117. </xsl:choose>
  118. <xsl:if test="$nd/@lang">
  119. <xsl:attribute name="lang">
  120. <xsl:value-of select="$nd/@lang"/>
  121. </xsl:attribute>
  122. </xsl:if>
  123. </xsl:template>
  124. <xsl:template name="div">
  125. <xsl:param name="nd" select="."/>
  126. <div>
  127. <xsl:call-template name="attrs">
  128. <xsl:with-param name="nd" select="$nd"/>
  129. </xsl:call-template>
  130. <ttl>
  131. <xsl:apply-templates select="$nd" mode="title.markup">
  132. <xsl:with-param name="verbose" select="0"/>
  133. </xsl:apply-templates>
  134. </ttl>
  135. <xreftext>
  136. <xsl:choose>
  137. <xsl:when test="$nd/@xreflabel">
  138. <xsl:call-template name="xref.xreflabel">
  139. <xsl:with-param name="target" select="$nd"/>
  140. </xsl:call-template>
  141. </xsl:when>
  142. <xsl:otherwise>
  143. <xsl:apply-templates select="$nd" mode="xref-to">
  144. <xsl:with-param name="verbose" select="0"/>
  145. </xsl:apply-templates>
  146. </xsl:otherwise>
  147. </xsl:choose>
  148. </xreftext>
  149. <xsl:apply-templates mode="olink.mode"/>
  150. </div>
  151. </xsl:template>
  152. <xsl:template name="obj">
  153. <xsl:param name="nd" select="."/>
  154. <obj>
  155. <xsl:call-template name="attrs">
  156. <xsl:with-param name="nd" select="$nd"/>
  157. </xsl:call-template>
  158. <ttl>
  159. <xsl:apply-templates select="$nd" mode="title.markup">
  160. <xsl:with-param name="verbose" select="0"/>
  161. </xsl:apply-templates>
  162. </ttl>
  163. <xreftext>
  164. <xsl:choose>
  165. <xsl:when test="$nd/@xreflabel">
  166. <xsl:call-template name="xref.xreflabel">
  167. <xsl:with-param name="target" select="$nd"/>
  168. </xsl:call-template>
  169. </xsl:when>
  170. <xsl:otherwise>
  171. <xsl:apply-templates select="$nd" mode="xref-to">
  172. <xsl:with-param name="verbose" select="0"/>
  173. </xsl:apply-templates>
  174. </xsl:otherwise>
  175. </xsl:choose>
  176. </xreftext>
  177. </obj>
  178. </xsl:template>
  179. <xsl:template match="text()|processing-instruction()|comment()"
  180. mode="olink.mode">
  181. <!-- nop -->
  182. </xsl:template>
  183. <!--
  184. <xsl:template match="*" mode="olink.mode">
  185. </xsl:template>
  186. -->
  187. <xsl:template match="set" mode="olink.mode">
  188. <xsl:call-template name="div"/>
  189. </xsl:template>
  190. <xsl:template match="book" mode="olink.mode">
  191. <xsl:call-template name="div"/>
  192. </xsl:template>
  193. <xsl:template match="preface|chapter|appendix" mode="olink.mode">
  194. <xsl:call-template name="div"/>
  195. </xsl:template>
  196. <xsl:template match="part|reference" mode="olink.mode">
  197. <xsl:call-template name="div"/>
  198. </xsl:template>
  199. <xsl:template match="article" mode="olink.mode">
  200. <xsl:call-template name="div"/>
  201. </xsl:template>
  202. <xsl:template match="topic" mode="olink.mode">
  203. <xsl:call-template name="div"/>
  204. </xsl:template>
  205. <xsl:template match="bibliography|bibliodiv" mode="olink.mode">
  206. <xsl:call-template name="div"/>
  207. </xsl:template>
  208. <xsl:template match="biblioentry|bibliomixed" mode="olink.mode">
  209. <xsl:call-template name="obj"/>
  210. </xsl:template>
  211. <xsl:template match="refentry" mode="olink.mode">
  212. <xsl:call-template name="div"/>
  213. </xsl:template>
  214. <xsl:template match="section|sect1|sect2|sect3|sect4|sect5" mode="olink.mode">
  215. <xsl:call-template name="div"/>
  216. </xsl:template>
  217. <xsl:template match="refsection|refsect1|refsect2|refsect3" mode="olink.mode">
  218. <xsl:call-template name="div"/>
  219. </xsl:template>
  220. <xsl:template match="figure|example|table" mode="olink.mode">
  221. <xsl:call-template name="obj"/>
  222. <xsl:apply-templates mode="olink.mode"/>
  223. </xsl:template>
  224. <xsl:template match="equation[title or info/title]" mode="olink.mode">
  225. <xsl:call-template name="obj"/>
  226. </xsl:template>
  227. <xsl:template match="qandaset|qandaentry" mode="olink.mode">
  228. <xsl:call-template name="div"/>
  229. </xsl:template>
  230. <!-- handle an glossary collection -->
  231. <xsl:template match="glossary[@role='auto']" mode="olink.mode" priority="2">
  232. <xsl:variable name="collection" select="document($glossary.collection, .)"/>
  233. <xsl:if test="$glossary.collection = ''">
  234. <xsl:message>
  235. <xsl:text>Warning: processing automatic glossary </xsl:text>
  236. <xsl:text>without a glossary.collection file.</xsl:text>
  237. </xsl:message>
  238. </xsl:if>
  239. <xsl:if test="not($collection) and $glossary.collection != ''">
  240. <xsl:message>
  241. <xsl:text>Warning: processing automatic glossary but unable to </xsl:text>
  242. <xsl:text>open glossary.collection file '</xsl:text>
  243. <xsl:value-of select="$glossary.collection"/>
  244. <xsl:text>'</xsl:text>
  245. </xsl:message>
  246. </xsl:if>
  247. <xsl:if test="$exsl.node.set.available != 0">
  248. <xsl:variable name="auto.glossary">
  249. <xsl:apply-templates select="." mode="assemble.auto.glossary"/>
  250. </xsl:variable>
  251. <xsl:variable name="auto.glossary.nodeset" select="exsl:node-set($auto.glossary)"/>
  252. <xsl:apply-templates select="$auto.glossary.nodeset/*" mode="olink.mode"/>
  253. </xsl:if>
  254. </xsl:template>
  255. <!-- construct a glossary in memory -->
  256. <xsl:template match="glossary" mode="assemble.auto.glossary">
  257. <xsl:copy>
  258. <xsl:copy-of select="@*[not(local-name() = 'role')]"/>
  259. <xsl:apply-templates select="node()" mode="assemble.auto.glossary"/>
  260. <xsl:call-template name="select.glossentries"/>
  261. </xsl:copy>
  262. </xsl:template>
  263. <xsl:template name="select.glossentries">
  264. <xsl:param name="collection" select="document($glossary.collection, .)"/>
  265. <xsl:param name="terms" select="//glossterm[not(parent::glossdef)]|//firstterm"/>
  266. <xsl:for-each select="$collection//glossentry">
  267. <xsl:variable name="cterm" select="glossterm"/>
  268. <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
  269. <xsl:copy-of select="."/>
  270. </xsl:if>
  271. </xsl:for-each>
  272. </xsl:template>
  273. <xsl:template match="glossentry" mode="assemble.auto.glossary">
  274. <!-- skip the dummy entries -->
  275. </xsl:template>
  276. <xsl:template match="*" mode="assemble.auto.glossary">
  277. <!-- pass through any titles and intro stuff -->
  278. <xsl:copy-of select="."/>
  279. </xsl:template>
  280. <xsl:template match="*" mode="olink.mode">
  281. <xsl:if test="@id or @xml:id">
  282. <xsl:call-template name="obj"/>
  283. </xsl:if>
  284. <xsl:apply-templates mode="olink.mode"/>
  285. </xsl:template>
  286. </xsl:stylesheet>