gentext.xsl 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  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. <xsl:template match="*" mode="object.title.template">
  15. <xsl:call-template name="gentext.template">
  16. <xsl:with-param name="context" select="'title'"/>
  17. <xsl:with-param name="name">
  18. <xsl:call-template name="xpath.location"/>
  19. </xsl:with-param>
  20. </xsl:call-template>
  21. </xsl:template>
  22. <xsl:template match="chapter" mode="object.title.template">
  23. <xsl:choose>
  24. <xsl:when test="string($chapter.autolabel) != 0">
  25. <xsl:call-template name="gentext.template">
  26. <xsl:with-param name="context" select="'title-numbered'"/>
  27. <xsl:with-param name="name">
  28. <xsl:call-template name="xpath.location"/>
  29. </xsl:with-param>
  30. </xsl:call-template>
  31. </xsl:when>
  32. <xsl:otherwise>
  33. <xsl:call-template name="gentext.template">
  34. <xsl:with-param name="context" select="'title-unnumbered'"/>
  35. <xsl:with-param name="name">
  36. <xsl:call-template name="xpath.location"/>
  37. </xsl:with-param>
  38. </xsl:call-template>
  39. </xsl:otherwise>
  40. </xsl:choose>
  41. </xsl:template>
  42. <xsl:template match="appendix" mode="object.title.template">
  43. <xsl:choose>
  44. <xsl:when test="string($appendix.autolabel) != 0">
  45. <xsl:call-template name="gentext.template">
  46. <xsl:with-param name="context" select="'title-numbered'"/>
  47. <xsl:with-param name="name">
  48. <xsl:call-template name="xpath.location"/>
  49. </xsl:with-param>
  50. </xsl:call-template>
  51. </xsl:when>
  52. <xsl:otherwise>
  53. <xsl:call-template name="gentext.template">
  54. <xsl:with-param name="context" select="'title-unnumbered'"/>
  55. <xsl:with-param name="name">
  56. <xsl:call-template name="xpath.location"/>
  57. </xsl:with-param>
  58. </xsl:call-template>
  59. </xsl:otherwise>
  60. </xsl:choose>
  61. </xsl:template>
  62. <xsl:template match="part" mode="object.title.template">
  63. <xsl:choose>
  64. <xsl:when test="string($part.autolabel) != 0">
  65. <xsl:call-template name="gentext.template">
  66. <xsl:with-param name="context" select="'title-numbered'"/>
  67. <xsl:with-param name="name">
  68. <xsl:call-template name="xpath.location"/>
  69. </xsl:with-param>
  70. </xsl:call-template>
  71. </xsl:when>
  72. <xsl:otherwise>
  73. <xsl:call-template name="gentext.template">
  74. <xsl:with-param name="context" select="'title-unnumbered'"/>
  75. <xsl:with-param name="name">
  76. <xsl:call-template name="xpath.location"/>
  77. </xsl:with-param>
  78. </xsl:call-template>
  79. </xsl:otherwise>
  80. </xsl:choose>
  81. </xsl:template>
  82. <xsl:template match="section|sect1|sect2|sect3|sect4|sect5|simplesect
  83. |bridgehead"
  84. mode="object.title.template">
  85. <xsl:variable name="is.numbered">
  86. <xsl:call-template name="label.this.section"/>
  87. </xsl:variable>
  88. <xsl:choose>
  89. <xsl:when test="$is.numbered != 0">
  90. <xsl:call-template name="gentext.template">
  91. <xsl:with-param name="context" select="'title-numbered'"/>
  92. <xsl:with-param name="name">
  93. <xsl:call-template name="xpath.location"/>
  94. </xsl:with-param>
  95. </xsl:call-template>
  96. </xsl:when>
  97. <xsl:otherwise>
  98. <xsl:call-template name="gentext.template">
  99. <xsl:with-param name="context" select="'title-unnumbered'"/>
  100. <xsl:with-param name="name">
  101. <xsl:call-template name="xpath.location"/>
  102. </xsl:with-param>
  103. </xsl:call-template>
  104. </xsl:otherwise>
  105. </xsl:choose>
  106. </xsl:template>
  107. <xsl:template match="procedure" mode="object.title.template">
  108. <xsl:choose>
  109. <xsl:when test="$formal.procedures != 0 and title">
  110. <xsl:call-template name="gentext.template">
  111. <xsl:with-param name="context" select="'title'"/>
  112. <xsl:with-param name="name">
  113. <xsl:call-template name="xpath.location"/>
  114. <xsl:text>.formal</xsl:text>
  115. </xsl:with-param>
  116. </xsl:call-template>
  117. </xsl:when>
  118. <xsl:otherwise>
  119. <xsl:call-template name="gentext.template">
  120. <xsl:with-param name="context" select="'title'"/>
  121. <xsl:with-param name="name">
  122. <xsl:call-template name="xpath.location"/>
  123. </xsl:with-param>
  124. </xsl:call-template>
  125. </xsl:otherwise>
  126. </xsl:choose>
  127. </xsl:template>
  128. <!-- ============================================================ -->
  129. <xsl:template match="*" mode="object.subtitle.template">
  130. <xsl:call-template name="gentext.template">
  131. <xsl:with-param name="context" select="'subtitle'"/>
  132. <xsl:with-param name="name">
  133. <xsl:call-template name="xpath.location"/>
  134. </xsl:with-param>
  135. </xsl:call-template>
  136. </xsl:template>
  137. <!-- ============================================================ -->
  138. <xsl:template match="*" mode="is.autonumber">
  139. <xsl:value-of select="'0'"/>
  140. </xsl:template>
  141. <xsl:template match="section|sect1|sect2|sect3|sect4|sect5"
  142. mode="is.autonumber">
  143. <xsl:call-template name="label.this.section"/>
  144. </xsl:template>
  145. <xsl:template match="figure|example|table|equation" mode="is.autonumber">
  146. <xsl:value-of select="'1'"/>
  147. </xsl:template>
  148. <xsl:template match="appendix" mode="is.autonumber">
  149. <xsl:value-of select="$appendix.autolabel"/>
  150. </xsl:template>
  151. <xsl:template match="chapter" mode="is.autonumber">
  152. <xsl:value-of select="$chapter.autolabel"/>
  153. </xsl:template>
  154. <xsl:template match="part" mode="is.autonumber">
  155. <xsl:value-of select="$part.autolabel"/>
  156. </xsl:template>
  157. <xsl:template match="preface" mode="is.autonumber">
  158. <xsl:value-of select="$preface.autolabel"/>
  159. </xsl:template>
  160. <xsl:template match="question|answer" mode="is.autonumber">
  161. <xsl:choose>
  162. <xsl:when test="$qanda.defaultlabel = 'number'
  163. and not(label)">
  164. <xsl:value-of select="'1'"/>
  165. </xsl:when>
  166. <xsl:otherwise>
  167. <xsl:value-of select="'0'"/>
  168. </xsl:otherwise>
  169. </xsl:choose>
  170. </xsl:template>
  171. <xsl:template match="qandadiv" mode="is.autonumber">
  172. <xsl:value-of select="$qandadiv.autolabel"/>
  173. </xsl:template>
  174. <xsl:template match="bridgehead" mode="is.autonumber">
  175. <xsl:value-of select="$section.autolabel"/>
  176. </xsl:template>
  177. <xsl:template match="*" mode="object.xref.template">
  178. <xsl:param name="purpose"/>
  179. <xsl:param name="xrefstyle"/>
  180. <xsl:param name="referrer"/>
  181. <!-- Is autonumbering on? -->
  182. <xsl:variable name="autonumber">
  183. <xsl:apply-templates select="." mode="is.autonumber"/>
  184. </xsl:variable>
  185. <xsl:variable name="number-and-title-template">
  186. <xsl:call-template name="gentext.template.exists">
  187. <xsl:with-param name="context" select="'xref-number-and-title'"/>
  188. <xsl:with-param name="name">
  189. <xsl:call-template name="xpath.location"/>
  190. </xsl:with-param>
  191. </xsl:call-template>
  192. </xsl:variable>
  193. <xsl:variable name="number-template">
  194. <xsl:call-template name="gentext.template.exists">
  195. <xsl:with-param name="context" select="'xref-number'"/>
  196. <xsl:with-param name="name">
  197. <xsl:call-template name="xpath.location"/>
  198. </xsl:with-param>
  199. </xsl:call-template>
  200. </xsl:variable>
  201. <xsl:variable name="context">
  202. <xsl:choose>
  203. <xsl:when test="string($autonumber) != 0
  204. and $number-and-title-template != 0
  205. and $xref.with.number.and.title != 0">
  206. <xsl:value-of select="'xref-number-and-title'"/>
  207. </xsl:when>
  208. <xsl:when test="string($autonumber) != 0
  209. and $number-template != 0">
  210. <xsl:value-of select="'xref-number'"/>
  211. </xsl:when>
  212. <xsl:otherwise>
  213. <xsl:value-of select="'xref'"/>
  214. </xsl:otherwise>
  215. </xsl:choose>
  216. </xsl:variable>
  217. <xsl:call-template name="gentext.template">
  218. <xsl:with-param name="context" select="$context"/>
  219. <xsl:with-param name="name">
  220. <xsl:call-template name="xpath.location"/>
  221. </xsl:with-param>
  222. <xsl:with-param name="purpose" select="$purpose"/>
  223. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  224. <xsl:with-param name="referrer" select="$referrer"/>
  225. </xsl:call-template>
  226. </xsl:template>
  227. <!-- ============================================================ -->
  228. <xsl:template match="*" mode="object.title.markup">
  229. <xsl:param name="allow-anchors" select="0"/>
  230. <xsl:variable name="template">
  231. <xsl:apply-templates select="." mode="object.title.template"/>
  232. </xsl:variable>
  233. <!--
  234. <xsl:message>
  235. <xsl:text>object.title.markup: </xsl:text>
  236. <xsl:value-of select="local-name(.)"/>
  237. <xsl:text>: </xsl:text>
  238. <xsl:value-of select="$template"/>
  239. </xsl:message>
  240. -->
  241. <xsl:call-template name="substitute-markup">
  242. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  243. <xsl:with-param name="template" select="$template"/>
  244. </xsl:call-template>
  245. </xsl:template>
  246. <xsl:template match="*" mode="object.title.markup.textonly">
  247. <xsl:variable name="title">
  248. <xsl:apply-templates select="." mode="object.title.markup"/>
  249. </xsl:variable>
  250. <xsl:value-of select="normalize-space($title)"/>
  251. </xsl:template>
  252. <!-- ============================================================ -->
  253. <xsl:template match="*" mode="object.titleabbrev.markup">
  254. <xsl:param name="allow-anchors" select="0"/>
  255. <!-- Just for consistency in template naming -->
  256. <xsl:apply-templates select="." mode="titleabbrev.markup">
  257. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  258. </xsl:apply-templates>
  259. </xsl:template>
  260. <!-- ============================================================ -->
  261. <xsl:template match="*" mode="object.subtitle.markup">
  262. <xsl:variable name="template">
  263. <xsl:apply-templates select="." mode="object.subtitle.template"/>
  264. </xsl:variable>
  265. <xsl:call-template name="substitute-markup">
  266. <xsl:with-param name="template" select="$template"/>
  267. </xsl:call-template>
  268. </xsl:template>
  269. <!-- ============================================================ -->
  270. <xsl:template match="*" mode="object.xref.markup">
  271. <xsl:param name="purpose"/>
  272. <xsl:param name="xrefstyle"/>
  273. <xsl:param name="referrer"/>
  274. <xsl:param name="verbose" select="1"/>
  275. <xsl:variable name="template">
  276. <xsl:choose>
  277. <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')">
  278. <xsl:call-template name="make.gentext.template">
  279. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  280. <xsl:with-param name="purpose" select="$purpose"/>
  281. <xsl:with-param name="referrer" select="$referrer"/>
  282. </xsl:call-template>
  283. </xsl:when>
  284. <xsl:when test="starts-with(normalize-space($xrefstyle), 'template:')">
  285. <xsl:value-of select="substring-after(normalize-space($xrefstyle), 'template:')"/>
  286. </xsl:when>
  287. <xsl:otherwise>
  288. <xsl:apply-templates select="." mode="object.xref.template">
  289. <xsl:with-param name="purpose" select="$purpose"/>
  290. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  291. <xsl:with-param name="referrer" select="$referrer"/>
  292. </xsl:apply-templates>
  293. </xsl:otherwise>
  294. </xsl:choose>
  295. </xsl:variable>
  296. <!--
  297. <xsl:message>
  298. <xsl:text>object.xref.markup: </xsl:text>
  299. <xsl:value-of select="local-name(.)"/>
  300. <xsl:text>(</xsl:text>
  301. <xsl:value-of select="$xrefstyle"/>
  302. <xsl:text>, </xsl:text>
  303. <xsl:value-of select="$purpose"/>
  304. <xsl:text>)</xsl:text>
  305. <xsl:text>: [</xsl:text>
  306. <xsl:value-of select="$template"/>
  307. <xsl:text>]</xsl:text>
  308. </xsl:message>
  309. -->
  310. <xsl:if test="$template = '' and $verbose != 0">
  311. <xsl:message>
  312. <xsl:text>object.xref.markup: empty xref template</xsl:text>
  313. <xsl:text> for linkend="</xsl:text>
  314. <xsl:value-of select="@id|@xml:id"/>
  315. <xsl:text>" and @xrefstyle="</xsl:text>
  316. <xsl:value-of select="$xrefstyle"/>
  317. <xsl:text>"</xsl:text>
  318. </xsl:message>
  319. </xsl:if>
  320. <xsl:call-template name="substitute-markup">
  321. <xsl:with-param name="purpose" select="$purpose"/>
  322. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  323. <xsl:with-param name="referrer" select="$referrer"/>
  324. <xsl:with-param name="template" select="$template"/>
  325. <xsl:with-param name="verbose" select="$verbose"/>
  326. </xsl:call-template>
  327. </xsl:template>
  328. <xsl:template match="listitem" mode="object.xref.markup">
  329. <xsl:param name="verbose" select="1"/>
  330. <xsl:choose>
  331. <xsl:when test="parent::orderedlist">
  332. <xsl:variable name="template">
  333. <xsl:apply-templates select="." mode="object.xref.template"/>
  334. </xsl:variable>
  335. <xsl:call-template name="substitute-markup">
  336. <xsl:with-param name="template" select="$template"/>
  337. </xsl:call-template>
  338. </xsl:when>
  339. <xsl:when test="$verbose != 0">
  340. <xsl:message>
  341. <xsl:text>Xref is only supported to listitems in an</xsl:text>
  342. <xsl:text> orderedlist: </xsl:text>
  343. <xsl:value-of select="@id|@xml:id"/>
  344. </xsl:message>
  345. <xsl:text>???</xsl:text>
  346. </xsl:when>
  347. </xsl:choose>
  348. </xsl:template>
  349. <xsl:template match="question" mode="object.xref.markup">
  350. <xsl:param name="purpose"/>
  351. <xsl:param name="xrefstyle"/>
  352. <xsl:param name="referrer"/>
  353. <xsl:variable name="deflabel">
  354. <xsl:choose>
  355. <xsl:when test="ancestor-or-self::*[@defaultlabel]">
  356. <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
  357. /@defaultlabel"/>
  358. </xsl:when>
  359. <xsl:otherwise>
  360. <xsl:value-of select="$qanda.defaultlabel"/>
  361. </xsl:otherwise>
  362. </xsl:choose>
  363. </xsl:variable>
  364. <xsl:variable name="template">
  365. <xsl:choose>
  366. <!-- This avoids double Q: Q: in xref when defaultlabel=qanda -->
  367. <xsl:when test="$deflabel = 'qanda' and not(label)">%n</xsl:when>
  368. <xsl:otherwise>
  369. <xsl:apply-templates select="." mode="object.xref.template">
  370. <xsl:with-param name="purpose" select="$purpose"/>
  371. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  372. <xsl:with-param name="referrer" select="$referrer"/>
  373. </xsl:apply-templates>
  374. </xsl:otherwise>
  375. </xsl:choose>
  376. </xsl:variable>
  377. <xsl:call-template name="substitute-markup">
  378. <xsl:with-param name="purpose" select="$purpose"/>
  379. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  380. <xsl:with-param name="referrer" select="$referrer"/>
  381. <xsl:with-param name="template" select="$template"/>
  382. </xsl:call-template>
  383. </xsl:template>
  384. <!-- ============================================================ -->
  385. <xsl:template name="substitute-markup">
  386. <xsl:param name="template" select="''"/>
  387. <xsl:param name="allow-anchors" select="'0'"/>
  388. <xsl:param name="title" select="''"/>
  389. <xsl:param name="subtitle" select="''"/>
  390. <xsl:param name="docname" select="''"/>
  391. <xsl:param name="label" select="''"/>
  392. <xsl:param name="pagenumber" select="''"/>
  393. <xsl:param name="purpose"/>
  394. <xsl:param name="xrefstyle"/>
  395. <xsl:param name="referrer"/>
  396. <xsl:param name="verbose"/>
  397. <xsl:choose>
  398. <xsl:when test="contains($template, '%')">
  399. <xsl:value-of select="substring-before($template, '%')"/>
  400. <xsl:variable name="candidate"
  401. select="substring(substring-after($template, '%'), 1, 1)"/>
  402. <xsl:choose>
  403. <xsl:when test="$candidate = 't'">
  404. <xsl:apply-templates select="." mode="insert.title.markup">
  405. <xsl:with-param name="purpose" select="$purpose"/>
  406. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  407. <xsl:with-param name="title">
  408. <xsl:choose>
  409. <xsl:when test="$title != ''">
  410. <xsl:copy-of select="$title"/>
  411. </xsl:when>
  412. <xsl:otherwise>
  413. <xsl:apply-templates select="." mode="title.markup">
  414. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  415. <xsl:with-param name="verbose" select="$verbose"/>
  416. </xsl:apply-templates>
  417. </xsl:otherwise>
  418. </xsl:choose>
  419. </xsl:with-param>
  420. </xsl:apply-templates>
  421. </xsl:when>
  422. <xsl:when test="$candidate = 's'">
  423. <xsl:apply-templates select="." mode="insert.subtitle.markup">
  424. <xsl:with-param name="purpose" select="$purpose"/>
  425. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  426. <xsl:with-param name="subtitle">
  427. <xsl:choose>
  428. <xsl:when test="$subtitle != ''">
  429. <xsl:copy-of select="$subtitle"/>
  430. </xsl:when>
  431. <xsl:otherwise>
  432. <xsl:apply-templates select="." mode="subtitle.markup">
  433. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  434. </xsl:apply-templates>
  435. </xsl:otherwise>
  436. </xsl:choose>
  437. </xsl:with-param>
  438. </xsl:apply-templates>
  439. </xsl:when>
  440. <xsl:when test="$candidate = 'n'">
  441. <xsl:apply-templates select="." mode="insert.label.markup">
  442. <xsl:with-param name="purpose" select="$purpose"/>
  443. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  444. <xsl:with-param name="label">
  445. <xsl:choose>
  446. <xsl:when test="$label != ''">
  447. <xsl:copy-of select="$label"/>
  448. </xsl:when>
  449. <xsl:otherwise>
  450. <xsl:apply-templates select="." mode="label.markup"/>
  451. </xsl:otherwise>
  452. </xsl:choose>
  453. </xsl:with-param>
  454. </xsl:apply-templates>
  455. </xsl:when>
  456. <xsl:when test="$candidate = 'p'">
  457. <xsl:apply-templates select="." mode="insert.pagenumber.markup">
  458. <xsl:with-param name="purpose" select="$purpose"/>
  459. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  460. <xsl:with-param name="pagenumber">
  461. <xsl:choose>
  462. <xsl:when test="$pagenumber != ''">
  463. <xsl:copy-of select="$pagenumber"/>
  464. </xsl:when>
  465. <xsl:otherwise>
  466. <xsl:apply-templates select="." mode="pagenumber.markup"/>
  467. </xsl:otherwise>
  468. </xsl:choose>
  469. </xsl:with-param>
  470. </xsl:apply-templates>
  471. </xsl:when>
  472. <xsl:when test="$candidate = 'o'">
  473. <!-- olink target document title -->
  474. <xsl:apply-templates select="." mode="insert.olink.docname.markup">
  475. <xsl:with-param name="purpose" select="$purpose"/>
  476. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  477. <xsl:with-param name="docname">
  478. <xsl:choose>
  479. <xsl:when test="$docname != ''">
  480. <xsl:copy-of select="$docname"/>
  481. </xsl:when>
  482. <xsl:otherwise>
  483. <xsl:apply-templates select="." mode="olink.docname.markup"/>
  484. </xsl:otherwise>
  485. </xsl:choose>
  486. </xsl:with-param>
  487. </xsl:apply-templates>
  488. </xsl:when>
  489. <xsl:when test="$candidate = 'd'">
  490. <xsl:apply-templates select="." mode="insert.direction.markup">
  491. <xsl:with-param name="purpose" select="$purpose"/>
  492. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  493. <xsl:with-param name="direction">
  494. <xsl:choose>
  495. <xsl:when test="$referrer">
  496. <xsl:variable name="referent-is-below">
  497. <xsl:for-each select="preceding::xref">
  498. <xsl:if test="generate-id(.) = generate-id($referrer)">1</xsl:if>
  499. </xsl:for-each>
  500. </xsl:variable>
  501. <xsl:choose>
  502. <xsl:when test="$referent-is-below = ''">
  503. <xsl:call-template name="gentext">
  504. <xsl:with-param name="key" select="'above'"/>
  505. </xsl:call-template>
  506. </xsl:when>
  507. <xsl:otherwise>
  508. <xsl:call-template name="gentext">
  509. <xsl:with-param name="key" select="'below'"/>
  510. </xsl:call-template>
  511. </xsl:otherwise>
  512. </xsl:choose>
  513. </xsl:when>
  514. <xsl:otherwise>
  515. <xsl:message>Attempt to use %d in gentext with no referrer!</xsl:message>
  516. </xsl:otherwise>
  517. </xsl:choose>
  518. </xsl:with-param>
  519. </xsl:apply-templates>
  520. </xsl:when>
  521. <xsl:when test="$candidate = '%' ">
  522. <xsl:text>%</xsl:text>
  523. </xsl:when>
  524. <xsl:otherwise>
  525. <xsl:text>%</xsl:text><xsl:value-of select="$candidate"/>
  526. </xsl:otherwise>
  527. </xsl:choose>
  528. <!-- recurse with the rest of the template string -->
  529. <xsl:variable name="rest"
  530. select="substring($template,
  531. string-length(substring-before($template, '%'))+3)"/>
  532. <xsl:call-template name="substitute-markup">
  533. <xsl:with-param name="template" select="$rest"/>
  534. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  535. <xsl:with-param name="title" select="$title"/>
  536. <xsl:with-param name="subtitle" select="$subtitle"/>
  537. <xsl:with-param name="docname" select="$docname"/>
  538. <xsl:with-param name="label" select="$label"/>
  539. <xsl:with-param name="pagenumber" select="$pagenumber"/>
  540. <xsl:with-param name="purpose" select="$purpose"/>
  541. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  542. <xsl:with-param name="referrer" select="$referrer"/>
  543. <xsl:with-param name="verbose" select="$verbose"/>
  544. </xsl:call-template>
  545. </xsl:when>
  546. <xsl:otherwise>
  547. <xsl:value-of select="$template"/>
  548. </xsl:otherwise>
  549. </xsl:choose>
  550. </xsl:template>
  551. <!-- ============================================================ -->
  552. <xsl:template name="make.gentext.template">
  553. <xsl:param name="xrefstyle" select="''"/>
  554. <xsl:param name="purpose"/>
  555. <xsl:param name="referrer"/>
  556. <xsl:param name="lang">
  557. <xsl:call-template name="l10n.language"/>
  558. </xsl:param>
  559. <xsl:param name="target.elem" select="local-name(.)"/>
  560. <!-- parse xrefstyle to get parts -->
  561. <xsl:variable name="parts"
  562. select="substring-after(normalize-space($xrefstyle), 'select:')"/>
  563. <xsl:variable name="labeltype">
  564. <xsl:choose>
  565. <xsl:when test="contains($parts, 'labelnumber')">
  566. <xsl:text>labelnumber</xsl:text>
  567. </xsl:when>
  568. <xsl:when test="contains($parts, 'labelname')">
  569. <xsl:text>labelname</xsl:text>
  570. </xsl:when>
  571. <xsl:when test="contains($parts, 'label')">
  572. <xsl:text>label</xsl:text>
  573. </xsl:when>
  574. </xsl:choose>
  575. </xsl:variable>
  576. <xsl:variable name="titletype">
  577. <xsl:choose>
  578. <xsl:when test="contains($parts, 'quotedtitle')">
  579. <xsl:text>quotedtitle</xsl:text>
  580. </xsl:when>
  581. <xsl:when test="contains($parts, 'title')">
  582. <xsl:text>title</xsl:text>
  583. </xsl:when>
  584. </xsl:choose>
  585. </xsl:variable>
  586. <xsl:variable name="pagetype">
  587. <xsl:choose>
  588. <xsl:when test="$insert.olink.page.number = 'no' and
  589. local-name($referrer) = 'olink'">
  590. <!-- suppress page numbers -->
  591. </xsl:when>
  592. <xsl:when test="$insert.xref.page.number = 'no' and
  593. local-name($referrer) != 'olink'">
  594. <!-- suppress page numbers -->
  595. </xsl:when>
  596. <xsl:when test="contains($parts, 'nopage')">
  597. <xsl:text>nopage</xsl:text>
  598. </xsl:when>
  599. <xsl:when test="contains($parts, 'pagenumber')">
  600. <xsl:text>pagenumber</xsl:text>
  601. </xsl:when>
  602. <xsl:when test="contains($parts, 'pageabbrev')">
  603. <xsl:text>pageabbrev</xsl:text>
  604. </xsl:when>
  605. <xsl:when test="contains($parts, 'Page')">
  606. <xsl:text>Page</xsl:text>
  607. </xsl:when>
  608. <xsl:when test="contains($parts, 'page')">
  609. <xsl:text>page</xsl:text>
  610. </xsl:when>
  611. </xsl:choose>
  612. </xsl:variable>
  613. <xsl:variable name="docnametype">
  614. <xsl:choose>
  615. <xsl:when test="($olink.doctitle = 0 or
  616. $olink.doctitle = 'no') and
  617. local-name($referrer) = 'olink'">
  618. <!-- suppress docname -->
  619. </xsl:when>
  620. <xsl:when test="contains($parts, 'nodocname')">
  621. <xsl:text>nodocname</xsl:text>
  622. </xsl:when>
  623. <xsl:when test="contains($parts, 'docnamelong')">
  624. <xsl:text>docnamelong</xsl:text>
  625. </xsl:when>
  626. <xsl:when test="contains($parts, 'docname')">
  627. <xsl:text>docname</xsl:text>
  628. </xsl:when>
  629. </xsl:choose>
  630. </xsl:variable>
  631. <xsl:if test="$labeltype != ''">
  632. <xsl:choose>
  633. <xsl:when test="$labeltype = 'labelname'">
  634. <xsl:call-template name="gentext">
  635. <xsl:with-param name="key">
  636. <xsl:choose>
  637. <xsl:when test="local-name($referrer) = 'olink'">
  638. <xsl:value-of select="$target.elem"/>
  639. </xsl:when>
  640. <xsl:otherwise>
  641. <xsl:value-of select="local-name(.)"/>
  642. </xsl:otherwise>
  643. </xsl:choose>
  644. </xsl:with-param>
  645. </xsl:call-template>
  646. </xsl:when>
  647. <xsl:when test="$labeltype = 'labelnumber'">
  648. <xsl:text>%n</xsl:text>
  649. </xsl:when>
  650. <xsl:when test="$labeltype = 'label'">
  651. <xsl:call-template name="gentext.template">
  652. <xsl:with-param name="context" select="'xref-number'"/>
  653. <xsl:with-param name="name">
  654. <xsl:choose>
  655. <xsl:when test="local-name($referrer) = 'olink'">
  656. <xsl:value-of select="$target.elem"/>
  657. </xsl:when>
  658. <xsl:otherwise>
  659. <xsl:call-template name="xpath.location"/>
  660. </xsl:otherwise>
  661. </xsl:choose>
  662. </xsl:with-param>
  663. <xsl:with-param name="purpose" select="$purpose"/>
  664. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  665. <xsl:with-param name="referrer" select="$referrer"/>
  666. </xsl:call-template>
  667. </xsl:when>
  668. </xsl:choose>
  669. <xsl:choose>
  670. <xsl:when test="$titletype != ''">
  671. <xsl:value-of select="$xref.label-title.separator"/>
  672. </xsl:when>
  673. <xsl:when test="$pagetype != ''">
  674. <xsl:value-of select="$xref.label-page.separator"/>
  675. </xsl:when>
  676. </xsl:choose>
  677. </xsl:if>
  678. <xsl:if test="$titletype != ''">
  679. <xsl:choose>
  680. <xsl:when test="$titletype = 'title'">
  681. <xsl:text>%t</xsl:text>
  682. </xsl:when>
  683. <xsl:when test="$titletype = 'quotedtitle'">
  684. <xsl:call-template name="gentext.dingbat">
  685. <xsl:with-param name="dingbat" select="'startquote'"/>
  686. </xsl:call-template>
  687. <xsl:text>%t</xsl:text>
  688. <xsl:call-template name="gentext.dingbat">
  689. <xsl:with-param name="dingbat" select="'endquote'"/>
  690. </xsl:call-template>
  691. </xsl:when>
  692. </xsl:choose>
  693. <xsl:choose>
  694. <xsl:when test="$pagetype != '' and $pagetype != 'nopage'">
  695. <xsl:value-of select="$xref.title-page.separator"/>
  696. </xsl:when>
  697. </xsl:choose>
  698. </xsl:if>
  699. <!-- special case: use regular xref template if just turning off page -->
  700. <xsl:if test="($pagetype = 'nopage' or $docnametype = 'nodocname')
  701. and local-name($referrer) != 'olink'
  702. and $labeltype = ''
  703. and $titletype = ''">
  704. <xsl:apply-templates select="." mode="object.xref.template">
  705. <xsl:with-param name="purpose" select="$purpose"/>
  706. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  707. <xsl:with-param name="referrer" select="$referrer"/>
  708. </xsl:apply-templates>
  709. </xsl:if>
  710. <xsl:if test="$pagetype != ''">
  711. <xsl:choose>
  712. <xsl:when test="$pagetype = 'page'">
  713. <xsl:call-template name="gentext.template">
  714. <xsl:with-param name="context" select="'xref'"/>
  715. <xsl:with-param name="name" select="'page'"/>
  716. </xsl:call-template>
  717. </xsl:when>
  718. <xsl:when test="$pagetype = 'Page'">
  719. <xsl:call-template name="gentext.template">
  720. <xsl:with-param name="context" select="'xref'"/>
  721. <xsl:with-param name="name" select="'Page'"/>
  722. </xsl:call-template>
  723. </xsl:when>
  724. <xsl:when test="$pagetype = 'pageabbrev'">
  725. <xsl:call-template name="gentext.template">
  726. <xsl:with-param name="context" select="'xref'"/>
  727. <xsl:with-param name="name" select="'pageabbrev'"/>
  728. </xsl:call-template>
  729. </xsl:when>
  730. <xsl:when test="$pagetype = 'pagenumber'">
  731. <xsl:text>%p</xsl:text>
  732. </xsl:when>
  733. </xsl:choose>
  734. </xsl:if>
  735. <!-- Add reference to other document title -->
  736. <xsl:if test="$docnametype != '' and local-name($referrer) = 'olink'">
  737. <!-- Any separator should be in the gentext template -->
  738. <xsl:choose>
  739. <xsl:when test="$docnametype = 'docnamelong'">
  740. <xsl:call-template name="gentext.template">
  741. <xsl:with-param name="context" select="'xref'"/>
  742. <xsl:with-param name="name" select="'docnamelong'"/>
  743. </xsl:call-template>
  744. </xsl:when>
  745. <xsl:when test="$docnametype = 'docname'">
  746. <xsl:call-template name="gentext.template">
  747. <xsl:with-param name="context" select="'xref'"/>
  748. <xsl:with-param name="name" select="'docname'"/>
  749. </xsl:call-template>
  750. </xsl:when>
  751. </xsl:choose>
  752. </xsl:if>
  753. </xsl:template>
  754. </xsl:stylesheet>