gentext.xsl 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  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: gentext.xsl 9713 2013-01-22 22:08:30Z bobstayton $
  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|topic"
  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. <!-- bridgeheads are not numbered -->
  176. <xsl:text>0</xsl:text>
  177. </xsl:template>
  178. <xsl:template match="procedure" mode="is.autonumber">
  179. <xsl:value-of select="$formal.procedures"/>
  180. </xsl:template>
  181. <xsl:template match="*" mode="object.xref.template">
  182. <xsl:param name="purpose"/>
  183. <xsl:param name="xrefstyle"/>
  184. <xsl:param name="referrer"/>
  185. <!-- Is autonumbering on? -->
  186. <xsl:variable name="autonumber">
  187. <xsl:apply-templates select="." mode="is.autonumber"/>
  188. </xsl:variable>
  189. <xsl:variable name="number-and-title-template">
  190. <xsl:call-template name="gentext.template.exists">
  191. <xsl:with-param name="context" select="'xref-number-and-title'"/>
  192. <xsl:with-param name="name">
  193. <xsl:call-template name="xpath.location"/>
  194. </xsl:with-param>
  195. </xsl:call-template>
  196. </xsl:variable>
  197. <xsl:variable name="number-template">
  198. <xsl:call-template name="gentext.template.exists">
  199. <xsl:with-param name="context" select="'xref-number'"/>
  200. <xsl:with-param name="name">
  201. <xsl:call-template name="xpath.location"/>
  202. </xsl:with-param>
  203. </xsl:call-template>
  204. </xsl:variable>
  205. <xsl:variable name="context">
  206. <xsl:choose>
  207. <xsl:when test="self::equation and not(title) and not(info/title)">
  208. <xsl:value-of select="'xref-number'"/>
  209. </xsl:when>
  210. <xsl:when test="string($autonumber) != 0
  211. and $number-and-title-template != 0
  212. and $xref.with.number.and.title != 0">
  213. <xsl:value-of select="'xref-number-and-title'"/>
  214. </xsl:when>
  215. <xsl:when test="string($autonumber) != 0
  216. and $number-template != 0">
  217. <xsl:value-of select="'xref-number'"/>
  218. </xsl:when>
  219. <xsl:otherwise>
  220. <xsl:value-of select="'xref'"/>
  221. </xsl:otherwise>
  222. </xsl:choose>
  223. </xsl:variable>
  224. <xsl:call-template name="gentext.template">
  225. <xsl:with-param name="context" select="$context"/>
  226. <xsl:with-param name="name">
  227. <xsl:call-template name="xpath.location"/>
  228. </xsl:with-param>
  229. <xsl:with-param name="purpose" select="$purpose"/>
  230. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  231. <xsl:with-param name="referrer" select="$referrer"/>
  232. </xsl:call-template>
  233. </xsl:template>
  234. <!-- ============================================================ -->
  235. <xsl:template match="*" mode="object.title.markup">
  236. <xsl:param name="allow-anchors" select="0"/>
  237. <xsl:variable name="template">
  238. <xsl:apply-templates select="." mode="object.title.template"/>
  239. </xsl:variable>
  240. <!--
  241. <xsl:message>
  242. <xsl:text>object.title.markup: </xsl:text>
  243. <xsl:value-of select="local-name(.)"/>
  244. <xsl:text>: </xsl:text>
  245. <xsl:value-of select="$template"/>
  246. </xsl:message>
  247. -->
  248. <xsl:call-template name="substitute-markup">
  249. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  250. <xsl:with-param name="template" select="$template"/>
  251. </xsl:call-template>
  252. </xsl:template>
  253. <xsl:template match="*" mode="object.title.markup.textonly">
  254. <xsl:variable name="title">
  255. <xsl:apply-templates select="." mode="object.title.markup"/>
  256. </xsl:variable>
  257. <xsl:value-of select="normalize-space($title)"/>
  258. </xsl:template>
  259. <!-- ============================================================ -->
  260. <xsl:template match="*" mode="object.titleabbrev.markup">
  261. <xsl:param name="allow-anchors" select="0"/>
  262. <!-- Just for consistency in template naming -->
  263. <xsl:apply-templates select="." mode="titleabbrev.markup">
  264. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  265. </xsl:apply-templates>
  266. </xsl:template>
  267. <!-- ============================================================ -->
  268. <xsl:template match="*" mode="object.subtitle.markup">
  269. <xsl:variable name="template">
  270. <xsl:apply-templates select="." mode="object.subtitle.template"/>
  271. </xsl:variable>
  272. <xsl:call-template name="substitute-markup">
  273. <xsl:with-param name="template" select="$template"/>
  274. </xsl:call-template>
  275. </xsl:template>
  276. <!-- ============================================================ -->
  277. <xsl:template match="*" mode="object.xref.markup">
  278. <xsl:param name="purpose"/>
  279. <xsl:param name="xrefstyle"/>
  280. <xsl:param name="referrer"/>
  281. <xsl:param name="verbose" select="1"/>
  282. <xsl:variable name="template">
  283. <xsl:choose>
  284. <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')">
  285. <xsl:call-template name="make.gentext.template">
  286. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  287. <xsl:with-param name="purpose" select="$purpose"/>
  288. <xsl:with-param name="referrer" select="$referrer"/>
  289. </xsl:call-template>
  290. </xsl:when>
  291. <xsl:when test="starts-with(normalize-space($xrefstyle), 'template:')">
  292. <xsl:value-of select="substring-after(normalize-space($xrefstyle), 'template:')"/>
  293. </xsl:when>
  294. <xsl:otherwise>
  295. <xsl:apply-templates select="." mode="object.xref.template">
  296. <xsl:with-param name="purpose" select="$purpose"/>
  297. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  298. <xsl:with-param name="referrer" select="$referrer"/>
  299. </xsl:apply-templates>
  300. </xsl:otherwise>
  301. </xsl:choose>
  302. </xsl:variable>
  303. <!--
  304. <xsl:message>
  305. <xsl:text>object.xref.markup: </xsl:text>
  306. <xsl:value-of select="local-name(.)"/>
  307. <xsl:text>(</xsl:text>
  308. <xsl:value-of select="$xrefstyle"/>
  309. <xsl:text>, </xsl:text>
  310. <xsl:value-of select="$purpose"/>
  311. <xsl:text>)</xsl:text>
  312. <xsl:text>: [</xsl:text>
  313. <xsl:value-of select="$template"/>
  314. <xsl:text>]</xsl:text>
  315. </xsl:message>
  316. -->
  317. <xsl:if test="$template = '' and $verbose != 0">
  318. <xsl:message>
  319. <xsl:text>object.xref.markup: empty xref template</xsl:text>
  320. <xsl:text> for linkend="</xsl:text>
  321. <xsl:value-of select="@id|@xml:id"/>
  322. <xsl:text>" and @xrefstyle="</xsl:text>
  323. <xsl:value-of select="$xrefstyle"/>
  324. <xsl:text>"</xsl:text>
  325. </xsl:message>
  326. </xsl:if>
  327. <xsl:call-template name="substitute-markup">
  328. <xsl:with-param name="purpose" select="$purpose"/>
  329. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  330. <xsl:with-param name="referrer" select="$referrer"/>
  331. <xsl:with-param name="template" select="$template"/>
  332. <xsl:with-param name="verbose" select="$verbose"/>
  333. </xsl:call-template>
  334. </xsl:template>
  335. <xsl:template match="listitem" mode="object.xref.markup">
  336. <xsl:param name="verbose" select="1"/>
  337. <xsl:choose>
  338. <xsl:when test="parent::orderedlist">
  339. <xsl:variable name="template">
  340. <xsl:apply-templates select="." mode="object.xref.template"/>
  341. </xsl:variable>
  342. <xsl:call-template name="substitute-markup">
  343. <xsl:with-param name="template" select="$template"/>
  344. </xsl:call-template>
  345. </xsl:when>
  346. <xsl:when test="$verbose != 0">
  347. <xsl:message>
  348. <xsl:text>Xref is only supported to listitems in an</xsl:text>
  349. <xsl:text> orderedlist: </xsl:text>
  350. <xsl:value-of select=".//@id|.//@xml:id"/>
  351. </xsl:message>
  352. <xsl:text>???</xsl:text>
  353. </xsl:when>
  354. </xsl:choose>
  355. </xsl:template>
  356. <xsl:template match="question" mode="object.xref.markup">
  357. <xsl:param name="purpose"/>
  358. <xsl:param name="xrefstyle"/>
  359. <xsl:param name="referrer"/>
  360. <xsl:variable name="deflabel">
  361. <xsl:choose>
  362. <xsl:when test="ancestor-or-self::*[@defaultlabel]">
  363. <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
  364. /@defaultlabel"/>
  365. </xsl:when>
  366. <xsl:otherwise>
  367. <xsl:value-of select="$qanda.defaultlabel"/>
  368. </xsl:otherwise>
  369. </xsl:choose>
  370. </xsl:variable>
  371. <xsl:variable name="template">
  372. <xsl:choose>
  373. <!-- This avoids double Q: Q: in xref when defaultlabel=qanda -->
  374. <xsl:when test="$deflabel = 'qanda' and not(label)">%n</xsl:when>
  375. <xsl:otherwise>
  376. <xsl:apply-templates select="." mode="object.xref.template">
  377. <xsl:with-param name="purpose" select="$purpose"/>
  378. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  379. <xsl:with-param name="referrer" select="$referrer"/>
  380. </xsl:apply-templates>
  381. </xsl:otherwise>
  382. </xsl:choose>
  383. </xsl:variable>
  384. <xsl:call-template name="substitute-markup">
  385. <xsl:with-param name="purpose" select="$purpose"/>
  386. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  387. <xsl:with-param name="referrer" select="$referrer"/>
  388. <xsl:with-param name="template" select="$template"/>
  389. </xsl:call-template>
  390. </xsl:template>
  391. <!-- ============================================================ -->
  392. <xsl:template name="substitute-markup">
  393. <xsl:param name="template" select="''"/>
  394. <xsl:param name="allow-anchors" select="'0'"/>
  395. <xsl:param name="title" select="''"/>
  396. <xsl:param name="subtitle" select="''"/>
  397. <xsl:param name="docname" select="''"/>
  398. <xsl:param name="label" select="''"/>
  399. <xsl:param name="pagenumber" select="''"/>
  400. <xsl:param name="purpose"/>
  401. <xsl:param name="xrefstyle"/>
  402. <xsl:param name="referrer"/>
  403. <xsl:param name="verbose"/>
  404. <xsl:choose>
  405. <xsl:when test="contains($template, '%')">
  406. <xsl:value-of select="substring-before($template, '%')"/>
  407. <xsl:variable name="candidate"
  408. select="substring(substring-after($template, '%'), 1, 1)"/>
  409. <xsl:choose>
  410. <xsl:when test="$candidate = 't'">
  411. <xsl:apply-templates select="." mode="insert.title.markup">
  412. <xsl:with-param name="purpose" select="$purpose"/>
  413. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  414. <xsl:with-param name="title">
  415. <xsl:choose>
  416. <xsl:when test="$title != ''">
  417. <xsl:copy-of select="$title"/>
  418. </xsl:when>
  419. <xsl:when test="$purpose = 'xref'">
  420. <xsl:apply-templates select="." mode="titleabbrev.markup">
  421. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  422. <xsl:with-param name="verbose" select="$verbose"/>
  423. </xsl:apply-templates>
  424. </xsl:when>
  425. <xsl:otherwise>
  426. <xsl:apply-templates select="." mode="title.markup">
  427. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  428. <xsl:with-param name="verbose" select="$verbose"/>
  429. </xsl:apply-templates>
  430. </xsl:otherwise>
  431. </xsl:choose>
  432. </xsl:with-param>
  433. </xsl:apply-templates>
  434. </xsl:when>
  435. <xsl:when test="$candidate = 's'">
  436. <xsl:apply-templates select="." mode="insert.subtitle.markup">
  437. <xsl:with-param name="purpose" select="$purpose"/>
  438. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  439. <xsl:with-param name="subtitle">
  440. <xsl:choose>
  441. <xsl:when test="$subtitle != ''">
  442. <xsl:copy-of select="$subtitle"/>
  443. </xsl:when>
  444. <xsl:otherwise>
  445. <xsl:apply-templates select="." mode="subtitle.markup">
  446. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  447. </xsl:apply-templates>
  448. </xsl:otherwise>
  449. </xsl:choose>
  450. </xsl:with-param>
  451. </xsl:apply-templates>
  452. </xsl:when>
  453. <xsl:when test="$candidate = 'n'">
  454. <xsl:apply-templates select="." mode="insert.label.markup">
  455. <xsl:with-param name="purpose" select="$purpose"/>
  456. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  457. <xsl:with-param name="label">
  458. <xsl:choose>
  459. <xsl:when test="$label != ''">
  460. <xsl:copy-of select="$label"/>
  461. </xsl:when>
  462. <xsl:otherwise>
  463. <xsl:apply-templates select="." mode="label.markup"/>
  464. </xsl:otherwise>
  465. </xsl:choose>
  466. </xsl:with-param>
  467. </xsl:apply-templates>
  468. </xsl:when>
  469. <xsl:when test="$candidate = 'p'">
  470. <xsl:apply-templates select="." mode="insert.pagenumber.markup">
  471. <xsl:with-param name="purpose" select="$purpose"/>
  472. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  473. <xsl:with-param name="pagenumber">
  474. <xsl:choose>
  475. <xsl:when test="$pagenumber != ''">
  476. <xsl:copy-of select="$pagenumber"/>
  477. </xsl:when>
  478. <xsl:otherwise>
  479. <xsl:apply-templates select="." mode="pagenumber.markup"/>
  480. </xsl:otherwise>
  481. </xsl:choose>
  482. </xsl:with-param>
  483. </xsl:apply-templates>
  484. </xsl:when>
  485. <xsl:when test="$candidate = 'o'">
  486. <!-- olink target document title -->
  487. <xsl:apply-templates select="." mode="insert.olink.docname.markup">
  488. <xsl:with-param name="purpose" select="$purpose"/>
  489. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  490. <xsl:with-param name="docname">
  491. <xsl:choose>
  492. <xsl:when test="$docname != ''">
  493. <xsl:copy-of select="$docname"/>
  494. </xsl:when>
  495. <xsl:otherwise>
  496. <xsl:apply-templates select="." mode="olink.docname.markup"/>
  497. </xsl:otherwise>
  498. </xsl:choose>
  499. </xsl:with-param>
  500. </xsl:apply-templates>
  501. </xsl:when>
  502. <xsl:when test="$candidate = 'd'">
  503. <xsl:apply-templates select="." mode="insert.direction.markup">
  504. <xsl:with-param name="purpose" select="$purpose"/>
  505. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  506. <xsl:with-param name="direction">
  507. <xsl:choose>
  508. <xsl:when test="$referrer">
  509. <xsl:variable name="referent-is-below">
  510. <xsl:for-each select="preceding::xref">
  511. <xsl:if test="generate-id(.) = generate-id($referrer)">1</xsl:if>
  512. </xsl:for-each>
  513. </xsl:variable>
  514. <xsl:choose>
  515. <xsl:when test="$referent-is-below = ''">
  516. <xsl:call-template name="gentext">
  517. <xsl:with-param name="key" select="'above'"/>
  518. </xsl:call-template>
  519. </xsl:when>
  520. <xsl:otherwise>
  521. <xsl:call-template name="gentext">
  522. <xsl:with-param name="key" select="'below'"/>
  523. </xsl:call-template>
  524. </xsl:otherwise>
  525. </xsl:choose>
  526. </xsl:when>
  527. <xsl:otherwise>
  528. <xsl:message>Attempt to use %d in gentext with no referrer!</xsl:message>
  529. </xsl:otherwise>
  530. </xsl:choose>
  531. </xsl:with-param>
  532. </xsl:apply-templates>
  533. </xsl:when>
  534. <xsl:when test="$candidate = '%' ">
  535. <xsl:text>%</xsl:text>
  536. </xsl:when>
  537. <xsl:otherwise>
  538. <xsl:text>%</xsl:text><xsl:value-of select="$candidate"/>
  539. </xsl:otherwise>
  540. </xsl:choose>
  541. <!-- recurse with the rest of the template string -->
  542. <xsl:variable name="rest"
  543. select="substring($template,
  544. string-length(substring-before($template, '%'))+3)"/>
  545. <xsl:call-template name="substitute-markup">
  546. <xsl:with-param name="template" select="$rest"/>
  547. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  548. <xsl:with-param name="title" select="$title"/>
  549. <xsl:with-param name="subtitle" select="$subtitle"/>
  550. <xsl:with-param name="docname" select="$docname"/>
  551. <xsl:with-param name="label" select="$label"/>
  552. <xsl:with-param name="pagenumber" select="$pagenumber"/>
  553. <xsl:with-param name="purpose" select="$purpose"/>
  554. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  555. <xsl:with-param name="referrer" select="$referrer"/>
  556. <xsl:with-param name="verbose" select="$verbose"/>
  557. </xsl:call-template>
  558. </xsl:when>
  559. <xsl:otherwise>
  560. <xsl:value-of select="$template"/>
  561. </xsl:otherwise>
  562. </xsl:choose>
  563. </xsl:template>
  564. <!-- ============================================================ -->
  565. <xsl:template name="make.gentext.template">
  566. <xsl:param name="xrefstyle" select="''"/>
  567. <xsl:param name="purpose"/>
  568. <xsl:param name="referrer"/>
  569. <xsl:param name="lang">
  570. <xsl:call-template name="l10n.language"/>
  571. </xsl:param>
  572. <xsl:param name="target.elem" select="local-name(.)"/>
  573. <!-- parse xrefstyle to get parts -->
  574. <xsl:variable name="parts"
  575. select="substring-after(normalize-space($xrefstyle), 'select:')"/>
  576. <xsl:variable name="labeltype">
  577. <xsl:choose>
  578. <xsl:when test="contains($parts, 'labelnumber')">
  579. <xsl:text>labelnumber</xsl:text>
  580. </xsl:when>
  581. <xsl:when test="contains($parts, 'labelname')">
  582. <xsl:text>labelname</xsl:text>
  583. </xsl:when>
  584. <xsl:when test="contains($parts, 'label')">
  585. <xsl:text>label</xsl:text>
  586. </xsl:when>
  587. </xsl:choose>
  588. </xsl:variable>
  589. <xsl:variable name="titletype">
  590. <xsl:choose>
  591. <xsl:when test="contains($parts, 'quotedtitle')">
  592. <xsl:text>quotedtitle</xsl:text>
  593. </xsl:when>
  594. <xsl:when test="contains($parts, 'title')">
  595. <xsl:text>title</xsl:text>
  596. </xsl:when>
  597. </xsl:choose>
  598. </xsl:variable>
  599. <xsl:variable name="pagetype">
  600. <xsl:choose>
  601. <xsl:when test="$insert.olink.page.number = 'no' and
  602. local-name($referrer) = 'olink'">
  603. <!-- suppress page numbers -->
  604. </xsl:when>
  605. <xsl:when test="$insert.xref.page.number = 'no' and
  606. local-name($referrer) != 'olink'">
  607. <!-- suppress page numbers -->
  608. </xsl:when>
  609. <xsl:when test="contains($parts, 'nopage')">
  610. <xsl:text>nopage</xsl:text>
  611. </xsl:when>
  612. <xsl:when test="contains($parts, 'pagenumber')">
  613. <xsl:text>pagenumber</xsl:text>
  614. </xsl:when>
  615. <xsl:when test="contains($parts, 'pageabbrev')">
  616. <xsl:text>pageabbrev</xsl:text>
  617. </xsl:when>
  618. <xsl:when test="contains($parts, 'Page')">
  619. <xsl:text>Page</xsl:text>
  620. </xsl:when>
  621. <xsl:when test="contains($parts, 'page')">
  622. <xsl:text>page</xsl:text>
  623. </xsl:when>
  624. </xsl:choose>
  625. </xsl:variable>
  626. <xsl:variable name="docnametype">
  627. <xsl:choose>
  628. <xsl:when test="($olink.doctitle = 0 or
  629. $olink.doctitle = 'no') and
  630. local-name($referrer) = 'olink'">
  631. <!-- suppress docname -->
  632. </xsl:when>
  633. <xsl:when test="contains($parts, 'nodocname')">
  634. <xsl:text>nodocname</xsl:text>
  635. </xsl:when>
  636. <xsl:when test="contains($parts, 'docnamelong')">
  637. <xsl:text>docnamelong</xsl:text>
  638. </xsl:when>
  639. <xsl:when test="contains($parts, 'docname')">
  640. <xsl:text>docname</xsl:text>
  641. </xsl:when>
  642. </xsl:choose>
  643. </xsl:variable>
  644. <xsl:if test="$labeltype != ''">
  645. <xsl:choose>
  646. <xsl:when test="$labeltype = 'labelname'">
  647. <xsl:call-template name="gentext">
  648. <xsl:with-param name="key">
  649. <xsl:choose>
  650. <xsl:when test="local-name($referrer) = 'olink'">
  651. <xsl:value-of select="$target.elem"/>
  652. </xsl:when>
  653. <xsl:otherwise>
  654. <xsl:value-of select="local-name(.)"/>
  655. </xsl:otherwise>
  656. </xsl:choose>
  657. </xsl:with-param>
  658. </xsl:call-template>
  659. </xsl:when>
  660. <xsl:when test="$labeltype = 'labelnumber'">
  661. <xsl:text>%n</xsl:text>
  662. </xsl:when>
  663. <xsl:when test="$labeltype = 'label'">
  664. <xsl:call-template name="gentext.template">
  665. <xsl:with-param name="context" select="'xref-number'"/>
  666. <xsl:with-param name="name">
  667. <xsl:choose>
  668. <xsl:when test="local-name($referrer) = 'olink'">
  669. <xsl:value-of select="$target.elem"/>
  670. </xsl:when>
  671. <xsl:otherwise>
  672. <xsl:call-template name="xpath.location"/>
  673. </xsl:otherwise>
  674. </xsl:choose>
  675. </xsl:with-param>
  676. <xsl:with-param name="purpose" select="$purpose"/>
  677. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  678. <xsl:with-param name="referrer" select="$referrer"/>
  679. </xsl:call-template>
  680. </xsl:when>
  681. </xsl:choose>
  682. <xsl:choose>
  683. <xsl:when test="$titletype != ''">
  684. <xsl:value-of select="$xref.label-title.separator"/>
  685. </xsl:when>
  686. <xsl:when test="$pagetype != '' and $pagetype != 'nopage'">
  687. <xsl:value-of select="$xref.label-page.separator"/>
  688. </xsl:when>
  689. </xsl:choose>
  690. </xsl:if>
  691. <xsl:if test="$titletype != ''">
  692. <xsl:choose>
  693. <xsl:when test="$titletype = 'title'">
  694. <xsl:text>%t</xsl:text>
  695. </xsl:when>
  696. <xsl:when test="$titletype = 'quotedtitle'">
  697. <xsl:call-template name="gentext.dingbat">
  698. <xsl:with-param name="dingbat" select="'startquote'"/>
  699. </xsl:call-template>
  700. <xsl:text>%t</xsl:text>
  701. <xsl:call-template name="gentext.dingbat">
  702. <xsl:with-param name="dingbat" select="'endquote'"/>
  703. </xsl:call-template>
  704. </xsl:when>
  705. </xsl:choose>
  706. <xsl:choose>
  707. <xsl:when test="$pagetype != '' and $pagetype != 'nopage'">
  708. <xsl:value-of select="$xref.title-page.separator"/>
  709. </xsl:when>
  710. </xsl:choose>
  711. </xsl:if>
  712. <!-- special case: use regular xref template if just turning off page -->
  713. <xsl:if test="($pagetype = 'nopage' or $docnametype = 'nodocname')
  714. and local-name($referrer) != 'olink'
  715. and $labeltype = ''
  716. and $titletype = ''">
  717. <xsl:apply-templates select="." mode="object.xref.template">
  718. <xsl:with-param name="purpose" select="$purpose"/>
  719. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  720. <xsl:with-param name="referrer" select="$referrer"/>
  721. </xsl:apply-templates>
  722. </xsl:if>
  723. <xsl:if test="$pagetype != ''">
  724. <xsl:choose>
  725. <xsl:when test="$pagetype = 'page'">
  726. <xsl:call-template name="gentext.template">
  727. <xsl:with-param name="context" select="'xref'"/>
  728. <xsl:with-param name="name" select="'page'"/>
  729. </xsl:call-template>
  730. </xsl:when>
  731. <xsl:when test="$pagetype = 'Page'">
  732. <xsl:call-template name="gentext.template">
  733. <xsl:with-param name="context" select="'xref'"/>
  734. <xsl:with-param name="name" select="'Page'"/>
  735. </xsl:call-template>
  736. </xsl:when>
  737. <xsl:when test="$pagetype = 'pageabbrev'">
  738. <xsl:call-template name="gentext.template">
  739. <xsl:with-param name="context" select="'xref'"/>
  740. <xsl:with-param name="name" select="'pageabbrev'"/>
  741. </xsl:call-template>
  742. </xsl:when>
  743. <xsl:when test="$pagetype = 'pagenumber'">
  744. <xsl:text>%p</xsl:text>
  745. </xsl:when>
  746. </xsl:choose>
  747. </xsl:if>
  748. <!-- Add reference to other document title -->
  749. <xsl:if test="$docnametype != '' and local-name($referrer) = 'olink'">
  750. <!-- Any separator should be in the gentext template -->
  751. <xsl:choose>
  752. <xsl:when test="$docnametype = 'docnamelong'">
  753. <xsl:call-template name="gentext.template">
  754. <xsl:with-param name="context" select="'xref'"/>
  755. <xsl:with-param name="name" select="'docnamelong'"/>
  756. </xsl:call-template>
  757. </xsl:when>
  758. <xsl:when test="$docnametype = 'docname'">
  759. <xsl:call-template name="gentext.template">
  760. <xsl:with-param name="context" select="'xref'"/>
  761. <xsl:with-param name="name" select="'docname'"/>
  762. </xsl:call-template>
  763. </xsl:when>
  764. </xsl:choose>
  765. </xsl:if>
  766. </xsl:template>
  767. </xsl:stylesheet>