labels.xsl 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  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: labels.xsl 9706 2013-01-16 18:56:16Z 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. <!-- label markup -->
  15. <doc:mode mode="label.markup" xmlns="">
  16. <refpurpose>Provides access to element labels</refpurpose>
  17. <refdescription id="label.markup-desc">
  18. <para>Processing an element in the
  19. <literal role="mode">label.markup</literal> mode produces the
  20. element label.</para>
  21. <para>Trailing punctuation is not added to the label.
  22. </para>
  23. </refdescription>
  24. </doc:mode>
  25. <xsl:template match="*" mode="intralabel.punctuation">
  26. <xsl:text>.</xsl:text>
  27. </xsl:template>
  28. <xsl:template match="*" mode="label.markup">
  29. <xsl:param name="verbose" select="1"/>
  30. <xsl:if test="$verbose">
  31. <xsl:message>
  32. <xsl:text>Request for label of unexpected element: </xsl:text>
  33. <xsl:value-of select="local-name(.)"/>
  34. </xsl:message>
  35. </xsl:if>
  36. </xsl:template>
  37. <xsl:template match="set|book" mode="label.markup">
  38. <xsl:if test="@label">
  39. <xsl:value-of select="@label"/>
  40. </xsl:if>
  41. </xsl:template>
  42. <xsl:template match="part" mode="label.markup">
  43. <xsl:choose>
  44. <xsl:when test="@label">
  45. <xsl:value-of select="@label"/>
  46. </xsl:when>
  47. <xsl:when test="string($part.autolabel) != 0">
  48. <xsl:variable name="format">
  49. <xsl:call-template name="autolabel.format">
  50. <xsl:with-param name="format" select="$part.autolabel"/>
  51. </xsl:call-template>
  52. </xsl:variable>
  53. <xsl:number from="book" count="part" format="{$format}"/>
  54. </xsl:when>
  55. </xsl:choose>
  56. </xsl:template>
  57. <xsl:template match="partintro" mode="label.markup">
  58. <!-- no label -->
  59. </xsl:template>
  60. <xsl:template match="preface" mode="label.markup">
  61. <xsl:choose>
  62. <xsl:when test="@label">
  63. <xsl:value-of select="@label"/>
  64. </xsl:when>
  65. <xsl:when test="string($preface.autolabel) != 0">
  66. <xsl:if test="$component.label.includes.part.label != 0 and
  67. ancestor::part">
  68. <xsl:variable name="part.label">
  69. <xsl:apply-templates select="ancestor::part"
  70. mode="label.markup"/>
  71. </xsl:variable>
  72. <xsl:if test="$part.label != ''">
  73. <xsl:value-of select="$part.label"/>
  74. <xsl:apply-templates select="ancestor::part"
  75. mode="intralabel.punctuation"/>
  76. </xsl:if>
  77. </xsl:if>
  78. <xsl:variable name="format">
  79. <xsl:call-template name="autolabel.format">
  80. <xsl:with-param name="format" select="$preface.autolabel"/>
  81. </xsl:call-template>
  82. </xsl:variable>
  83. <xsl:choose>
  84. <xsl:when test="$label.from.part != 0 and ancestor::part">
  85. <xsl:number from="part" count="preface" format="{$format}" level="any"/>
  86. </xsl:when>
  87. <xsl:otherwise>
  88. <xsl:number from="book" count="preface" format="{$format}" level="any"/>
  89. </xsl:otherwise>
  90. </xsl:choose>
  91. </xsl:when>
  92. </xsl:choose>
  93. </xsl:template>
  94. <xsl:template match="chapter" mode="label.markup">
  95. <xsl:choose>
  96. <xsl:when test="@label">
  97. <xsl:value-of select="@label"/>
  98. </xsl:when>
  99. <xsl:when test="string($chapter.autolabel) != 0">
  100. <xsl:if test="$component.label.includes.part.label != 0 and
  101. ancestor::part">
  102. <xsl:variable name="part.label">
  103. <xsl:apply-templates select="ancestor::part"
  104. mode="label.markup"/>
  105. </xsl:variable>
  106. <xsl:if test="$part.label != ''">
  107. <xsl:value-of select="$part.label"/>
  108. <xsl:apply-templates select="ancestor::part"
  109. mode="intralabel.punctuation"/>
  110. </xsl:if>
  111. </xsl:if>
  112. <xsl:variable name="format">
  113. <xsl:call-template name="autolabel.format">
  114. <xsl:with-param name="format" select="$chapter.autolabel"/>
  115. </xsl:call-template>
  116. </xsl:variable>
  117. <xsl:choose>
  118. <xsl:when test="$label.from.part != 0 and ancestor::part">
  119. <xsl:number from="part" count="chapter" format="{$format}" level="any"/>
  120. </xsl:when>
  121. <xsl:otherwise>
  122. <xsl:number from="book" count="chapter" format="{$format}" level="any"/>
  123. </xsl:otherwise>
  124. </xsl:choose>
  125. </xsl:when>
  126. </xsl:choose>
  127. </xsl:template>
  128. <xsl:template match="appendix" mode="label.markup">
  129. <xsl:choose>
  130. <xsl:when test="@label">
  131. <xsl:value-of select="@label"/>
  132. </xsl:when>
  133. <xsl:when test="string($appendix.autolabel) != 0">
  134. <xsl:if test="$component.label.includes.part.label != 0 and
  135. ancestor::part">
  136. <xsl:variable name="part.label">
  137. <xsl:apply-templates select="ancestor::part"
  138. mode="label.markup"/>
  139. </xsl:variable>
  140. <xsl:if test="$part.label != ''">
  141. <xsl:value-of select="$part.label"/>
  142. <xsl:apply-templates select="ancestor::part"
  143. mode="intralabel.punctuation"/>
  144. </xsl:if>
  145. </xsl:if>
  146. <xsl:variable name="format">
  147. <xsl:call-template name="autolabel.format">
  148. <xsl:with-param name="format" select="$appendix.autolabel"/>
  149. </xsl:call-template>
  150. </xsl:variable>
  151. <xsl:choose>
  152. <xsl:when test="$label.from.part != 0 and ancestor::part">
  153. <xsl:number from="part" count="appendix" format="{$format}" level="any"/>
  154. </xsl:when>
  155. <xsl:otherwise>
  156. <xsl:number from="book|article"
  157. count="appendix" format="{$format}" level="any"/>
  158. </xsl:otherwise>
  159. </xsl:choose>
  160. </xsl:when>
  161. </xsl:choose>
  162. </xsl:template>
  163. <xsl:template match="article" mode="label.markup">
  164. <xsl:if test="@label">
  165. <xsl:value-of select="@label"/>
  166. </xsl:if>
  167. </xsl:template>
  168. <xsl:template match="dedication|colophon" mode="label.markup">
  169. <xsl:if test="@label">
  170. <xsl:value-of select="@label"/>
  171. </xsl:if>
  172. </xsl:template>
  173. <xsl:template match="reference" mode="label.markup">
  174. <xsl:choose>
  175. <xsl:when test="@label">
  176. <xsl:value-of select="@label"/>
  177. </xsl:when>
  178. <xsl:when test="string($reference.autolabel) != 0">
  179. <xsl:if test="$component.label.includes.part.label != 0 and
  180. ancestor::part">
  181. <xsl:variable name="part.label">
  182. <xsl:apply-templates select="ancestor::part"
  183. mode="label.markup"/>
  184. </xsl:variable>
  185. <xsl:if test="$part.label != ''">
  186. <xsl:value-of select="$part.label"/>
  187. <xsl:apply-templates select="ancestor::part"
  188. mode="intralabel.punctuation"/>
  189. </xsl:if>
  190. </xsl:if>
  191. <xsl:variable name="format">
  192. <xsl:call-template name="autolabel.format">
  193. <xsl:with-param name="format" select="$reference.autolabel"/>
  194. </xsl:call-template>
  195. </xsl:variable>
  196. <xsl:choose>
  197. <xsl:when test="$label.from.part != 0 and ancestor::part">
  198. <xsl:number from="part" count="reference" format="{$format}" level="any"/>
  199. </xsl:when>
  200. <xsl:otherwise>
  201. <xsl:number from="book" count="reference" format="{$format}" level="any"/>
  202. </xsl:otherwise>
  203. </xsl:choose>
  204. </xsl:when>
  205. </xsl:choose>
  206. </xsl:template>
  207. <xsl:template match="refentry" mode="label.markup">
  208. <xsl:if test="@label">
  209. <xsl:value-of select="@label"/>
  210. </xsl:if>
  211. </xsl:template>
  212. <xsl:template match="section" mode="label.markup">
  213. <!-- if this is a nested section, label the parent -->
  214. <xsl:if test="local-name(..) = 'section'">
  215. <xsl:variable name="parent.section.label">
  216. <xsl:call-template name="label.this.section">
  217. <xsl:with-param name="section" select=".."/>
  218. </xsl:call-template>
  219. </xsl:variable>
  220. <xsl:if test="$parent.section.label != '0'">
  221. <xsl:apply-templates select=".." mode="label.markup"/>
  222. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  223. </xsl:if>
  224. </xsl:if>
  225. <!-- if the parent is a component, maybe label that too -->
  226. <xsl:variable name="parent.is.component">
  227. <xsl:call-template name="is.component">
  228. <xsl:with-param name="node" select=".."/>
  229. </xsl:call-template>
  230. </xsl:variable>
  231. <!-- does this section get labelled? -->
  232. <xsl:variable name="label">
  233. <xsl:call-template name="label.this.section">
  234. <xsl:with-param name="section" select="."/>
  235. </xsl:call-template>
  236. </xsl:variable>
  237. <xsl:if test="$section.label.includes.component.label != 0
  238. and $parent.is.component != 0">
  239. <xsl:variable name="parent.label">
  240. <xsl:apply-templates select=".." mode="label.markup"/>
  241. </xsl:variable>
  242. <xsl:if test="$parent.label != ''">
  243. <xsl:apply-templates select=".." mode="label.markup"/>
  244. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  245. </xsl:if>
  246. </xsl:if>
  247. <!--
  248. <xsl:message>
  249. test: <xsl:value-of select="$label"/>, <xsl:number count="section"/>
  250. </xsl:message>
  251. -->
  252. <xsl:choose>
  253. <xsl:when test="@label">
  254. <xsl:value-of select="@label"/>
  255. </xsl:when>
  256. <xsl:when test="$label != 0">
  257. <xsl:variable name="format">
  258. <xsl:call-template name="autolabel.format">
  259. <xsl:with-param name="format" select="$section.autolabel"/>
  260. </xsl:call-template>
  261. </xsl:variable>
  262. <xsl:number format="{$format}" count="section"/>
  263. </xsl:when>
  264. </xsl:choose>
  265. </xsl:template>
  266. <xsl:template match="sect1" mode="label.markup">
  267. <!-- if the parent is a component, maybe label that too -->
  268. <xsl:variable name="parent.is.component">
  269. <xsl:call-template name="is.component">
  270. <xsl:with-param name="node" select=".."/>
  271. </xsl:call-template>
  272. </xsl:variable>
  273. <xsl:variable name="component.label">
  274. <xsl:if test="$section.label.includes.component.label != 0
  275. and $parent.is.component != 0">
  276. <xsl:variable name="parent.label">
  277. <xsl:apply-templates select=".." mode="label.markup"/>
  278. </xsl:variable>
  279. <xsl:if test="$parent.label != ''">
  280. <xsl:apply-templates select=".." mode="label.markup"/>
  281. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  282. </xsl:if>
  283. </xsl:if>
  284. </xsl:variable>
  285. <xsl:variable name="is.numbered">
  286. <xsl:call-template name="label.this.section"/>
  287. </xsl:variable>
  288. <xsl:choose>
  289. <xsl:when test="@label">
  290. <xsl:value-of select="@label"/>
  291. </xsl:when>
  292. <xsl:when test="$is.numbered != 0">
  293. <xsl:variable name="format">
  294. <xsl:call-template name="autolabel.format">
  295. <xsl:with-param name="format" select="$section.autolabel"/>
  296. </xsl:call-template>
  297. </xsl:variable>
  298. <xsl:copy-of select="$component.label"/>
  299. <xsl:number format="{$format}" count="sect1"/>
  300. </xsl:when>
  301. </xsl:choose>
  302. </xsl:template>
  303. <xsl:template match="sect2|sect3|sect4|sect5" mode="label.markup">
  304. <!-- label the parent -->
  305. <xsl:variable name="parent.section.label">
  306. <xsl:call-template name="label.this.section">
  307. <xsl:with-param name="section" select=".."/>
  308. </xsl:call-template>
  309. </xsl:variable>
  310. <xsl:if test="$parent.section.label != '0'">
  311. <xsl:apply-templates select=".." mode="label.markup"/>
  312. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  313. </xsl:if>
  314. <xsl:variable name="is.numbered">
  315. <xsl:call-template name="label.this.section"/>
  316. </xsl:variable>
  317. <xsl:choose>
  318. <xsl:when test="@label">
  319. <xsl:value-of select="@label"/>
  320. </xsl:when>
  321. <xsl:when test="$is.numbered != 0">
  322. <xsl:variable name="format">
  323. <xsl:call-template name="autolabel.format">
  324. <xsl:with-param name="format" select="$section.autolabel"/>
  325. </xsl:call-template>
  326. </xsl:variable>
  327. <xsl:choose>
  328. <xsl:when test="local-name(.) = 'sect2'">
  329. <xsl:number format="{$format}" count="sect2"/>
  330. </xsl:when>
  331. <xsl:when test="local-name(.) = 'sect3'">
  332. <xsl:number format="{$format}" count="sect3"/>
  333. </xsl:when>
  334. <xsl:when test="local-name(.) = 'sect4'">
  335. <xsl:number format="{$format}" count="sect4"/>
  336. </xsl:when>
  337. <xsl:when test="local-name(.) = 'sect5'">
  338. <xsl:number format="{$format}" count="sect5"/>
  339. </xsl:when>
  340. <xsl:otherwise>
  341. <xsl:message>label.markup: this can't happen!</xsl:message>
  342. </xsl:otherwise>
  343. </xsl:choose>
  344. </xsl:when>
  345. </xsl:choose>
  346. </xsl:template>
  347. <xsl:template match="bridgehead" mode="label.markup">
  348. <!-- bridgeheads are not normally numbered -->
  349. </xsl:template>
  350. <xsl:template match="refsect1" mode="label.markup">
  351. <xsl:choose>
  352. <xsl:when test="@label">
  353. <xsl:value-of select="@label"/>
  354. </xsl:when>
  355. <xsl:when test="$section.autolabel != 0">
  356. <xsl:variable name="format">
  357. <xsl:call-template name="autolabel.format">
  358. <xsl:with-param name="format" select="$section.autolabel"/>
  359. </xsl:call-template>
  360. </xsl:variable>
  361. <xsl:number count="refsect1" format="{$format}"/>
  362. </xsl:when>
  363. </xsl:choose>
  364. </xsl:template>
  365. <xsl:template match="refsect2|refsect3" mode="label.markup">
  366. <!-- label the parent -->
  367. <xsl:variable name="parent.label">
  368. <xsl:apply-templates select=".." mode="label.markup"/>
  369. </xsl:variable>
  370. <xsl:if test="$parent.label != ''">
  371. <xsl:apply-templates select=".." mode="label.markup"/>
  372. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  373. </xsl:if>
  374. <xsl:choose>
  375. <xsl:when test="@label">
  376. <xsl:value-of select="@label"/>
  377. </xsl:when>
  378. <xsl:when test="$section.autolabel != 0">
  379. <xsl:variable name="format">
  380. <xsl:call-template name="autolabel.format">
  381. <xsl:with-param name="format" select="$section.autolabel"/>
  382. </xsl:call-template>
  383. </xsl:variable>
  384. <xsl:choose>
  385. <xsl:when test="local-name(.) = 'refsect2'">
  386. <xsl:number count="refsect2" format="{$format}"/>
  387. </xsl:when>
  388. <xsl:otherwise>
  389. <xsl:number count="refsect3" format="{$format}"/>
  390. </xsl:otherwise>
  391. </xsl:choose>
  392. </xsl:when>
  393. </xsl:choose>
  394. </xsl:template>
  395. <xsl:template match="simplesect" mode="label.markup">
  396. <!-- if this is a nested section, label the parent -->
  397. <xsl:if test="local-name(..) = 'section'
  398. or local-name(..) = 'sect1'
  399. or local-name(..) = 'sect2'
  400. or local-name(..) = 'sect3'
  401. or local-name(..) = 'sect4'
  402. or local-name(..) = 'sect5'">
  403. <xsl:variable name="parent.section.label">
  404. <xsl:apply-templates select=".." mode="label.markup"/>
  405. </xsl:variable>
  406. <xsl:if test="$parent.section.label != ''">
  407. <xsl:apply-templates select=".." mode="label.markup"/>
  408. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  409. </xsl:if>
  410. </xsl:if>
  411. <!-- if the parent is a component, maybe label that too -->
  412. <xsl:variable name="parent.is.component">
  413. <xsl:call-template name="is.component">
  414. <xsl:with-param name="node" select=".."/>
  415. </xsl:call-template>
  416. </xsl:variable>
  417. <!-- does this section get labelled? -->
  418. <xsl:variable name="label">
  419. <xsl:call-template name="label.this.section">
  420. <xsl:with-param name="section" select="."/>
  421. </xsl:call-template>
  422. </xsl:variable>
  423. <xsl:if test="$section.label.includes.component.label != 0
  424. and $parent.is.component != 0">
  425. <xsl:variable name="parent.label">
  426. <xsl:apply-templates select=".." mode="label.markup"/>
  427. </xsl:variable>
  428. <xsl:if test="$parent.label != ''">
  429. <xsl:apply-templates select=".." mode="label.markup"/>
  430. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  431. </xsl:if>
  432. </xsl:if>
  433. <xsl:choose>
  434. <xsl:when test="@label">
  435. <xsl:value-of select="@label"/>
  436. </xsl:when>
  437. <xsl:when test="$label != 0">
  438. <xsl:variable name="format">
  439. <xsl:call-template name="autolabel.format">
  440. <xsl:with-param name="format" select="$section.autolabel"/>
  441. </xsl:call-template>
  442. </xsl:variable>
  443. <xsl:number format="{$format}" count="simplesect"/>
  444. </xsl:when>
  445. </xsl:choose>
  446. </xsl:template>
  447. <xsl:template match="topic" mode="label.markup">
  448. <!-- topics are not numbered by default -->
  449. </xsl:template>
  450. <xsl:template match="qandadiv" mode="label.markup">
  451. <xsl:variable name="lparent" select="(ancestor::set
  452. |ancestor::book
  453. |ancestor::chapter
  454. |ancestor::appendix
  455. |ancestor::preface
  456. |ancestor::section
  457. |ancestor::simplesect
  458. |ancestor::sect1
  459. |ancestor::sect2
  460. |ancestor::sect3
  461. |ancestor::sect4
  462. |ancestor::sect5
  463. |ancestor::refsect1
  464. |ancestor::refsect2
  465. |ancestor::refsect3)[last()]"/>
  466. <xsl:variable name="lparent.prefix">
  467. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  468. </xsl:variable>
  469. <xsl:variable name="prefix">
  470. <xsl:if test="$qanda.inherit.numeration != 0">
  471. <xsl:if test="$lparent.prefix != ''">
  472. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  473. <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/>
  474. </xsl:if>
  475. </xsl:if>
  476. </xsl:variable>
  477. <xsl:choose>
  478. <xsl:when test="$qandadiv.autolabel != 0">
  479. <xsl:variable name="format">
  480. <xsl:call-template name="autolabel.format">
  481. <xsl:with-param name="format" select="$qandadiv.autolabel"/>
  482. </xsl:call-template>
  483. </xsl:variable>
  484. <xsl:value-of select="$prefix"/>
  485. <xsl:number level="multiple" count="qandadiv" format="{$format}"/>
  486. </xsl:when>
  487. </xsl:choose>
  488. </xsl:template>
  489. <xsl:template match="question|answer" mode="label.markup">
  490. <xsl:variable name="lparent" select="(ancestor::set
  491. |ancestor::book
  492. |ancestor::chapter
  493. |ancestor::appendix
  494. |ancestor::preface
  495. |ancestor::section
  496. |ancestor::simplesect
  497. |ancestor::sect1
  498. |ancestor::sect2
  499. |ancestor::sect3
  500. |ancestor::sect4
  501. |ancestor::sect5
  502. |ancestor::refsect1
  503. |ancestor::refsect2
  504. |ancestor::refsect3)[last()]"/>
  505. <xsl:variable name="lparent.prefix">
  506. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  507. </xsl:variable>
  508. <xsl:variable name="prefix">
  509. <xsl:if test="$qanda.inherit.numeration != 0">
  510. <xsl:choose>
  511. <xsl:when test="ancestor::qandadiv">
  512. <xsl:variable name="div.label">
  513. <xsl:apply-templates select="ancestor::qandadiv[1]" mode="label.markup"/>
  514. </xsl:variable>
  515. <xsl:if test="string-length($div.label) != 0">
  516. <xsl:copy-of select="$div.label"/>
  517. <xsl:apply-templates select="ancestor::qandadiv[1]"
  518. mode="intralabel.punctuation"/>
  519. </xsl:if>
  520. </xsl:when>
  521. <xsl:when test="$lparent.prefix != ''">
  522. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  523. <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/>
  524. </xsl:when>
  525. </xsl:choose>
  526. </xsl:if>
  527. </xsl:variable>
  528. <xsl:variable name="inhlabel"
  529. select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
  530. <xsl:variable name="deflabel">
  531. <xsl:choose>
  532. <xsl:when test="$inhlabel != ''">
  533. <xsl:value-of select="$inhlabel"/>
  534. </xsl:when>
  535. <xsl:otherwise>
  536. <xsl:value-of select="$qanda.defaultlabel"/>
  537. </xsl:otherwise>
  538. </xsl:choose>
  539. </xsl:variable>
  540. <xsl:variable name="label" select="label"/>
  541. <xsl:choose>
  542. <xsl:when test="count($label)>0">
  543. <xsl:apply-templates select="$label"/>
  544. </xsl:when>
  545. <xsl:when test="$deflabel = 'qanda' and self::question">
  546. <xsl:call-template name="gentext">
  547. <xsl:with-param name="key" select="'Question'"/>
  548. </xsl:call-template>
  549. </xsl:when>
  550. <xsl:when test="$deflabel = 'qanda' and self::answer">
  551. <xsl:call-template name="gentext">
  552. <xsl:with-param name="key" select="'Answer'"/>
  553. </xsl:call-template>
  554. </xsl:when>
  555. <xsl:when test="($deflabel = 'qnumber' or
  556. $deflabel = 'qnumberanda') and self::question">
  557. <xsl:call-template name="gentext">
  558. <xsl:with-param name="key" select="'Question'"/>
  559. </xsl:call-template>
  560. <xsl:text>&#xA0;</xsl:text>
  561. <xsl:value-of select="$prefix"/>
  562. <xsl:number level="multiple" count="qandaentry" format="1"/>
  563. </xsl:when>
  564. <xsl:when test="$deflabel = 'qnumberanda' and self::answer">
  565. <xsl:call-template name="gentext">
  566. <xsl:with-param name="key" select="'Answer'"/>
  567. </xsl:call-template>
  568. </xsl:when>
  569. <xsl:when test="$deflabel = 'number' and self::question">
  570. <xsl:value-of select="$prefix"/>
  571. <xsl:number level="multiple" count="qandaentry" format="1"/>
  572. </xsl:when>
  573. </xsl:choose>
  574. </xsl:template>
  575. <xsl:template match="bibliography|glossary|
  576. qandaset|index|setindex" mode="label.markup">
  577. <xsl:if test="@label">
  578. <xsl:value-of select="@label"/>
  579. </xsl:if>
  580. </xsl:template>
  581. <xsl:template match="figure|table|example" mode="label.markup">
  582. <xsl:variable name="pchap"
  583. select="(ancestor::chapter
  584. |ancestor::appendix
  585. |ancestor::article[ancestor::book])[last()]"/>
  586. <xsl:variable name="prefix">
  587. <xsl:if test="count($pchap) &gt; 0">
  588. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  589. </xsl:if>
  590. </xsl:variable>
  591. <xsl:choose>
  592. <xsl:when test="@label">
  593. <xsl:value-of select="@label"/>
  594. </xsl:when>
  595. <xsl:otherwise>
  596. <xsl:choose>
  597. <xsl:when test="$prefix != ''">
  598. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  599. <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
  600. <xsl:number format="1" from="chapter|appendix" level="any"/>
  601. </xsl:when>
  602. <xsl:otherwise>
  603. <xsl:number format="1" from="book|article" level="any"/>
  604. </xsl:otherwise>
  605. </xsl:choose>
  606. </xsl:otherwise>
  607. </xsl:choose>
  608. </xsl:template>
  609. <xsl:template match="procedure" mode="label.markup">
  610. <xsl:variable name="pchap"
  611. select="ancestor::chapter
  612. |ancestor::appendix
  613. |ancestor::article[ancestor::book]"/>
  614. <xsl:variable name="prefix">
  615. <xsl:if test="count($pchap) &gt; 0">
  616. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  617. </xsl:if>
  618. </xsl:variable>
  619. <xsl:choose>
  620. <xsl:when test="@label">
  621. <xsl:value-of select="@label"/>
  622. </xsl:when>
  623. <xsl:when test="$formal.procedures = 0">
  624. <!-- No label -->
  625. </xsl:when>
  626. <xsl:otherwise>
  627. <xsl:choose>
  628. <xsl:when test="count($pchap)>0">
  629. <xsl:if test="$prefix != ''">
  630. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  631. <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
  632. </xsl:if>
  633. <xsl:number count="procedure[title]" format="1"
  634. from="chapter|appendix" level="any"/>
  635. </xsl:when>
  636. <xsl:otherwise>
  637. <xsl:number count="procedure[title]" format="1"
  638. from="book|article" level="any"/>
  639. </xsl:otherwise>
  640. </xsl:choose>
  641. </xsl:otherwise>
  642. </xsl:choose>
  643. </xsl:template>
  644. <xsl:template match="equation" mode="label.markup">
  645. <xsl:variable name="pchap"
  646. select="ancestor::chapter
  647. |ancestor::appendix
  648. |ancestor::article[ancestor::book]"/>
  649. <xsl:variable name="prefix">
  650. <xsl:if test="count($pchap) &gt; 0">
  651. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  652. </xsl:if>
  653. </xsl:variable>
  654. <xsl:choose>
  655. <xsl:when test="@label">
  656. <xsl:value-of select="@label"/>
  657. </xsl:when>
  658. <xsl:otherwise>
  659. <xsl:choose>
  660. <xsl:when test="count($pchap)>0">
  661. <xsl:if test="$prefix != ''">
  662. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  663. <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
  664. </xsl:if>
  665. <xsl:number format="1" count="equation"
  666. from="chapter|appendix" level="any"/>
  667. </xsl:when>
  668. <xsl:otherwise>
  669. <xsl:number format="1" count="equation"
  670. from="book|article" level="any"/>
  671. </xsl:otherwise>
  672. </xsl:choose>
  673. </xsl:otherwise>
  674. </xsl:choose>
  675. </xsl:template>
  676. <xsl:template match="orderedlist/listitem" mode="label.markup">
  677. <xsl:variable name="numeration">
  678. <xsl:call-template name="list.numeration">
  679. <xsl:with-param name="node" select="parent::orderedlist"/>
  680. </xsl:call-template>
  681. </xsl:variable>
  682. <xsl:variable name="type">
  683. <xsl:choose>
  684. <xsl:when test="$numeration='arabic'">1</xsl:when>
  685. <xsl:when test="$numeration='loweralpha'">a</xsl:when>
  686. <xsl:when test="$numeration='lowerroman'">i</xsl:when>
  687. <xsl:when test="$numeration='upperalpha'">A</xsl:when>
  688. <xsl:when test="$numeration='upperroman'">I</xsl:when>
  689. <!-- What!? This should never happen -->
  690. <xsl:otherwise>
  691. <xsl:message>
  692. <xsl:text>Unexpected numeration: </xsl:text>
  693. <xsl:value-of select="$numeration"/>
  694. </xsl:message>
  695. <xsl:value-of select="1."/>
  696. </xsl:otherwise>
  697. </xsl:choose>
  698. </xsl:variable>
  699. <xsl:variable name="item-number">
  700. <xsl:call-template name="orderedlist-item-number"/>
  701. </xsl:variable>
  702. <xsl:number value="$item-number" format="{$type}"/>
  703. </xsl:template>
  704. <xsl:template match="production" mode="label.markup">
  705. <xsl:number count="production" level="any"/>
  706. </xsl:template>
  707. <xsl:template match="abstract" mode="label.markup">
  708. <!-- nop -->
  709. </xsl:template>
  710. <xsl:template match="sidebar" mode="label.markup">
  711. <!-- nop -->
  712. </xsl:template>
  713. <xsl:template match="glossdiv|glosslist" mode="label.markup">
  714. <!-- nop -->
  715. </xsl:template>
  716. <xsl:template match="glossentry" mode="label.markup">
  717. <!-- nop -->
  718. </xsl:template>
  719. <!-- ============================================================ -->
  720. <xsl:template name="label.this.section">
  721. <xsl:param name="section" select="."/>
  722. <xsl:variable name="level">
  723. <xsl:call-template name="section.level"/>
  724. </xsl:variable>
  725. <xsl:choose>
  726. <!-- bridgeheads are not numbered -->
  727. <xsl:when test="$section/self::bridgehead">0</xsl:when>
  728. <xsl:when test="$level &lt;= $section.autolabel.max.depth">
  729. <xsl:value-of select="$section.autolabel"/>
  730. </xsl:when>
  731. <xsl:otherwise>0</xsl:otherwise>
  732. </xsl:choose>
  733. </xsl:template>
  734. <doc:template name="label.this.section" xmlns="">
  735. <refpurpose>Returns true if $section should be labelled</refpurpose>
  736. <refdescription id="label.this.section-desc">
  737. <para>Returns true if the specified section should be labelled.
  738. By default, this template returns zero unless
  739. the section level is less than or equal to the value of the
  740. <literal>$section.autolabel.max.depth</literal> parameter, in
  741. which case it returns
  742. <literal>$section.autolabel</literal>.
  743. Custom stylesheets may override it to get more selective behavior.</para>
  744. </refdescription>
  745. </doc:template>
  746. <!-- ============================================================ -->
  747. <xsl:template name="default.autolabel.format">
  748. <xsl:param name="context" select="."/>
  749. <xsl:choose>
  750. <xsl:when test="local-name($context) = 'appendix'">
  751. <xsl:value-of select="'A'"/>
  752. </xsl:when>
  753. <xsl:when test="local-name($context) = 'part'">
  754. <xsl:value-of select="'I'"/>
  755. </xsl:when>
  756. <xsl:otherwise>1</xsl:otherwise>
  757. </xsl:choose>
  758. </xsl:template>
  759. <xsl:template name="autolabel.format">
  760. <xsl:param name="context" select="."/>
  761. <xsl:param name="format"/>
  762. <xsl:choose>
  763. <xsl:when test="string($format) != 0">
  764. <xsl:choose>
  765. <xsl:when test="string($format)='arabic' or $format='1'">1</xsl:when>
  766. <xsl:when test="$format='loweralpha' or $format='a'">
  767. <xsl:value-of select="'a'"/>
  768. </xsl:when>
  769. <xsl:when test="$format='lowerroman' or $format='i'">
  770. <xsl:value-of select="'i'"/>
  771. </xsl:when>
  772. <xsl:when test="$format='upperalpha' or $format='A'">
  773. <xsl:value-of select="'A'"/>
  774. </xsl:when>
  775. <xsl:when test="$format='upperroman' or $format='I'">
  776. <xsl:value-of select="'I'"/>
  777. </xsl:when>
  778. <xsl:when test="$format='arabicindic' or $format='&#x661;'">
  779. <xsl:value-of select="'&#x661;'"/>
  780. </xsl:when>
  781. <xsl:otherwise>
  782. <xsl:message>
  783. <xsl:text>Unexpected </xsl:text><xsl:value-of select="local-name(.)"/><xsl:text>.autolabel value: </xsl:text>
  784. <xsl:value-of select="$format"/><xsl:text>; using default.</xsl:text>
  785. </xsl:message>
  786. <xsl:call-template name="default.autolabel.format"/>
  787. </xsl:otherwise>
  788. </xsl:choose>
  789. </xsl:when>
  790. </xsl:choose>
  791. </xsl:template>
  792. <doc:template name="autolabel.format" xmlns="">
  793. <refpurpose>Returns format for autolabel parameters</refpurpose>
  794. <refdescription id="autolabel.format-desc">
  795. <para>Returns format passed as parameter if non zero. Supported
  796. format are 'arabic' or '1', 'loweralpha' or 'a', 'lowerroman' or 'i',
  797. 'upperlapha' or 'A', 'upperroman' or 'I', 'arabicindic' or '&#x661;'.
  798. If its not one of these then
  799. returns the default format.</para>
  800. </refdescription>
  801. </doc:template>
  802. <!-- ============================================================ -->
  803. </xsl:stylesheet>