labels.xsl 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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:variable name="format">
  180. <xsl:call-template name="autolabel.format">
  181. <xsl:with-param name="format" select="$reference.autolabel"/>
  182. </xsl:call-template>
  183. </xsl:variable>
  184. <xsl:number from="book" count="reference" format="{$format}" level="any"/>
  185. </xsl:when>
  186. </xsl:choose>
  187. </xsl:template>
  188. <xsl:template match="refentry" mode="label.markup">
  189. <xsl:if test="@label">
  190. <xsl:value-of select="@label"/>
  191. </xsl:if>
  192. </xsl:template>
  193. <xsl:template match="section" mode="label.markup">
  194. <!-- if this is a nested section, label the parent -->
  195. <xsl:if test="local-name(..) = 'section'">
  196. <xsl:variable name="parent.section.label">
  197. <xsl:call-template name="label.this.section">
  198. <xsl:with-param name="section" select=".."/>
  199. </xsl:call-template>
  200. </xsl:variable>
  201. <xsl:if test="$parent.section.label != '0'">
  202. <xsl:apply-templates select=".." mode="label.markup"/>
  203. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  204. </xsl:if>
  205. </xsl:if>
  206. <!-- if the parent is a component, maybe label that too -->
  207. <xsl:variable name="parent.is.component">
  208. <xsl:call-template name="is.component">
  209. <xsl:with-param name="node" select=".."/>
  210. </xsl:call-template>
  211. </xsl:variable>
  212. <!-- does this section get labelled? -->
  213. <xsl:variable name="label">
  214. <xsl:call-template name="label.this.section">
  215. <xsl:with-param name="section" select="."/>
  216. </xsl:call-template>
  217. </xsl:variable>
  218. <xsl:if test="$section.label.includes.component.label != 0
  219. and $parent.is.component != 0">
  220. <xsl:variable name="parent.label">
  221. <xsl:apply-templates select=".." mode="label.markup"/>
  222. </xsl:variable>
  223. <xsl:if test="$parent.label != ''">
  224. <xsl:apply-templates select=".." mode="label.markup"/>
  225. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  226. </xsl:if>
  227. </xsl:if>
  228. <!--
  229. <xsl:message>
  230. test: <xsl:value-of select="$label"/>, <xsl:number count="section"/>
  231. </xsl:message>
  232. -->
  233. <xsl:choose>
  234. <xsl:when test="@label">
  235. <xsl:value-of select="@label"/>
  236. </xsl:when>
  237. <xsl:when test="$label != 0">
  238. <xsl:variable name="format">
  239. <xsl:call-template name="autolabel.format">
  240. <xsl:with-param name="format" select="$section.autolabel"/>
  241. </xsl:call-template>
  242. </xsl:variable>
  243. <xsl:number format="{$format}" count="section"/>
  244. </xsl:when>
  245. </xsl:choose>
  246. </xsl:template>
  247. <xsl:template match="sect1" mode="label.markup">
  248. <!-- if the parent is a component, maybe label that too -->
  249. <xsl:variable name="parent.is.component">
  250. <xsl:call-template name="is.component">
  251. <xsl:with-param name="node" select=".."/>
  252. </xsl:call-template>
  253. </xsl:variable>
  254. <xsl:variable name="component.label">
  255. <xsl:if test="$section.label.includes.component.label != 0
  256. and $parent.is.component != 0">
  257. <xsl:variable name="parent.label">
  258. <xsl:apply-templates select=".." mode="label.markup"/>
  259. </xsl:variable>
  260. <xsl:if test="$parent.label != ''">
  261. <xsl:apply-templates select=".." mode="label.markup"/>
  262. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  263. </xsl:if>
  264. </xsl:if>
  265. </xsl:variable>
  266. <xsl:variable name="is.numbered">
  267. <xsl:call-template name="label.this.section"/>
  268. </xsl:variable>
  269. <xsl:choose>
  270. <xsl:when test="@label">
  271. <xsl:value-of select="@label"/>
  272. </xsl:when>
  273. <xsl:when test="$is.numbered != 0">
  274. <xsl:variable name="format">
  275. <xsl:call-template name="autolabel.format">
  276. <xsl:with-param name="format" select="$section.autolabel"/>
  277. </xsl:call-template>
  278. </xsl:variable>
  279. <xsl:copy-of select="$component.label"/>
  280. <xsl:number format="{$format}" count="sect1"/>
  281. </xsl:when>
  282. </xsl:choose>
  283. </xsl:template>
  284. <xsl:template match="sect2|sect3|sect4|sect5" mode="label.markup">
  285. <!-- label the parent -->
  286. <xsl:variable name="parent.section.label">
  287. <xsl:call-template name="label.this.section">
  288. <xsl:with-param name="section" select=".."/>
  289. </xsl:call-template>
  290. </xsl:variable>
  291. <xsl:if test="$parent.section.label != '0'">
  292. <xsl:apply-templates select=".." mode="label.markup"/>
  293. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  294. </xsl:if>
  295. <xsl:variable name="is.numbered">
  296. <xsl:call-template name="label.this.section"/>
  297. </xsl:variable>
  298. <xsl:choose>
  299. <xsl:when test="@label">
  300. <xsl:value-of select="@label"/>
  301. </xsl:when>
  302. <xsl:when test="$is.numbered != 0">
  303. <xsl:variable name="format">
  304. <xsl:call-template name="autolabel.format">
  305. <xsl:with-param name="format" select="$section.autolabel"/>
  306. </xsl:call-template>
  307. </xsl:variable>
  308. <xsl:choose>
  309. <xsl:when test="local-name(.) = 'sect2'">
  310. <xsl:number format="{$format}" count="sect2"/>
  311. </xsl:when>
  312. <xsl:when test="local-name(.) = 'sect3'">
  313. <xsl:number format="{$format}" count="sect3"/>
  314. </xsl:when>
  315. <xsl:when test="local-name(.) = 'sect4'">
  316. <xsl:number format="{$format}" count="sect4"/>
  317. </xsl:when>
  318. <xsl:when test="local-name(.) = 'sect5'">
  319. <xsl:number format="{$format}" count="sect5"/>
  320. </xsl:when>
  321. <xsl:otherwise>
  322. <xsl:message>label.markup: this can't happen!</xsl:message>
  323. </xsl:otherwise>
  324. </xsl:choose>
  325. </xsl:when>
  326. </xsl:choose>
  327. </xsl:template>
  328. <xsl:template match="bridgehead" mode="label.markup">
  329. <!-- FIXME: could we do a better job here? -->
  330. <xsl:variable name="contsec"
  331. select="(ancestor::section
  332. |ancestor::simplesect
  333. |ancestor::sect1
  334. |ancestor::sect2
  335. |ancestor::sect3
  336. |ancestor::sect4
  337. |ancestor::sect5
  338. |ancestor::refsect1
  339. |ancestor::refsect2
  340. |ancestor::refsect3
  341. |ancestor::chapter
  342. |ancestor::appendix
  343. |ancestor::preface)[last()]"/>
  344. <xsl:apply-templates select="$contsec" mode="label.markup"/>
  345. </xsl:template>
  346. <xsl:template match="refsect1" mode="label.markup">
  347. <xsl:choose>
  348. <xsl:when test="@label">
  349. <xsl:value-of select="@label"/>
  350. </xsl:when>
  351. <xsl:when test="$section.autolabel != 0">
  352. <xsl:variable name="format">
  353. <xsl:call-template name="autolabel.format">
  354. <xsl:with-param name="format" select="$section.autolabel"/>
  355. </xsl:call-template>
  356. </xsl:variable>
  357. <xsl:number count="refsect1" format="{$format}"/>
  358. </xsl:when>
  359. </xsl:choose>
  360. </xsl:template>
  361. <xsl:template match="refsect2|refsect3" mode="label.markup">
  362. <!-- label the parent -->
  363. <xsl:variable name="parent.label">
  364. <xsl:apply-templates select=".." mode="label.markup"/>
  365. </xsl:variable>
  366. <xsl:if test="$parent.label != ''">
  367. <xsl:apply-templates select=".." mode="label.markup"/>
  368. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  369. </xsl:if>
  370. <xsl:choose>
  371. <xsl:when test="@label">
  372. <xsl:value-of select="@label"/>
  373. </xsl:when>
  374. <xsl:when test="$section.autolabel != 0">
  375. <xsl:variable name="format">
  376. <xsl:call-template name="autolabel.format">
  377. <xsl:with-param name="format" select="$section.autolabel"/>
  378. </xsl:call-template>
  379. </xsl:variable>
  380. <xsl:choose>
  381. <xsl:when test="local-name(.) = 'refsect2'">
  382. <xsl:number count="refsect2" format="{$format}"/>
  383. </xsl:when>
  384. <xsl:otherwise>
  385. <xsl:number count="refsect3" format="{$format}"/>
  386. </xsl:otherwise>
  387. </xsl:choose>
  388. </xsl:when>
  389. </xsl:choose>
  390. </xsl:template>
  391. <xsl:template match="simplesect" mode="label.markup">
  392. <!-- if this is a nested section, label the parent -->
  393. <xsl:if test="local-name(..) = 'section'
  394. or local-name(..) = 'sect1'
  395. or local-name(..) = 'sect2'
  396. or local-name(..) = 'sect3'
  397. or local-name(..) = 'sect4'
  398. or local-name(..) = 'sect5'">
  399. <xsl:variable name="parent.section.label">
  400. <xsl:apply-templates select=".." mode="label.markup"/>
  401. </xsl:variable>
  402. <xsl:if test="$parent.section.label != ''">
  403. <xsl:apply-templates select=".." mode="label.markup"/>
  404. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  405. </xsl:if>
  406. </xsl:if>
  407. <!-- if the parent is a component, maybe label that too -->
  408. <xsl:variable name="parent.is.component">
  409. <xsl:call-template name="is.component">
  410. <xsl:with-param name="node" select=".."/>
  411. </xsl:call-template>
  412. </xsl:variable>
  413. <!-- does this section get labelled? -->
  414. <xsl:variable name="label">
  415. <xsl:call-template name="label.this.section">
  416. <xsl:with-param name="section" select="."/>
  417. </xsl:call-template>
  418. </xsl:variable>
  419. <xsl:if test="$section.label.includes.component.label != 0
  420. and $parent.is.component != 0">
  421. <xsl:variable name="parent.label">
  422. <xsl:apply-templates select=".." mode="label.markup"/>
  423. </xsl:variable>
  424. <xsl:if test="$parent.label != ''">
  425. <xsl:apply-templates select=".." mode="label.markup"/>
  426. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  427. </xsl:if>
  428. </xsl:if>
  429. <xsl:choose>
  430. <xsl:when test="@label">
  431. <xsl:value-of select="@label"/>
  432. </xsl:when>
  433. <xsl:when test="$label != 0">
  434. <xsl:variable name="format">
  435. <xsl:call-template name="autolabel.format">
  436. <xsl:with-param name="format" select="$section.autolabel"/>
  437. </xsl:call-template>
  438. </xsl:variable>
  439. <xsl:number format="{$format}" count="simplesect"/>
  440. </xsl:when>
  441. </xsl:choose>
  442. </xsl:template>
  443. <xsl:template match="qandadiv" mode="label.markup">
  444. <xsl:variable name="lparent" select="(ancestor::set
  445. |ancestor::book
  446. |ancestor::chapter
  447. |ancestor::appendix
  448. |ancestor::preface
  449. |ancestor::section
  450. |ancestor::simplesect
  451. |ancestor::sect1
  452. |ancestor::sect2
  453. |ancestor::sect3
  454. |ancestor::sect4
  455. |ancestor::sect5
  456. |ancestor::refsect1
  457. |ancestor::refsect2
  458. |ancestor::refsect3)[last()]"/>
  459. <xsl:variable name="lparent.prefix">
  460. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  461. </xsl:variable>
  462. <xsl:variable name="prefix">
  463. <xsl:if test="$qanda.inherit.numeration != 0">
  464. <xsl:if test="$lparent.prefix != ''">
  465. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  466. <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/>
  467. </xsl:if>
  468. </xsl:if>
  469. </xsl:variable>
  470. <xsl:choose>
  471. <xsl:when test="$qandadiv.autolabel != 0">
  472. <xsl:variable name="format">
  473. <xsl:call-template name="autolabel.format">
  474. <xsl:with-param name="format" select="$qandadiv.autolabel"/>
  475. </xsl:call-template>
  476. </xsl:variable>
  477. <xsl:value-of select="$prefix"/>
  478. <xsl:number level="multiple" count="qandadiv" format="{$format}"/>
  479. </xsl:when>
  480. </xsl:choose>
  481. </xsl:template>
  482. <xsl:template match="question|answer" mode="label.markup">
  483. <xsl:variable name="lparent" select="(ancestor::set
  484. |ancestor::book
  485. |ancestor::chapter
  486. |ancestor::appendix
  487. |ancestor::preface
  488. |ancestor::section
  489. |ancestor::simplesect
  490. |ancestor::sect1
  491. |ancestor::sect2
  492. |ancestor::sect3
  493. |ancestor::sect4
  494. |ancestor::sect5
  495. |ancestor::refsect1
  496. |ancestor::refsect2
  497. |ancestor::refsect3)[last()]"/>
  498. <xsl:variable name="lparent.prefix">
  499. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  500. </xsl:variable>
  501. <xsl:variable name="prefix">
  502. <xsl:if test="$qanda.inherit.numeration != 0">
  503. <xsl:choose>
  504. <xsl:when test="ancestor::qandadiv">
  505. <xsl:apply-templates select="ancestor::qandadiv[1]" mode="label.markup"/>
  506. <xsl:apply-templates select="ancestor::qandadiv[1]"
  507. mode="intralabel.punctuation"/>
  508. </xsl:when>
  509. <xsl:when test="$lparent.prefix != ''">
  510. <xsl:apply-templates select="$lparent" mode="label.markup"/>
  511. <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/>
  512. </xsl:when>
  513. </xsl:choose>
  514. </xsl:if>
  515. </xsl:variable>
  516. <xsl:variable name="inhlabel"
  517. select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
  518. <xsl:variable name="deflabel">
  519. <xsl:choose>
  520. <xsl:when test="$inhlabel != ''">
  521. <xsl:value-of select="$inhlabel"/>
  522. </xsl:when>
  523. <xsl:otherwise>
  524. <xsl:value-of select="$qanda.defaultlabel"/>
  525. </xsl:otherwise>
  526. </xsl:choose>
  527. </xsl:variable>
  528. <xsl:variable name="label" select="label"/>
  529. <xsl:choose>
  530. <xsl:when test="count($label)>0">
  531. <xsl:apply-templates select="$label"/>
  532. </xsl:when>
  533. <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'question'">
  534. <xsl:call-template name="gentext">
  535. <xsl:with-param name="key" select="'Question'"/>
  536. </xsl:call-template>
  537. </xsl:when>
  538. <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'answer'">
  539. <xsl:call-template name="gentext">
  540. <xsl:with-param name="key" select="'Answer'"/>
  541. </xsl:call-template>
  542. </xsl:when>
  543. <xsl:when test="$deflabel = 'number' and local-name(.) = 'question'">
  544. <xsl:value-of select="$prefix"/>
  545. <xsl:number level="multiple" count="qandaentry" format="1"/>
  546. </xsl:when>
  547. </xsl:choose>
  548. </xsl:template>
  549. <xsl:template match="bibliography|glossary|
  550. qandaset|index|setindex" mode="label.markup">
  551. <xsl:if test="@label">
  552. <xsl:value-of select="@label"/>
  553. </xsl:if>
  554. </xsl:template>
  555. <xsl:template match="figure|table|example" mode="label.markup">
  556. <xsl:variable name="pchap"
  557. select="ancestor::chapter
  558. |ancestor::appendix
  559. |ancestor::article[ancestor::book]"/>
  560. <xsl:variable name="prefix">
  561. <xsl:if test="count($pchap) &gt; 0">
  562. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  563. </xsl:if>
  564. </xsl:variable>
  565. <xsl:choose>
  566. <xsl:when test="@label">
  567. <xsl:value-of select="@label"/>
  568. </xsl:when>
  569. <xsl:otherwise>
  570. <xsl:choose>
  571. <xsl:when test="$prefix != ''">
  572. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  573. <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
  574. <xsl:number format="1" from="chapter|appendix" level="any"/>
  575. </xsl:when>
  576. <xsl:otherwise>
  577. <xsl:number format="1" from="book|article" level="any"/>
  578. </xsl:otherwise>
  579. </xsl:choose>
  580. </xsl:otherwise>
  581. </xsl:choose>
  582. </xsl:template>
  583. <xsl:template match="procedure" mode="label.markup">
  584. <xsl:variable name="pchap"
  585. select="ancestor::chapter
  586. |ancestor::appendix
  587. |ancestor::article[ancestor::book]"/>
  588. <xsl:variable name="prefix">
  589. <xsl:if test="count($pchap) &gt; 0">
  590. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  591. </xsl:if>
  592. </xsl:variable>
  593. <xsl:choose>
  594. <xsl:when test="@label">
  595. <xsl:value-of select="@label"/>
  596. </xsl:when>
  597. <xsl:when test="$formal.procedures = 0">
  598. <!-- No label -->
  599. </xsl:when>
  600. <xsl:otherwise>
  601. <xsl:choose>
  602. <xsl:when test="count($pchap)>0">
  603. <xsl:if test="$prefix != ''">
  604. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  605. <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
  606. </xsl:if>
  607. <xsl:number count="procedure[title]" format="1"
  608. from="chapter|appendix" level="any"/>
  609. </xsl:when>
  610. <xsl:otherwise>
  611. <xsl:number count="procedure[title]" format="1"
  612. from="book|article" level="any"/>
  613. </xsl:otherwise>
  614. </xsl:choose>
  615. </xsl:otherwise>
  616. </xsl:choose>
  617. </xsl:template>
  618. <xsl:template match="equation" mode="label.markup">
  619. <xsl:variable name="pchap"
  620. select="ancestor::chapter
  621. |ancestor::appendix
  622. |ancestor::article[ancestor::book]"/>
  623. <xsl:variable name="prefix">
  624. <xsl:if test="count($pchap) &gt; 0">
  625. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  626. </xsl:if>
  627. </xsl:variable>
  628. <xsl:choose>
  629. <xsl:when test="@label">
  630. <xsl:value-of select="@label"/>
  631. </xsl:when>
  632. <xsl:otherwise>
  633. <xsl:choose>
  634. <xsl:when test="count($pchap)>0">
  635. <xsl:if test="$prefix != ''">
  636. <xsl:apply-templates select="$pchap" mode="label.markup"/>
  637. <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
  638. </xsl:if>
  639. <xsl:number format="1" count="equation[title or info/title]"
  640. from="chapter|appendix" level="any"/>
  641. </xsl:when>
  642. <xsl:otherwise>
  643. <xsl:number format="1" count="equation[title or info/title]"
  644. from="book|article" level="any"/>
  645. </xsl:otherwise>
  646. </xsl:choose>
  647. </xsl:otherwise>
  648. </xsl:choose>
  649. </xsl:template>
  650. <xsl:template match="orderedlist/listitem" mode="label.markup">
  651. <xsl:variable name="numeration">
  652. <xsl:call-template name="list.numeration">
  653. <xsl:with-param name="node" select="parent::orderedlist"/>
  654. </xsl:call-template>
  655. </xsl:variable>
  656. <xsl:variable name="type">
  657. <xsl:choose>
  658. <xsl:when test="$numeration='arabic'">1</xsl:when>
  659. <xsl:when test="$numeration='loweralpha'">a</xsl:when>
  660. <xsl:when test="$numeration='lowerroman'">i</xsl:when>
  661. <xsl:when test="$numeration='upperalpha'">A</xsl:when>
  662. <xsl:when test="$numeration='upperroman'">I</xsl:when>
  663. <!-- What!? This should never happen -->
  664. <xsl:otherwise>
  665. <xsl:message>
  666. <xsl:text>Unexpected numeration: </xsl:text>
  667. <xsl:value-of select="$numeration"/>
  668. </xsl:message>
  669. <xsl:value-of select="1."/>
  670. </xsl:otherwise>
  671. </xsl:choose>
  672. </xsl:variable>
  673. <xsl:variable name="item-number">
  674. <xsl:call-template name="orderedlist-item-number"/>
  675. </xsl:variable>
  676. <xsl:number value="$item-number" format="{$type}"/>
  677. </xsl:template>
  678. <xsl:template match="abstract" mode="label.markup">
  679. <!-- nop -->
  680. </xsl:template>
  681. <xsl:template match="sidebar" mode="label.markup">
  682. <!-- nop -->
  683. </xsl:template>
  684. <!-- ============================================================ -->
  685. <xsl:template name="label.this.section">
  686. <xsl:param name="section" select="."/>
  687. <xsl:variable name="level">
  688. <xsl:call-template name="section.level"/>
  689. </xsl:variable>
  690. <xsl:choose>
  691. <xsl:when test="$level &lt;= $section.autolabel.max.depth">
  692. <xsl:value-of select="$section.autolabel"/>
  693. </xsl:when>
  694. <xsl:otherwise>0</xsl:otherwise>
  695. </xsl:choose>
  696. </xsl:template>
  697. <doc:template name="label.this.section" xmlns="">
  698. <refpurpose>Returns true if $section should be labelled</refpurpose>
  699. <refdescription id="label.this.section-desc">
  700. <para>Returns true if the specified section should be labelled.
  701. By default, this template returns zero unless
  702. the section level is less than or equal to the value of the
  703. <literal>$section.autolabel.max.depth</literal> parameter, in
  704. which case it returns
  705. <literal>$section.autolabel</literal>.
  706. Custom stylesheets may override it to get more selective behavior.</para>
  707. </refdescription>
  708. </doc:template>
  709. <!-- ============================================================ -->
  710. <xsl:template name="default.autolabel.format">
  711. <xsl:param name="context" select="."/>
  712. <xsl:choose>
  713. <xsl:when test="local-name($context) = 'appendix'">
  714. <xsl:value-of select="'A'"/>
  715. </xsl:when>
  716. <xsl:when test="local-name($context) = 'part'">
  717. <xsl:value-of select="'I'"/>
  718. </xsl:when>
  719. <xsl:otherwise>1</xsl:otherwise>
  720. </xsl:choose>
  721. </xsl:template>
  722. <xsl:template name="autolabel.format">
  723. <xsl:param name="context" select="."/>
  724. <xsl:param name="format"/>
  725. <xsl:choose>
  726. <xsl:when test="string($format) != 0">
  727. <xsl:choose>
  728. <xsl:when test="string($format)='arabic' or $format='1'">1</xsl:when>
  729. <xsl:when test="$format='loweralpha' or $format='a'">
  730. <xsl:value-of select="'a'"/>
  731. </xsl:when>
  732. <xsl:when test="$format='lowerroman' or $format='i'">
  733. <xsl:value-of select="'i'"/>
  734. </xsl:when>
  735. <xsl:when test="$format='upperalpha' or $format='A'">
  736. <xsl:value-of select="'A'"/>
  737. </xsl:when>
  738. <xsl:when test="$format='upperroman' or $format='I'">
  739. <xsl:value-of select="'I'"/>
  740. </xsl:when>
  741. <xsl:when test="$format='arabicindic' or $format='&#x661;'">
  742. <xsl:value-of select="'&#x661;'"/>
  743. </xsl:when>
  744. <xsl:otherwise>
  745. <xsl:message>
  746. <xsl:text>Unexpected </xsl:text><xsl:value-of select="local-name(.)"/><xsl:text>.autolabel value: </xsl:text>
  747. <xsl:value-of select="$format"/><xsl:text>; using default.</xsl:text>
  748. </xsl:message>
  749. <xsl:call-template name="default.autolabel.format"/>
  750. </xsl:otherwise>
  751. </xsl:choose>
  752. </xsl:when>
  753. </xsl:choose>
  754. </xsl:template>
  755. <doc:template name="autolabel.format" xmlns="">
  756. <refpurpose>Returns format for autolabel parameters</refpurpose>
  757. <refdescription id="autolabel.format-desc">
  758. <para>Returns format passed as parameter if non zero. Supported
  759. format are 'arabic' or '1', 'loweralpha' or 'a', 'lowerroman' or 'i',
  760. 'upperlapha' or 'A', 'upperroman' or 'I', 'arabicindic' or '&#x661;'.
  761. If its not one of these then
  762. returns the default format.</para>
  763. </refdescription>
  764. </doc:template>
  765. <!-- ============================================================ -->
  766. </xsl:stylesheet>