labels.xsl 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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. <!-- 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. <!-- FIXME: could we do a better job here? -->
  349. <xsl:variable name="contsec"
  350. select="(ancestor::section
  351. |ancestor::simplesect
  352. |ancestor::sect1
  353. |ancestor::sect2
  354. |ancestor::sect3
  355. |ancestor::sect4
  356. |ancestor::sect5
  357. |ancestor::refsect1
  358. |ancestor::refsect2
  359. |ancestor::refsect3
  360. |ancestor::chapter
  361. |ancestor::appendix
  362. |ancestor::preface)[last()]"/>
  363. <xsl:apply-templates select="$contsec" mode="label.markup"/>
  364. </xsl:template>
  365. <xsl:template match="refsect1" mode="label.markup">
  366. <xsl:choose>
  367. <xsl:when test="@label">
  368. <xsl:value-of select="@label"/>
  369. </xsl:when>
  370. <xsl:when test="$section.autolabel != 0">
  371. <xsl:variable name="format">
  372. <xsl:call-template name="autolabel.format">
  373. <xsl:with-param name="format" select="$section.autolabel"/>
  374. </xsl:call-template>
  375. </xsl:variable>
  376. <xsl:number count="refsect1" format="{$format}"/>
  377. </xsl:when>
  378. </xsl:choose>
  379. </xsl:template>
  380. <xsl:template match="refsect2|refsect3" mode="label.markup">
  381. <!-- label the parent -->
  382. <xsl:variable name="parent.label">
  383. <xsl:apply-templates select=".." mode="label.markup"/>
  384. </xsl:variable>
  385. <xsl:if test="$parent.label != ''">
  386. <xsl:apply-templates select=".." mode="label.markup"/>
  387. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  388. </xsl:if>
  389. <xsl:choose>
  390. <xsl:when test="@label">
  391. <xsl:value-of select="@label"/>
  392. </xsl:when>
  393. <xsl:when test="$section.autolabel != 0">
  394. <xsl:variable name="format">
  395. <xsl:call-template name="autolabel.format">
  396. <xsl:with-param name="format" select="$section.autolabel"/>
  397. </xsl:call-template>
  398. </xsl:variable>
  399. <xsl:choose>
  400. <xsl:when test="local-name(.) = 'refsect2'">
  401. <xsl:number count="refsect2" format="{$format}"/>
  402. </xsl:when>
  403. <xsl:otherwise>
  404. <xsl:number count="refsect3" format="{$format}"/>
  405. </xsl:otherwise>
  406. </xsl:choose>
  407. </xsl:when>
  408. </xsl:choose>
  409. </xsl:template>
  410. <xsl:template match="simplesect" mode="label.markup">
  411. <!-- if this is a nested section, label the parent -->
  412. <xsl:if test="local-name(..) = 'section'
  413. or local-name(..) = 'sect1'
  414. or local-name(..) = 'sect2'
  415. or local-name(..) = 'sect3'
  416. or local-name(..) = 'sect4'
  417. or local-name(..) = 'sect5'">
  418. <xsl:variable name="parent.section.label">
  419. <xsl:apply-templates select=".." mode="label.markup"/>
  420. </xsl:variable>
  421. <xsl:if test="$parent.section.label != ''">
  422. <xsl:apply-templates select=".." mode="label.markup"/>
  423. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  424. </xsl:if>
  425. </xsl:if>
  426. <!-- if the parent is a component, maybe label that too -->
  427. <xsl:variable name="parent.is.component">
  428. <xsl:call-template name="is.component">
  429. <xsl:with-param name="node" select=".."/>
  430. </xsl:call-template>
  431. </xsl:variable>
  432. <!-- does this section get labelled? -->
  433. <xsl:variable name="label">
  434. <xsl:call-template name="label.this.section">
  435. <xsl:with-param name="section" select="."/>
  436. </xsl:call-template>
  437. </xsl:variable>
  438. <xsl:if test="$section.label.includes.component.label != 0
  439. and $parent.is.component != 0">
  440. <xsl:variable name="parent.label">
  441. <xsl:apply-templates select=".." mode="label.markup"/>
  442. </xsl:variable>
  443. <xsl:if test="$parent.label != ''">
  444. <xsl:apply-templates select=".." mode="label.markup"/>
  445. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  446. </xsl:if>
  447. </xsl:if>
  448. <xsl:choose>
  449. <xsl:when test="@label">
  450. <xsl:value-of select="@label"/>
  451. </xsl:when>
  452. <xsl:when test="$label != 0">
  453. <xsl:variable name="format">
  454. <xsl:call-template name="autolabel.format">
  455. <xsl:with-param name="format" select="$section.autolabel"/>
  456. </xsl:call-template>
  457. </xsl:variable>
  458. <xsl:number format="{$format}" count="simplesect"/>
  459. </xsl:when>
  460. </xsl:choose>
  461. </xsl:template>
  462. <xsl:template match="qandadiv" mode="label.markup">
  463. <xsl:variable name="lparent" select="(ancestor::set
  464. |ancestor::book
  465. |ancestor::chapter
  466. |ancestor::appendix
  467. |ancestor::preface
  468. |ancestor::section
  469. |ancestor::simplesect
  470. |ancestor::sect1
  471. |ancestor::sect2
  472. |ancestor::sect3
  473. |ancestor::sect4
  474. |ancestor::sect5
  475. |ancestor::refsect1
  476. |ancestor::refsect2
  477. |ancestor::refsect3)[last()]"/>
  478. <xsl:variable name="lparent.prefix">
  479. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  480. </xsl:variable>
  481. <xsl:variable name="prefix">
  482. <xsl:if test="$qanda.inherit.numeration != 0">
  483. <xsl:if test="$lparent.prefix != ''">
  484. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  485. <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/>
  486. </xsl:if>
  487. </xsl:if>
  488. </xsl:variable>
  489. <xsl:choose>
  490. <xsl:when test="$qandadiv.autolabel != 0">
  491. <xsl:variable name="format">
  492. <xsl:call-template name="autolabel.format">
  493. <xsl:with-param name="format" select="$qandadiv.autolabel"/>
  494. </xsl:call-template>
  495. </xsl:variable>
  496. <xsl:value-of select="$prefix"/>
  497. <xsl:number level="multiple" count="qandadiv" format="{$format}"/>
  498. </xsl:when>
  499. </xsl:choose>
  500. </xsl:template>
  501. <xsl:template match="question|answer" mode="label.markup">
  502. <xsl:variable name="lparent" select="(ancestor::set
  503. |ancestor::book
  504. |ancestor::chapter
  505. |ancestor::appendix
  506. |ancestor::preface
  507. |ancestor::section
  508. |ancestor::simplesect
  509. |ancestor::sect1
  510. |ancestor::sect2
  511. |ancestor::sect3
  512. |ancestor::sect4
  513. |ancestor::sect5
  514. |ancestor::refsect1
  515. |ancestor::refsect2
  516. |ancestor::refsect3)[last()]"/>
  517. <xsl:variable name="lparent.prefix">
  518. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  519. </xsl:variable>
  520. <xsl:variable name="prefix">
  521. <xsl:if test="$qanda.inherit.numeration != 0">
  522. <xsl:choose>
  523. <xsl:when test="ancestor::qandadiv">
  524. <xsl:apply-templates select="ancestor::qandadiv[1]" mode="label.markup"/>
  525. <xsl:apply-templates select="ancestor::qandadiv[1]"
  526. mode="intralabel.punctuation"/>
  527. </xsl:when>
  528. <xsl:when test="$lparent.prefix != ''">
  529. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  530. <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/>
  531. </xsl:when>
  532. </xsl:choose>
  533. </xsl:if>
  534. </xsl:variable>
  535. <xsl:variable name="inhlabel"
  536. select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
  537. <xsl:variable name="deflabel">
  538. <xsl:choose>
  539. <xsl:when test="$inhlabel != ''">
  540. <xsl:value-of select="$inhlabel"/>
  541. </xsl:when>
  542. <xsl:otherwise>
  543. <xsl:value-of select="$qanda.defaultlabel"/>
  544. </xsl:otherwise>
  545. </xsl:choose>
  546. </xsl:variable>
  547. <xsl:variable name="label" select="label"/>
  548. <xsl:choose>
  549. <xsl:when test="count($label)>0">
  550. <xsl:apply-templates select="$label"/>
  551. </xsl:when>
  552. <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'question'">
  553. <xsl:call-template name="gentext">
  554. <xsl:with-param name="key" select="'Question'"/>
  555. </xsl:call-template>
  556. </xsl:when>
  557. <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'answer'">
  558. <xsl:call-template name="gentext">
  559. <xsl:with-param name="key" select="'Answer'"/>
  560. </xsl:call-template>
  561. </xsl:when>
  562. <xsl:when test="$deflabel = 'number' and local-name(.) = 'question'">
  563. <xsl:value-of select="$prefix"/>
  564. <xsl:number level="multiple" count="qandaentry" format="1"/>
  565. </xsl:when>
  566. </xsl:choose>
  567. </xsl:template>
  568. <xsl:template match="bibliography|glossary|
  569. qandaset|index|setindex" mode="label.markup">
  570. <xsl:if test="@label">
  571. <xsl:value-of select="@label"/>
  572. </xsl:if>
  573. </xsl:template>
  574. <xsl:template match="figure|table|example" mode="label.markup">
  575. <xsl:variable name="pchap"
  576. select="ancestor::chapter
  577. |ancestor::appendix
  578. |ancestor::article[ancestor::book]"/>
  579. <xsl:variable name="prefix">
  580. <xsl:if test="count($pchap) &gt; 0">
  581. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  582. </xsl:if>
  583. </xsl:variable>
  584. <xsl:choose>
  585. <xsl:when test="@label">
  586. <xsl:value-of select="@label"/>
  587. </xsl:when>
  588. <xsl:otherwise>
  589. <xsl:choose>
  590. <xsl:when test="$prefix != ''">
  591. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  592. <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
  593. <xsl:number format="1" from="chapter|appendix" level="any"/>
  594. </xsl:when>
  595. <xsl:otherwise>
  596. <xsl:number format="1" from="book|article" level="any"/>
  597. </xsl:otherwise>
  598. </xsl:choose>
  599. </xsl:otherwise>
  600. </xsl:choose>
  601. </xsl:template>
  602. <xsl:template match="procedure" mode="label.markup">
  603. <xsl:variable name="pchap"
  604. select="ancestor::chapter
  605. |ancestor::appendix
  606. |ancestor::article[ancestor::book]"/>
  607. <xsl:variable name="prefix">
  608. <xsl:if test="count($pchap) &gt; 0">
  609. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  610. </xsl:if>
  611. </xsl:variable>
  612. <xsl:choose>
  613. <xsl:when test="@label">
  614. <xsl:value-of select="@label"/>
  615. </xsl:when>
  616. <xsl:when test="$formal.procedures = 0">
  617. <!-- No label -->
  618. </xsl:when>
  619. <xsl:otherwise>
  620. <xsl:choose>
  621. <xsl:when test="count($pchap)>0">
  622. <xsl:if test="$prefix != ''">
  623. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  624. <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
  625. </xsl:if>
  626. <xsl:number count="procedure[title]" format="1"
  627. from="chapter|appendix" level="any"/>
  628. </xsl:when>
  629. <xsl:otherwise>
  630. <xsl:number count="procedure[title]" format="1"
  631. from="book|article" level="any"/>
  632. </xsl:otherwise>
  633. </xsl:choose>
  634. </xsl:otherwise>
  635. </xsl:choose>
  636. </xsl:template>
  637. <xsl:template match="equation" mode="label.markup">
  638. <xsl:variable name="pchap"
  639. select="ancestor::chapter
  640. |ancestor::appendix
  641. |ancestor::article[ancestor::book]"/>
  642. <xsl:variable name="prefix">
  643. <xsl:if test="count($pchap) &gt; 0">
  644. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  645. </xsl:if>
  646. </xsl:variable>
  647. <xsl:choose>
  648. <xsl:when test="@label">
  649. <xsl:value-of select="@label"/>
  650. </xsl:when>
  651. <xsl:otherwise>
  652. <xsl:choose>
  653. <xsl:when test="count($pchap)>0">
  654. <xsl:if test="$prefix != ''">
  655. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  656. <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
  657. </xsl:if>
  658. <xsl:number format="1" count="equation[title or info/title]"
  659. from="chapter|appendix" level="any"/>
  660. </xsl:when>
  661. <xsl:otherwise>
  662. <xsl:number format="1" count="equation[title or info/title]"
  663. from="book|article" level="any"/>
  664. </xsl:otherwise>
  665. </xsl:choose>
  666. </xsl:otherwise>
  667. </xsl:choose>
  668. </xsl:template>
  669. <xsl:template match="orderedlist/listitem" mode="label.markup">
  670. <xsl:variable name="numeration">
  671. <xsl:call-template name="list.numeration">
  672. <xsl:with-param name="node" select="parent::orderedlist"/>
  673. </xsl:call-template>
  674. </xsl:variable>
  675. <xsl:variable name="type">
  676. <xsl:choose>
  677. <xsl:when test="$numeration='arabic'">1</xsl:when>
  678. <xsl:when test="$numeration='loweralpha'">a</xsl:when>
  679. <xsl:when test="$numeration='lowerroman'">i</xsl:when>
  680. <xsl:when test="$numeration='upperalpha'">A</xsl:when>
  681. <xsl:when test="$numeration='upperroman'">I</xsl:when>
  682. <!-- What!? This should never happen -->
  683. <xsl:otherwise>
  684. <xsl:message>
  685. <xsl:text>Unexpected numeration: </xsl:text>
  686. <xsl:value-of select="$numeration"/>
  687. </xsl:message>
  688. <xsl:value-of select="1."/>
  689. </xsl:otherwise>
  690. </xsl:choose>
  691. </xsl:variable>
  692. <xsl:variable name="item-number">
  693. <xsl:call-template name="orderedlist-item-number"/>
  694. </xsl:variable>
  695. <xsl:number value="$item-number" format="{$type}"/>
  696. </xsl:template>
  697. <xsl:template match="abstract" mode="label.markup">
  698. <!-- nop -->
  699. </xsl:template>
  700. <xsl:template match="sidebar" mode="label.markup">
  701. <!-- nop -->
  702. </xsl:template>
  703. <!-- ============================================================ -->
  704. <xsl:template name="label.this.section">
  705. <xsl:param name="section" select="."/>
  706. <xsl:variable name="level">
  707. <xsl:call-template name="section.level"/>
  708. </xsl:variable>
  709. <xsl:choose>
  710. <xsl:when test="$level &lt;= $section.autolabel.max.depth">
  711. <xsl:value-of select="$section.autolabel"/>
  712. </xsl:when>
  713. <xsl:otherwise>0</xsl:otherwise>
  714. </xsl:choose>
  715. </xsl:template>
  716. <doc:template name="label.this.section" xmlns="">
  717. <refpurpose>Returns true if $section should be labelled</refpurpose>
  718. <refdescription id="label.this.section-desc">
  719. <para>Returns true if the specified section should be labelled.
  720. By default, this template returns zero unless
  721. the section level is less than or equal to the value of the
  722. <literal>$section.autolabel.max.depth</literal> parameter, in
  723. which case it returns
  724. <literal>$section.autolabel</literal>.
  725. Custom stylesheets may override it to get more selective behavior.</para>
  726. </refdescription>
  727. </doc:template>
  728. <!-- ============================================================ -->
  729. <xsl:template name="default.autolabel.format">
  730. <xsl:param name="context" select="."/>
  731. <xsl:choose>
  732. <xsl:when test="local-name($context) = 'appendix'">
  733. <xsl:value-of select="'A'"/>
  734. </xsl:when>
  735. <xsl:when test="local-name($context) = 'part'">
  736. <xsl:value-of select="'I'"/>
  737. </xsl:when>
  738. <xsl:otherwise>1</xsl:otherwise>
  739. </xsl:choose>
  740. </xsl:template>
  741. <xsl:template name="autolabel.format">
  742. <xsl:param name="context" select="."/>
  743. <xsl:param name="format"/>
  744. <xsl:choose>
  745. <xsl:when test="string($format) != 0">
  746. <xsl:choose>
  747. <xsl:when test="string($format)='arabic' or $format='1'">1</xsl:when>
  748. <xsl:when test="$format='loweralpha' or $format='a'">
  749. <xsl:value-of select="'a'"/>
  750. </xsl:when>
  751. <xsl:when test="$format='lowerroman' or $format='i'">
  752. <xsl:value-of select="'i'"/>
  753. </xsl:when>
  754. <xsl:when test="$format='upperalpha' or $format='A'">
  755. <xsl:value-of select="'A'"/>
  756. </xsl:when>
  757. <xsl:when test="$format='upperroman' or $format='I'">
  758. <xsl:value-of select="'I'"/>
  759. </xsl:when>
  760. <xsl:when test="$format='arabicindic' or $format='&#x661;'">
  761. <xsl:value-of select="'&#x661;'"/>
  762. </xsl:when>
  763. <xsl:otherwise>
  764. <xsl:message>
  765. <xsl:text>Unexpected </xsl:text><xsl:value-of select="local-name(.)"/><xsl:text>.autolabel value: </xsl:text>
  766. <xsl:value-of select="$format"/><xsl:text>; using default.</xsl:text>
  767. </xsl:message>
  768. <xsl:call-template name="default.autolabel.format"/>
  769. </xsl:otherwise>
  770. </xsl:choose>
  771. </xsl:when>
  772. </xsl:choose>
  773. </xsl:template>
  774. <doc:template name="autolabel.format" xmlns="">
  775. <refpurpose>Returns format for autolabel parameters</refpurpose>
  776. <refdescription id="autolabel.format-desc">
  777. <para>Returns format passed as parameter if non zero. Supported
  778. format are 'arabic' or '1', 'loweralpha' or 'a', 'lowerroman' or 'i',
  779. 'upperlapha' or 'A', 'upperroman' or 'I', 'arabicindic' or '&#x661;'.
  780. If its not one of these then
  781. returns the default format.</para>
  782. </refdescription>
  783. </doc:template>
  784. <!-- ============================================================ -->
  785. </xsl:stylesheet>