common.xsl 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028
  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. xmlns:dyn="http://exslt.org/dynamic"
  5. xmlns:saxon="http://icl.com/saxon"
  6. exclude-result-prefixes="doc dyn saxon"
  7. version='1.0'>
  8. <!-- ********************************************************************
  9. $Id$
  10. ********************************************************************
  11. This file is part of the XSL DocBook Stylesheet distribution.
  12. See ../README or http://docbook.sf.net/release/xsl/current/ for
  13. copyright and other information.
  14. This file contains general templates common to both the HTML and FO
  15. versions of the DocBook stylesheets.
  16. ******************************************************************** -->
  17. <doc:reference xmlns="">
  18. <referenceinfo>
  19. <releaseinfo role="meta">
  20. $Id$
  21. </releaseinfo>
  22. <author><surname>Walsh</surname>
  23. <firstname>Norman</firstname></author>
  24. <copyright><year>1999-2007</year>
  25. <holder>Norman Walsh</holder>
  26. </copyright>
  27. </referenceinfo>
  28. <title>Common Template Reference</title>
  29. <partintro id="partintro">
  30. <title>Introduction</title>
  31. <para>This is technical reference documentation for the “common”
  32. templates in the DocBook XSL Stylesheets. The common templates are
  33. “common” because they are shared across output formats (that is,
  34. they’re not output-format-dependent).</para>
  35. <para>This documentation is not intended to be <quote>user</quote>
  36. documentation. It is provided for developers writing
  37. customization layers for the stylesheets, and for anyone who's
  38. interested in <quote>how it works</quote>.</para>
  39. </partintro>
  40. </doc:reference>
  41. <!-- ==================================================================== -->
  42. <!-- Establish strip/preserve whitespace rules -->
  43. <xsl:preserve-space elements="*"/>
  44. <xsl:strip-space elements="
  45. abstract affiliation anchor answer appendix area areaset areaspec
  46. artheader article audiodata audioobject author authorblurb authorgroup
  47. beginpage bibliodiv biblioentry bibliography biblioset blockquote book
  48. bookbiblio bookinfo callout calloutlist caption caution chapter
  49. citerefentry cmdsynopsis co collab colophon colspec confgroup
  50. copyright dedication docinfo editor entrytbl epigraph equation
  51. example figure footnote footnoteref formalpara funcprototype
  52. funcsynopsis glossary glossdef glossdiv glossentry glosslist graphicco
  53. group highlights imagedata imageobject imageobjectco important index
  54. indexdiv indexentry indexterm info informalequation informalexample
  55. informalfigure informaltable inlineequation inlinemediaobject
  56. itemizedlist itermset keycombo keywordset legalnotice listitem lot
  57. mediaobject mediaobjectco menuchoice msg msgentry msgexplan msginfo
  58. msgmain msgrel msgset msgsub msgtext note objectinfo
  59. orderedlist othercredit part partintro preface printhistory procedure
  60. programlistingco publisher qandadiv qandaentry qandaset question
  61. refentry reference refmeta refnamediv refsection refsect1 refsect1info refsect2
  62. refsect2info refsect3 refsect3info refsynopsisdiv refsynopsisdivinfo
  63. revhistory revision row sbr screenco screenshot sect1 sect1info sect2
  64. sect2info sect3 sect3info sect4 sect4info sect5 sect5info section
  65. sectioninfo seglistitem segmentedlist seriesinfo set setindex setinfo
  66. shortcut sidebar simplelist simplesect spanspec step subject
  67. subjectset substeps synopfragment table tbody textobject tfoot tgroup
  68. thead tip toc tocchap toclevel1 toclevel2 toclevel3 toclevel4
  69. toclevel5 tocpart varargs variablelist varlistentry videodata
  70. videoobject void warning subjectset
  71. classsynopsis
  72. constructorsynopsis
  73. destructorsynopsis
  74. fieldsynopsis
  75. methodparam
  76. methodsynopsis
  77. ooclass
  78. ooexception
  79. oointerface
  80. simplemsgentry
  81. manvolnum
  82. "/>
  83. <!-- ====================================================================== -->
  84. <doc:template name="is.component" xmlns="">
  85. <refpurpose>Tests if a given node is a component-level element</refpurpose>
  86. <refdescription id="is.component-desc">
  87. <para>This template returns '1' if the specified node is a component
  88. (Chapter, Appendix, etc.), and '0' otherwise.</para>
  89. </refdescription>
  90. <refparameter id="is.component-params">
  91. <variablelist>
  92. <varlistentry><term>node</term>
  93. <listitem>
  94. <para>The node which is to be tested.</para>
  95. </listitem>
  96. </varlistentry>
  97. </variablelist>
  98. </refparameter>
  99. <refreturn id="is.component-returns">
  100. <para>This template returns '1' if the specified node is a component
  101. (Chapter, Appendix, etc.), and '0' otherwise.</para>
  102. </refreturn>
  103. </doc:template>
  104. <xsl:template name="is.component">
  105. <xsl:param name="node" select="."/>
  106. <xsl:choose>
  107. <xsl:when test="local-name($node) = 'appendix'
  108. or local-name($node) = 'article'
  109. or local-name($node) = 'chapter'
  110. or local-name($node) = 'preface'
  111. or local-name($node) = 'bibliography'
  112. or local-name($node) = 'glossary'
  113. or local-name($node) = 'index'">1</xsl:when>
  114. <xsl:otherwise>0</xsl:otherwise>
  115. </xsl:choose>
  116. </xsl:template>
  117. <!-- ====================================================================== -->
  118. <doc:template name="is.section" xmlns="">
  119. <refpurpose>Tests if a given node is a section-level element</refpurpose>
  120. <refdescription id="is.section-desc">
  121. <para>This template returns '1' if the specified node is a section
  122. (Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
  123. </refdescription>
  124. <refparameter id="is.section-params">
  125. <variablelist>
  126. <varlistentry><term>node</term>
  127. <listitem>
  128. <para>The node which is to be tested.</para>
  129. </listitem>
  130. </varlistentry>
  131. </variablelist>
  132. </refparameter>
  133. <refreturn id="is.section-returns">
  134. <para>This template returns '1' if the specified node is a section
  135. (Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
  136. </refreturn>
  137. </doc:template>
  138. <xsl:template name="is.section">
  139. <xsl:param name="node" select="."/>
  140. <xsl:choose>
  141. <xsl:when test="local-name($node) = 'section'
  142. or local-name($node) = 'sect1'
  143. or local-name($node) = 'sect2'
  144. or local-name($node) = 'sect3'
  145. or local-name($node) = 'sect4'
  146. or local-name($node) = 'sect5'
  147. or local-name($node) = 'refsect1'
  148. or local-name($node) = 'refsect2'
  149. or local-name($node) = 'refsect3'
  150. or local-name($node) = 'simplesect'">1</xsl:when>
  151. <xsl:otherwise>0</xsl:otherwise>
  152. </xsl:choose>
  153. </xsl:template>
  154. <!-- ====================================================================== -->
  155. <doc:template name="section.level" xmlns="">
  156. <refpurpose>Returns the hierarchical level of a section</refpurpose>
  157. <refdescription id="section.level-desc">
  158. <para>This template calculates the hierarchical level of a section.
  159. The element <sgmltag>sect1</sgmltag> is at level 1, <sgmltag>sect2</sgmltag> is
  160. at level 2, etc.</para>
  161. <para>Recursive sections are calculated down to the fifth level.</para>
  162. </refdescription>
  163. <refparameter id="section.level-params">
  164. <variablelist>
  165. <varlistentry><term>node</term>
  166. <listitem>
  167. <para>The section node for which the level should be calculated.
  168. Defaults to the context node.</para>
  169. </listitem>
  170. </varlistentry>
  171. </variablelist>
  172. </refparameter>
  173. <refreturn id="section.level-returns">
  174. <para>The section level, <quote>1</quote>, <quote>2</quote>, etc.
  175. </para>
  176. </refreturn>
  177. </doc:template>
  178. <xsl:template name="section.level">
  179. <xsl:param name="node" select="."/>
  180. <xsl:choose>
  181. <xsl:when test="local-name($node)='sect1'">1</xsl:when>
  182. <xsl:when test="local-name($node)='sect2'">2</xsl:when>
  183. <xsl:when test="local-name($node)='sect3'">3</xsl:when>
  184. <xsl:when test="local-name($node)='sect4'">4</xsl:when>
  185. <xsl:when test="local-name($node)='sect5'">5</xsl:when>
  186. <xsl:when test="local-name($node)='section'">
  187. <xsl:choose>
  188. <xsl:when test="$node/../../../../../../section">6</xsl:when>
  189. <xsl:when test="$node/../../../../../section">5</xsl:when>
  190. <xsl:when test="$node/../../../../section">4</xsl:when>
  191. <xsl:when test="$node/../../../section">3</xsl:when>
  192. <xsl:when test="$node/../../section">2</xsl:when>
  193. <xsl:otherwise>1</xsl:otherwise>
  194. </xsl:choose>
  195. </xsl:when>
  196. <xsl:when test="local-name($node)='refsect1' or
  197. local-name($node)='refsect2' or
  198. local-name($node)='refsect3' or
  199. local-name($node)='refsection' or
  200. local-name($node)='refsynopsisdiv'">
  201. <xsl:call-template name="refentry.section.level">
  202. <xsl:with-param name="node" select="$node"/>
  203. </xsl:call-template>
  204. </xsl:when>
  205. <xsl:when test="local-name($node)='simplesect'">
  206. <xsl:choose>
  207. <xsl:when test="$node/../../sect1">2</xsl:when>
  208. <xsl:when test="$node/../../sect2">3</xsl:when>
  209. <xsl:when test="$node/../../sect3">4</xsl:when>
  210. <xsl:when test="$node/../../sect4">5</xsl:when>
  211. <xsl:when test="$node/../../sect5">5</xsl:when>
  212. <xsl:when test="$node/../../section">
  213. <xsl:choose>
  214. <xsl:when test="$node/../../../../../section">5</xsl:when>
  215. <xsl:when test="$node/../../../../section">4</xsl:when>
  216. <xsl:when test="$node/../../../section">3</xsl:when>
  217. <xsl:otherwise>2</xsl:otherwise>
  218. </xsl:choose>
  219. </xsl:when>
  220. <xsl:otherwise>1</xsl:otherwise>
  221. </xsl:choose>
  222. </xsl:when>
  223. <xsl:otherwise>1</xsl:otherwise>
  224. </xsl:choose>
  225. </xsl:template><!-- section.level -->
  226. <doc:template name="qanda.section.level" xmlns="">
  227. <refpurpose>Returns the hierarchical level of a QandASet</refpurpose>
  228. <refdescription id="qanda.section.level-desc">
  229. <para>This template calculates the hierarchical level of a QandASet.
  230. </para>
  231. </refdescription>
  232. <refreturn id="qanda.section.level-returns">
  233. <para>The level, <quote>1</quote>, <quote>2</quote>, etc.
  234. </para>
  235. </refreturn>
  236. </doc:template>
  237. <xsl:template name="qanda.section.level">
  238. <xsl:variable name="section"
  239. select="(ancestor::section
  240. |ancestor::simplesect
  241. |ancestor::sect5
  242. |ancestor::sect4
  243. |ancestor::sect3
  244. |ancestor::sect2
  245. |ancestor::sect1
  246. |ancestor::refsect3
  247. |ancestor::refsect2
  248. |ancestor::refsect1)[last()]"/>
  249. <xsl:choose>
  250. <xsl:when test="count($section) = '0'">1</xsl:when>
  251. <xsl:otherwise>
  252. <xsl:variable name="slevel">
  253. <xsl:call-template name="section.level">
  254. <xsl:with-param name="node" select="$section"/>
  255. </xsl:call-template>
  256. </xsl:variable>
  257. <xsl:value-of select="$slevel + 1"/>
  258. </xsl:otherwise>
  259. </xsl:choose>
  260. </xsl:template>
  261. <!-- Finds the total section depth of a section in a refentry -->
  262. <xsl:template name="refentry.section.level">
  263. <xsl:param name="node" select="."/>
  264. <xsl:variable name="RElevel">
  265. <xsl:call-template name="refentry.level">
  266. <xsl:with-param name="node" select="$node/ancestor::refentry[1]"/>
  267. </xsl:call-template>
  268. </xsl:variable>
  269. <xsl:variable name="levelinRE">
  270. <xsl:choose>
  271. <xsl:when test="local-name($node)='refsynopsisdiv'">1</xsl:when>
  272. <xsl:when test="local-name($node)='refsect1'">1</xsl:when>
  273. <xsl:when test="local-name($node)='refsect2'">2</xsl:when>
  274. <xsl:when test="local-name($node)='refsect3'">3</xsl:when>
  275. <xsl:when test="local-name($node)='refsection'">
  276. <xsl:choose>
  277. <xsl:when test="$node/../../../../../refsection">5</xsl:when>
  278. <xsl:when test="$node/../../../../refsection">4</xsl:when>
  279. <xsl:when test="$node/../../../refsection">3</xsl:when>
  280. <xsl:when test="$node/../../refsection">2</xsl:when>
  281. <xsl:otherwise>1</xsl:otherwise>
  282. </xsl:choose>
  283. </xsl:when>
  284. </xsl:choose>
  285. </xsl:variable>
  286. <xsl:value-of select="$levelinRE + $RElevel"/>
  287. </xsl:template>
  288. <!-- Finds the section depth of a refentry -->
  289. <xsl:template name="refentry.level">
  290. <xsl:param name="node" select="."/>
  291. <xsl:variable name="container"
  292. select="($node/ancestor::section |
  293. $node/ancestor::sect1 |
  294. $node/ancestor::sect2 |
  295. $node/ancestor::sect3 |
  296. $node/ancestor::sect4 |
  297. $node/ancestor::sect5)[last()]"/>
  298. <xsl:choose>
  299. <xsl:when test="$container">
  300. <xsl:variable name="slevel">
  301. <xsl:call-template name="section.level">
  302. <xsl:with-param name="node" select="$container"/>
  303. </xsl:call-template>
  304. </xsl:variable>
  305. <xsl:value-of select="$slevel + 1"/>
  306. </xsl:when>
  307. <xsl:otherwise>1</xsl:otherwise>
  308. </xsl:choose>
  309. </xsl:template>
  310. <xsl:template name="qandadiv.section.level">
  311. <xsl:variable name="section.level">
  312. <xsl:call-template name="qanda.section.level"/>
  313. </xsl:variable>
  314. <xsl:variable name="anc.divs" select="ancestor::qandadiv"/>
  315. <xsl:value-of select="count($anc.divs) + number($section.level)"/>
  316. </xsl:template>
  317. <xsl:template name="question.answer.label">
  318. <xsl:variable name="deflabel">
  319. <xsl:choose>
  320. <xsl:when test="ancestor-or-self::*[@defaultlabel]">
  321. <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
  322. /@defaultlabel"/>
  323. </xsl:when>
  324. <xsl:otherwise>
  325. <xsl:value-of select="$qanda.defaultlabel"/>
  326. </xsl:otherwise>
  327. </xsl:choose>
  328. </xsl:variable>
  329. <xsl:variable name="label" select="@label"/>
  330. <!--
  331. (hnr (hierarchical-number-recursive (normalize "qandadiv") node))
  332. (parsect (ancestor-member node (section-element-list)))
  333. (defnum (if (and %qanda-inherit-numeration%
  334. %section-autolabel%)
  335. (if (node-list-empty? parsect)
  336. (section-autolabel-prefix node)
  337. (section-autolabel parsect))
  338. ""))
  339. (hnumber (let loop ((numlist hnr) (number defnum)
  340. (sep (if (equal? defnum "") "" ".")))
  341. (if (null? numlist)
  342. number
  343. (loop (cdr numlist)
  344. (string-append number
  345. sep
  346. (number->string (car numlist)))
  347. "."))))
  348. (cnumber (child-number (parent node)))
  349. (number (string-append hnumber
  350. (if (equal? hnumber "")
  351. ""
  352. ".")
  353. (number->string cnumber))))
  354. -->
  355. <xsl:choose>
  356. <xsl:when test="$deflabel = 'qanda'">
  357. <xsl:call-template name="gentext">
  358. <xsl:with-param name="key">
  359. <xsl:choose>
  360. <xsl:when test="local-name(.) = 'question'">question</xsl:when>
  361. <xsl:when test="local-name(.) = 'answer'">answer</xsl:when>
  362. <xsl:when test="local-name(.) = 'qandadiv'">qandadiv</xsl:when>
  363. <xsl:otherwise>qandaset</xsl:otherwise>
  364. </xsl:choose>
  365. </xsl:with-param>
  366. </xsl:call-template>
  367. </xsl:when>
  368. <xsl:when test="$deflabel = 'label'">
  369. <xsl:value-of select="$label"/>
  370. </xsl:when>
  371. <xsl:when test="$deflabel = 'number'
  372. and local-name(.) = 'question'">
  373. <xsl:apply-templates select="ancestor::qandaset[1]"
  374. mode="number"/>
  375. <xsl:choose>
  376. <xsl:when test="ancestor::qandadiv">
  377. <xsl:apply-templates select="ancestor::qandadiv[1]"
  378. mode="number"/>
  379. <xsl:apply-templates select="ancestor::qandaentry"
  380. mode="number"/>
  381. </xsl:when>
  382. <xsl:otherwise>
  383. <xsl:apply-templates select="ancestor::qandaentry"
  384. mode="number"/>
  385. </xsl:otherwise>
  386. </xsl:choose>
  387. </xsl:when>
  388. <xsl:otherwise>
  389. <!-- nothing -->
  390. </xsl:otherwise>
  391. </xsl:choose>
  392. </xsl:template>
  393. <xsl:template match="qandaset" mode="number">
  394. <!-- FIXME: -->
  395. </xsl:template>
  396. <xsl:template match="qandadiv" mode="number">
  397. <xsl:number level="multiple" from="qandaset" format="1."/>
  398. </xsl:template>
  399. <xsl:template match="qandaentry" mode="number">
  400. <xsl:choose>
  401. <xsl:when test="ancestor::qandadiv">
  402. <xsl:number level="single" from="qandadiv" format="1."/>
  403. </xsl:when>
  404. <xsl:otherwise>
  405. <xsl:number level="single" from="qandaset" format="1."/>
  406. </xsl:otherwise>
  407. </xsl:choose>
  408. </xsl:template>
  409. <!-- ====================================================================== -->
  410. <xsl:template name="object.id">
  411. <xsl:param name="object" select="."/>
  412. <xsl:choose>
  413. <xsl:when test="$object/@id">
  414. <xsl:value-of select="$object/@id"/>
  415. </xsl:when>
  416. <xsl:when test="$object/@xml:id">
  417. <xsl:value-of select="$object/@xml:id"/>
  418. </xsl:when>
  419. <xsl:otherwise>
  420. <xsl:value-of select="generate-id($object)"/>
  421. </xsl:otherwise>
  422. </xsl:choose>
  423. </xsl:template>
  424. <xsl:template name="person.name">
  425. <!-- Formats a personal name. Handles corpauthor as a special case. -->
  426. <xsl:param name="node" select="."/>
  427. <xsl:variable name="style">
  428. <xsl:choose>
  429. <xsl:when test="$node/@role">
  430. <xsl:value-of select="$node/@role"/>
  431. </xsl:when>
  432. <xsl:otherwise>
  433. <xsl:call-template name="gentext.template">
  434. <xsl:with-param name="context" select="'styles'"/>
  435. <xsl:with-param name="name" select="'person-name'"/>
  436. </xsl:call-template>
  437. </xsl:otherwise>
  438. </xsl:choose>
  439. </xsl:variable>
  440. <xsl:choose>
  441. <!-- the personname element is a specialcase -->
  442. <xsl:when test="$node/personname">
  443. <xsl:call-template name="person.name">
  444. <xsl:with-param name="node" select="$node/personname"/>
  445. </xsl:call-template>
  446. </xsl:when>
  447. <!-- handle corpauthor as a special case...-->
  448. <!-- * MikeSmith 2007-06: I'm wondering if the person.name template -->
  449. <!-- * actually ever gets called to handle corpauthor.. maybe -->
  450. <!-- * we don't actually need to check for corpauthor here. -->
  451. <xsl:when test="local-name($node)='corpauthor'">
  452. <xsl:apply-templates select="$node"/>
  453. </xsl:when>
  454. <xsl:otherwise>
  455. <xsl:choose>
  456. <!-- Handle case when personname contains only general markup (DocBook 5.0) -->
  457. <xsl:when test="$node/self::personname and not($node/firstname or $node/honorific or $node/lineage or $node/othername or $node/surname)">
  458. <xsl:apply-templates select="$node/node()"/>
  459. </xsl:when>
  460. <xsl:when test="$style = 'family-given'">
  461. <xsl:call-template name="person.name.family-given">
  462. <xsl:with-param name="node" select="$node"/>
  463. </xsl:call-template>
  464. </xsl:when>
  465. <xsl:when test="$style = 'last-first'">
  466. <xsl:call-template name="person.name.last-first">
  467. <xsl:with-param name="node" select="$node"/>
  468. </xsl:call-template>
  469. </xsl:when>
  470. <xsl:otherwise>
  471. <xsl:call-template name="person.name.first-last">
  472. <xsl:with-param name="node" select="$node"/>
  473. </xsl:call-template>
  474. </xsl:otherwise>
  475. </xsl:choose>
  476. </xsl:otherwise>
  477. </xsl:choose>
  478. </xsl:template>
  479. <xsl:template name="person.name.family-given">
  480. <xsl:param name="node" select="."/>
  481. <!-- The family-given style applies a convention for identifying given -->
  482. <!-- and family names in locales where it may be ambiguous -->
  483. <xsl:apply-templates select="$node//surname[1]"/>
  484. <xsl:if test="$node//surname and $node//firstname">
  485. <xsl:text> </xsl:text>
  486. </xsl:if>
  487. <xsl:apply-templates select="$node//firstname[1]"/>
  488. <xsl:text> [FAMILY Given]</xsl:text>
  489. </xsl:template>
  490. <xsl:template name="person.name.last-first">
  491. <xsl:param name="node" select="."/>
  492. <xsl:apply-templates select="$node//surname[1]"/>
  493. <xsl:if test="$node//surname and $node//firstname">
  494. <xsl:text>, </xsl:text>
  495. </xsl:if>
  496. <xsl:apply-templates select="$node//firstname[1]"/>
  497. </xsl:template>
  498. <xsl:template name="person.name.first-last">
  499. <xsl:param name="node" select="."/>
  500. <xsl:if test="$node//honorific">
  501. <xsl:apply-templates select="$node//honorific[1]"/>
  502. <xsl:value-of select="$punct.honorific"/>
  503. </xsl:if>
  504. <xsl:if test="$node//firstname">
  505. <xsl:if test="$node//honorific">
  506. <xsl:text> </xsl:text>
  507. </xsl:if>
  508. <xsl:apply-templates select="$node//firstname[1]"/>
  509. </xsl:if>
  510. <xsl:if test="$node//othername and $author.othername.in.middle != 0">
  511. <xsl:if test="$node//honorific or $node//firstname">
  512. <xsl:text> </xsl:text>
  513. </xsl:if>
  514. <xsl:apply-templates select="$node//othername[1]"/>
  515. </xsl:if>
  516. <xsl:if test="$node//surname">
  517. <xsl:if test="$node//honorific or $node//firstname
  518. or ($node//othername and $author.othername.in.middle != 0)">
  519. <xsl:text> </xsl:text>
  520. </xsl:if>
  521. <xsl:apply-templates select="$node//surname[1]"/>
  522. </xsl:if>
  523. <xsl:if test="$node//lineage">
  524. <xsl:text>, </xsl:text>
  525. <xsl:apply-templates select="$node//lineage[1]"/>
  526. </xsl:if>
  527. </xsl:template>
  528. <xsl:template name="person.name.list">
  529. <!-- Return a formatted string representation of the contents of
  530. the current element. The current element must contain one or
  531. more AUTHORs, CORPAUTHORs, OTHERCREDITs, and/or EDITORs.
  532. John Doe
  533. or
  534. John Doe and Jane Doe
  535. or
  536. John Doe, Jane Doe, and A. Nonymous
  537. -->
  538. <xsl:param name="person.list"
  539. select="author|corpauthor|othercredit|editor"/>
  540. <xsl:param name="person.count" select="count($person.list)"/>
  541. <xsl:param name="count" select="1"/>
  542. <xsl:choose>
  543. <xsl:when test="$count &gt; $person.count"></xsl:when>
  544. <xsl:otherwise>
  545. <xsl:call-template name="person.name">
  546. <xsl:with-param name="node" select="$person.list[position()=$count]"/>
  547. </xsl:call-template>
  548. <xsl:choose>
  549. <xsl:when test="$person.count = 2 and $count = 1">
  550. <xsl:call-template name="gentext.template">
  551. <xsl:with-param name="context" select="'authorgroup'"/>
  552. <xsl:with-param name="name" select="'sep2'"/>
  553. </xsl:call-template>
  554. </xsl:when>
  555. <xsl:when test="$person.count &gt; 2 and $count+1 = $person.count">
  556. <xsl:call-template name="gentext.template">
  557. <xsl:with-param name="context" select="'authorgroup'"/>
  558. <xsl:with-param name="name" select="'seplast'"/>
  559. </xsl:call-template>
  560. </xsl:when>
  561. <xsl:when test="$count &lt; $person.count">
  562. <xsl:call-template name="gentext.template">
  563. <xsl:with-param name="context" select="'authorgroup'"/>
  564. <xsl:with-param name="name" select="'sep'"/>
  565. </xsl:call-template>
  566. </xsl:when>
  567. </xsl:choose>
  568. <xsl:call-template name="person.name.list">
  569. <xsl:with-param name="person.list" select="$person.list"/>
  570. <xsl:with-param name="person.count" select="$person.count"/>
  571. <xsl:with-param name="count" select="$count+1"/>
  572. </xsl:call-template>
  573. </xsl:otherwise>
  574. </xsl:choose>
  575. </xsl:template><!-- person.name.list -->
  576. <!-- === synopsis ======================================================= -->
  577. <!-- The following definitions match those given in the reference
  578. documentation for DocBook V3.0
  579. -->
  580. <xsl:variable name="arg.choice.opt.open.str">[</xsl:variable>
  581. <xsl:variable name="arg.choice.opt.close.str">]</xsl:variable>
  582. <xsl:variable name="arg.choice.req.open.str">{</xsl:variable>
  583. <xsl:variable name="arg.choice.req.close.str">}</xsl:variable>
  584. <xsl:variable name="arg.choice.plain.open.str"><xsl:text> </xsl:text></xsl:variable>
  585. <xsl:variable name="arg.choice.plain.close.str"><xsl:text> </xsl:text></xsl:variable>
  586. <xsl:variable name="arg.choice.def.open.str">[</xsl:variable>
  587. <xsl:variable name="arg.choice.def.close.str">]</xsl:variable>
  588. <xsl:variable name="arg.rep.repeat.str">...</xsl:variable>
  589. <xsl:variable name="arg.rep.norepeat.str"></xsl:variable>
  590. <xsl:variable name="arg.rep.def.str"></xsl:variable>
  591. <xsl:variable name="arg.or.sep"> | </xsl:variable>
  592. <xsl:variable name="cmdsynopsis.hanging.indent">4pi</xsl:variable>
  593. <!-- ====================================================================== -->
  594. <!--
  595. <xsl:template name="xref.g.subst">
  596. <xsl:param name="string"></xsl:param>
  597. <xsl:param name="target" select="."/>
  598. <xsl:variable name="subst">%g</xsl:variable>
  599. <xsl:choose>
  600. <xsl:when test="contains($string, $subst)">
  601. <xsl:value-of select="substring-before($string, $subst)"/>
  602. <xsl:call-template name="gentext.element.name">
  603. <xsl:with-param name="element.name" select="local-name($target)"/>
  604. </xsl:call-template>
  605. <xsl:call-template name="xref.g.subst">
  606. <xsl:with-param name="string"
  607. select="substring-after($string, $subst)"/>
  608. <xsl:with-param name="target" select="$target"/>
  609. </xsl:call-template>
  610. </xsl:when>
  611. <xsl:otherwise>
  612. <xsl:value-of select="$string"/>
  613. </xsl:otherwise>
  614. </xsl:choose>
  615. </xsl:template>
  616. <xsl:template name="xref.t.subst">
  617. <xsl:param name="string"></xsl:param>
  618. <xsl:param name="target" select="."/>
  619. <xsl:variable name="subst">%t</xsl:variable>
  620. <xsl:choose>
  621. <xsl:when test="contains($string, $subst)">
  622. <xsl:call-template name="xref.g.subst">
  623. <xsl:with-param name="string"
  624. select="substring-before($string, $subst)"/>
  625. <xsl:with-param name="target" select="$target"/>
  626. </xsl:call-template>
  627. <xsl:call-template name="title.xref">
  628. <xsl:with-param name="target" select="$target"/>
  629. </xsl:call-template>
  630. <xsl:call-template name="xref.t.subst">
  631. <xsl:with-param name="string"
  632. select="substring-after($string, $subst)"/>
  633. <xsl:with-param name="target" select="$target"/>
  634. </xsl:call-template>
  635. </xsl:when>
  636. <xsl:otherwise>
  637. <xsl:call-template name="xref.g.subst">
  638. <xsl:with-param name="string" select="$string"/>
  639. <xsl:with-param name="target" select="$target"/>
  640. </xsl:call-template>
  641. </xsl:otherwise>
  642. </xsl:choose>
  643. </xsl:template>
  644. <xsl:template name="xref.n.subst">
  645. <xsl:param name="string"></xsl:param>
  646. <xsl:param name="target" select="."/>
  647. <xsl:variable name="subst">%n</xsl:variable>
  648. <xsl:choose>
  649. <xsl:when test="contains($string, $subst)">
  650. <xsl:call-template name="xref.t.subst">
  651. <xsl:with-param name="string"
  652. select="substring-before($string, $subst)"/>
  653. <xsl:with-param name="target" select="$target"/>
  654. </xsl:call-template>
  655. <xsl:call-template name="number.xref">
  656. <xsl:with-param name="target" select="$target"/>
  657. </xsl:call-template>
  658. <xsl:call-template name="xref.t.subst">
  659. <xsl:with-param name="string"
  660. select="substring-after($string, $subst)"/>
  661. <xsl:with-param name="target" select="$target"/>
  662. </xsl:call-template>
  663. </xsl:when>
  664. <xsl:otherwise>
  665. <xsl:call-template name="xref.t.subst">
  666. <xsl:with-param name="string" select="$string"/>
  667. <xsl:with-param name="target" select="$target"/>
  668. </xsl:call-template>
  669. </xsl:otherwise>
  670. </xsl:choose>
  671. </xsl:template>
  672. <xsl:template name="subst.xref.text">
  673. <xsl:param name="xref.text"></xsl:param>
  674. <xsl:param name="target" select="."/>
  675. <xsl:call-template name="xref.n.subst">
  676. <xsl:with-param name="string" select="$xref.text"/>
  677. <xsl:with-param name="target" select="$target"/>
  678. </xsl:call-template>
  679. </xsl:template>
  680. -->
  681. <!-- ====================================================================== -->
  682. <xsl:template name="filename-basename">
  683. <!-- We assume all filenames are really URIs and use "/" -->
  684. <xsl:param name="filename"></xsl:param>
  685. <xsl:param name="recurse" select="false()"/>
  686. <xsl:choose>
  687. <xsl:when test="substring-after($filename, '/') != ''">
  688. <xsl:call-template name="filename-basename">
  689. <xsl:with-param name="filename"
  690. select="substring-after($filename, '/')"/>
  691. <xsl:with-param name="recurse" select="true()"/>
  692. </xsl:call-template>
  693. </xsl:when>
  694. <xsl:otherwise>
  695. <xsl:value-of select="$filename"/>
  696. </xsl:otherwise>
  697. </xsl:choose>
  698. </xsl:template>
  699. <xsl:template name="filename-extension">
  700. <xsl:param name="filename"></xsl:param>
  701. <xsl:param name="recurse" select="false()"/>
  702. <!-- Make sure we only look at the base name... -->
  703. <xsl:variable name="basefn">
  704. <xsl:choose>
  705. <xsl:when test="$recurse">
  706. <xsl:value-of select="$filename"/>
  707. </xsl:when>
  708. <xsl:otherwise>
  709. <xsl:call-template name="filename-basename">
  710. <xsl:with-param name="filename" select="$filename"/>
  711. </xsl:call-template>
  712. </xsl:otherwise>
  713. </xsl:choose>
  714. </xsl:variable>
  715. <xsl:choose>
  716. <xsl:when test="substring-after($basefn, '.') != ''">
  717. <xsl:call-template name="filename-extension">
  718. <xsl:with-param name="filename"
  719. select="substring-after($basefn, '.')"/>
  720. <xsl:with-param name="recurse" select="true()"/>
  721. </xsl:call-template>
  722. </xsl:when>
  723. <xsl:when test="$recurse">
  724. <xsl:value-of select="$basefn"/>
  725. </xsl:when>
  726. <xsl:otherwise></xsl:otherwise>
  727. </xsl:choose>
  728. </xsl:template>
  729. <!-- ====================================================================== -->
  730. <doc:template name="select.mediaobject" xmlns="">
  731. <refpurpose>Selects and processes an appropriate media object from a list</refpurpose>
  732. <refdescription id="select.mediaobject-desc">
  733. <para>This template takes a list of media objects (usually the
  734. children of a mediaobject or inlinemediaobject) and processes
  735. the "right" object.</para>
  736. <para>This template relies on a template named
  737. "select.mediaobject.index" to determine which object
  738. in the list is appropriate.</para>
  739. <para>If no acceptable object is located, nothing happens.</para>
  740. </refdescription>
  741. <refparameter id="select.mediaobject-params">
  742. <variablelist>
  743. <varlistentry><term>olist</term>
  744. <listitem>
  745. <para>The node list of potential objects to examine.</para>
  746. </listitem>
  747. </varlistentry>
  748. </variablelist>
  749. </refparameter>
  750. <refreturn id="select.mediaobject-returns">
  751. <para>Calls &lt;xsl:apply-templates&gt; on the selected object.</para>
  752. </refreturn>
  753. </doc:template>
  754. <xsl:template name="select.mediaobject">
  755. <xsl:param name="olist"
  756. select="imageobject|imageobjectco
  757. |videoobject|audioobject|textobject"/>
  758. <xsl:variable name="mediaobject.index">
  759. <xsl:call-template name="select.mediaobject.index">
  760. <xsl:with-param name="olist" select="$olist"/>
  761. <xsl:with-param name="count" select="1"/>
  762. </xsl:call-template>
  763. </xsl:variable>
  764. <xsl:if test="$mediaobject.index != ''">
  765. <xsl:apply-templates select="$olist[position() = $mediaobject.index]"/>
  766. </xsl:if>
  767. </xsl:template>
  768. <!-- ====================================================================== -->
  769. <doc:template name="select.mediaobject.index" xmlns="">
  770. <refpurpose>Selects the position of the appropriate media object from a list</refpurpose>
  771. <refdescription id="select.mediaobject.index-desc">
  772. <para>This template takes a list of media objects (usually the
  773. children of a mediaobject or inlinemediaobject) and determines
  774. the "right" object. It returns the position of that object
  775. to be used by the calling template.</para>
  776. <para>If the parameter <parameter>use.role.for.mediaobject</parameter>
  777. is nonzero, then it first checks for an object with
  778. a role attribute of the appropriate value. It takes the first
  779. of those. Otherwise, it takes the first acceptable object
  780. through a recursive pass through the list.</para>
  781. <para>This template relies on a template named "is.acceptable.mediaobject"
  782. to determine if a given object is an acceptable graphic. The semantics
  783. of media objects is that the first acceptable graphic should be used.
  784. </para>
  785. <para>If no acceptable object is located, no index is returned.</para>
  786. </refdescription>
  787. <refparameter id="select.mediaobject.index-params">
  788. <variablelist>
  789. <varlistentry><term>olist</term>
  790. <listitem>
  791. <para>The node list of potential objects to examine.</para>
  792. </listitem>
  793. </varlistentry>
  794. <varlistentry><term>count</term>
  795. <listitem>
  796. <para>The position in the list currently being considered by the
  797. recursive process.</para>
  798. </listitem>
  799. </varlistentry>
  800. </variablelist>
  801. </refparameter>
  802. <refreturn id="select.mediaobject.index-returns">
  803. <para>Returns the position in the original list of the selected object.</para>
  804. </refreturn>
  805. </doc:template>
  806. <xsl:template name="select.mediaobject.index">
  807. <xsl:param name="olist"
  808. select="imageobject|imageobjectco
  809. |videoobject|audioobject|textobject"/>
  810. <xsl:param name="count">1</xsl:param>
  811. <xsl:choose>
  812. <!-- Test for objects preferred by role -->
  813. <xsl:when test="$use.role.for.mediaobject != 0
  814. and $preferred.mediaobject.role != ''
  815. and $olist[@role = $preferred.mediaobject.role]">
  816. <!-- Get the first hit's position index -->
  817. <xsl:for-each select="$olist">
  818. <xsl:if test="@role = $preferred.mediaobject.role and
  819. not(preceding-sibling::*[@role = $preferred.mediaobject.role])">
  820. <xsl:value-of select="position()"/>
  821. </xsl:if>
  822. </xsl:for-each>
  823. </xsl:when>
  824. <xsl:when test="$use.role.for.mediaobject != 0
  825. and $olist[@role = $stylesheet.result.type]">
  826. <!-- Get the first hit's position index -->
  827. <xsl:for-each select="$olist">
  828. <xsl:if test="@role = $stylesheet.result.type and
  829. not(preceding-sibling::*[@role = $stylesheet.result.type])">
  830. <xsl:value-of select="position()"/>
  831. </xsl:if>
  832. </xsl:for-each>
  833. </xsl:when>
  834. <!-- Accept 'html' for $stylesheet.result.type = 'xhtml' -->
  835. <xsl:when test="$use.role.for.mediaobject != 0
  836. and $stylesheet.result.type = 'xhtml'
  837. and $olist[@role = 'html']">
  838. <!-- Get the first hit's position index -->
  839. <xsl:for-each select="$olist">
  840. <xsl:if test="@role = 'html' and
  841. not(preceding-sibling::*[@role = 'html'])">
  842. <xsl:value-of select="position()"/>
  843. </xsl:if>
  844. </xsl:for-each>
  845. </xsl:when>
  846. <!-- If no selection by role, and there is only one object, use it -->
  847. <xsl:when test="count($olist) = 1 and $count = 1">
  848. <xsl:value-of select="$count"/>
  849. </xsl:when>
  850. <xsl:otherwise>
  851. <!-- Otherwise select first acceptable object -->
  852. <xsl:if test="$count &lt;= count($olist)">
  853. <xsl:variable name="object" select="$olist[position()=$count]"/>
  854. <xsl:variable name="useobject">
  855. <xsl:choose>
  856. <!-- The phrase is used only when contains TeX Math and output is FO -->
  857. <xsl:when test="local-name($object)='textobject' and $object/phrase
  858. and $object/@role='tex' and $stylesheet.result.type = 'fo'
  859. and $tex.math.in.alt != ''">
  860. <xsl:text>1</xsl:text>
  861. </xsl:when>
  862. <!-- The phrase is never used -->
  863. <xsl:when test="local-name($object)='textobject' and $object/phrase">
  864. <xsl:text>0</xsl:text>
  865. </xsl:when>
  866. <xsl:when test="local-name($object)='textobject'
  867. and $object/ancestor::equation ">
  868. <!-- The first textobject is not a reasonable fallback
  869. for equation image -->
  870. <xsl:text>0</xsl:text>
  871. </xsl:when>
  872. <!-- The first textobject is a reasonable fallback -->
  873. <xsl:when test="local-name($object)='textobject'
  874. and $object[not(@role) or @role!='tex']">
  875. <xsl:text>1</xsl:text>
  876. </xsl:when>
  877. <!-- don't use graphic when output is FO, TeX Math is used
  878. and there is math in alt element -->
  879. <xsl:when test="$object/ancestor::equation and
  880. $object/ancestor::equation/alt[@role='tex']
  881. and $stylesheet.result.type = 'fo'
  882. and $tex.math.in.alt != ''">
  883. <xsl:text>0</xsl:text>
  884. </xsl:when>
  885. <!-- If there's only one object, use it -->
  886. <xsl:when test="$count = 1 and count($olist) = 1">
  887. <xsl:text>1</xsl:text>
  888. </xsl:when>
  889. <!-- Otherwise, see if this one is a useable graphic -->
  890. <xsl:otherwise>
  891. <xsl:choose>
  892. <!-- peek inside imageobjectco to simplify the test -->
  893. <xsl:when test="local-name($object) = 'imageobjectco'">
  894. <xsl:call-template name="is.acceptable.mediaobject">
  895. <xsl:with-param name="object" select="$object/imageobject"/>
  896. </xsl:call-template>
  897. </xsl:when>
  898. <xsl:otherwise>
  899. <xsl:call-template name="is.acceptable.mediaobject">
  900. <xsl:with-param name="object" select="$object"/>
  901. </xsl:call-template>
  902. </xsl:otherwise>
  903. </xsl:choose>
  904. </xsl:otherwise>
  905. </xsl:choose>
  906. </xsl:variable>
  907. <xsl:choose>
  908. <xsl:when test="$useobject='1'">
  909. <xsl:value-of select="$count"/>
  910. </xsl:when>
  911. <xsl:otherwise>
  912. <xsl:call-template name="select.mediaobject.index">
  913. <xsl:with-param name="olist" select="$olist"/>
  914. <xsl:with-param name="count" select="$count + 1"/>
  915. </xsl:call-template>
  916. </xsl:otherwise>
  917. </xsl:choose>
  918. </xsl:if>
  919. </xsl:otherwise>
  920. </xsl:choose>
  921. </xsl:template>
  922. <doc:template name="is.acceptable.mediaobject" xmlns="">
  923. <refpurpose>Returns '1' if the specified media object is recognized</refpurpose>
  924. <refdescription id="is.acceptable.mediaobject-desc">
  925. <para>This template examines a media object and returns '1' if the
  926. object is recognized as a graphic.</para>
  927. </refdescription>
  928. <refparameter id="is.acceptable.mediaobject-params">
  929. <variablelist>
  930. <varlistentry><term>object</term>
  931. <listitem>
  932. <para>The media object to consider.</para>
  933. </listitem>
  934. </varlistentry>
  935. </variablelist>
  936. </refparameter>
  937. <refreturn id="is.acceptable.mediaobject-returns">
  938. <para>0 or 1</para>
  939. </refreturn>
  940. </doc:template>
  941. <xsl:template name="is.acceptable.mediaobject">
  942. <xsl:param name="object"></xsl:param>
  943. <xsl:variable name="filename">
  944. <xsl:call-template name="mediaobject.filename">
  945. <xsl:with-param name="object" select="$object"/>
  946. </xsl:call-template>
  947. </xsl:variable>
  948. <xsl:variable name="ext">
  949. <xsl:call-template name="filename-extension">
  950. <xsl:with-param name="filename" select="$filename"/>
  951. </xsl:call-template>
  952. </xsl:variable>
  953. <!-- there will only be one -->
  954. <xsl:variable name="data" select="$object/videodata
  955. |$object/imagedata
  956. |$object/audiodata"/>
  957. <xsl:variable name="format" select="$data/@format"/>
  958. <xsl:variable name="graphic.format">
  959. <xsl:if test="$format">
  960. <xsl:call-template name="is.graphic.format">
  961. <xsl:with-param name="format" select="$format"/>
  962. </xsl:call-template>
  963. </xsl:if>
  964. </xsl:variable>
  965. <xsl:variable name="graphic.ext">
  966. <xsl:if test="$ext">
  967. <xsl:call-template name="is.graphic.extension">
  968. <xsl:with-param name="ext" select="$ext"/>
  969. </xsl:call-template>
  970. </xsl:if>
  971. </xsl:variable>
  972. <xsl:choose>
  973. <xsl:when test="$use.svg = 0 and $format = 'SVG'">0</xsl:when>
  974. <xsl:when xmlns:svg="http://www.w3.org/2000/svg"
  975. test="$use.svg != 0 and $object/svg:*">1</xsl:when>
  976. <xsl:when test="$graphic.format = '1'">1</xsl:when>
  977. <xsl:when test="$graphic.ext = '1'">1</xsl:when>
  978. <xsl:otherwise>0</xsl:otherwise>
  979. </xsl:choose>
  980. </xsl:template>
  981. <xsl:template name="mediaobject.filename">
  982. <xsl:param name="object"></xsl:param>
  983. <xsl:variable name="data" select="$object/videodata
  984. |$object/imagedata
  985. |$object/audiodata
  986. |$object"/>
  987. <xsl:variable name="filename">
  988. <xsl:choose>
  989. <xsl:when test="$data[@fileref]">
  990. <xsl:apply-templates select="$data/@fileref"/>
  991. </xsl:when>
  992. <xsl:when test="$data[@entityref]">
  993. <xsl:value-of select="unparsed-entity-uri($data/@entityref)"/>
  994. </xsl:when>
  995. <xsl:otherwise></xsl:otherwise>
  996. </xsl:choose>
  997. </xsl:variable>
  998. <xsl:variable name="real.ext">
  999. <xsl:call-template name="filename-extension">
  1000. <xsl:with-param name="filename" select="$filename"/>
  1001. </xsl:call-template>
  1002. </xsl:variable>
  1003. <xsl:variable name="ext">
  1004. <xsl:choose>
  1005. <xsl:when test="$real.ext != ''">
  1006. <xsl:value-of select="$real.ext"/>
  1007. </xsl:when>
  1008. <xsl:otherwise>
  1009. <xsl:value-of select="$graphic.default.extension"/>
  1010. </xsl:otherwise>
  1011. </xsl:choose>
  1012. </xsl:variable>
  1013. <xsl:variable name="graphic.ext">
  1014. <xsl:call-template name="is.graphic.extension">
  1015. <xsl:with-param name="ext" select="$ext"/>
  1016. </xsl:call-template>
  1017. </xsl:variable>
  1018. <xsl:choose>
  1019. <xsl:when test="$real.ext = ''">
  1020. <xsl:choose>
  1021. <xsl:when test="$ext != ''">
  1022. <xsl:value-of select="$filename"/>
  1023. <xsl:text>.</xsl:text>
  1024. <xsl:value-of select="$ext"/>
  1025. </xsl:when>
  1026. <xsl:otherwise>
  1027. <xsl:value-of select="$filename"/>
  1028. </xsl:otherwise>
  1029. </xsl:choose>
  1030. </xsl:when>
  1031. <xsl:when test="not($graphic.ext)">
  1032. <xsl:choose>
  1033. <xsl:when test="$graphic.default.extension != ''">
  1034. <xsl:value-of select="$filename"/>
  1035. <xsl:text>.</xsl:text>
  1036. <xsl:value-of select="$graphic.default.extension"/>
  1037. </xsl:when>
  1038. <xsl:otherwise>
  1039. <xsl:value-of select="$filename"/>
  1040. </xsl:otherwise>
  1041. </xsl:choose>
  1042. </xsl:when>
  1043. <xsl:otherwise>
  1044. <xsl:value-of select="$filename"/>
  1045. </xsl:otherwise>
  1046. </xsl:choose>
  1047. </xsl:template>
  1048. <!-- ====================================================================== -->
  1049. <doc:template name="check.id.unique" xmlns="">
  1050. <refpurpose>Warn users about references to non-unique IDs</refpurpose>
  1051. <refdescription id="check.id.unique-desc">
  1052. <para>If passed an ID in <varname>linkend</varname>,
  1053. <function>check.id.unique</function> prints
  1054. a warning message to the user if either the ID does not exist or
  1055. the ID is not unique.</para>
  1056. </refdescription>
  1057. </doc:template>
  1058. <xsl:template name="check.id.unique">
  1059. <xsl:param name="linkend"></xsl:param>
  1060. <xsl:if test="$linkend != ''">
  1061. <xsl:variable name="targets" select="key('id',$linkend)"/>
  1062. <xsl:variable name="target" select="$targets[1]"/>
  1063. <xsl:if test="count($targets)=0">
  1064. <xsl:message>
  1065. <xsl:text>Error: no ID for constraint linkend: </xsl:text>
  1066. <xsl:value-of select="$linkend"/>
  1067. <xsl:text>.</xsl:text>
  1068. </xsl:message>
  1069. <!--
  1070. <xsl:message>
  1071. <xsl:text>If the ID exists in your document, did your </xsl:text>
  1072. <xsl:text>XSLT Processor load the DTD?</xsl:text>
  1073. </xsl:message>
  1074. -->
  1075. </xsl:if>
  1076. <xsl:if test="count($targets)>1">
  1077. <xsl:message>
  1078. <xsl:text>Warning: multiple "IDs" for constraint linkend: </xsl:text>
  1079. <xsl:value-of select="$linkend"/>
  1080. <xsl:text>.</xsl:text>
  1081. </xsl:message>
  1082. </xsl:if>
  1083. </xsl:if>
  1084. </xsl:template>
  1085. <doc:template name="check.idref.targets" xmlns="">
  1086. <refpurpose>Warn users about incorrectly typed references</refpurpose>
  1087. <refdescription id="check.idref.targets-desc">
  1088. <para>If passed an ID in <varname>linkend</varname>,
  1089. <function>check.idref.targets</function> makes sure that the element
  1090. pointed to by the link is one of the elements listed in
  1091. <varname>element-list</varname> and warns the user otherwise.</para>
  1092. </refdescription>
  1093. </doc:template>
  1094. <xsl:template name="check.idref.targets">
  1095. <xsl:param name="linkend"></xsl:param>
  1096. <xsl:param name="element-list"></xsl:param>
  1097. <xsl:if test="$linkend != ''">
  1098. <xsl:variable name="targets" select="key('id',$linkend)"/>
  1099. <xsl:variable name="target" select="$targets[1]"/>
  1100. <xsl:if test="count($target) &gt; 0">
  1101. <xsl:if test="not(contains(concat(' ', $element-list, ' '), local-name($target)))">
  1102. <xsl:message>
  1103. <xsl:text>Error: linkend (</xsl:text>
  1104. <xsl:value-of select="$linkend"/>
  1105. <xsl:text>) points to "</xsl:text>
  1106. <xsl:value-of select="local-name($target)"/>
  1107. <xsl:text>" not (one of): </xsl:text>
  1108. <xsl:value-of select="$element-list"/>
  1109. </xsl:message>
  1110. </xsl:if>
  1111. </xsl:if>
  1112. </xsl:if>
  1113. </xsl:template>
  1114. <!-- ====================================================================== -->
  1115. <!-- Procedure Step Numeration -->
  1116. <xsl:param name="procedure.step.numeration.formats" select="'1aiAI'"/>
  1117. <xsl:template name="procedure.step.numeration">
  1118. <xsl:param name="context" select="."/>
  1119. <xsl:variable name="format.length"
  1120. select="string-length($procedure.step.numeration.formats)"/>
  1121. <xsl:choose>
  1122. <xsl:when test="local-name($context) = 'substeps'">
  1123. <xsl:variable name="ssdepth"
  1124. select="count($context/ancestor::substeps)"/>
  1125. <xsl:variable name="sstype" select="($ssdepth mod $format.length)+2"/>
  1126. <xsl:choose>
  1127. <xsl:when test="$sstype &gt; $format.length">
  1128. <xsl:value-of select="substring($procedure.step.numeration.formats,1,1)"/>
  1129. </xsl:when>
  1130. <xsl:otherwise>
  1131. <xsl:value-of select="substring($procedure.step.numeration.formats,$sstype,1)"/>
  1132. </xsl:otherwise>
  1133. </xsl:choose>
  1134. </xsl:when>
  1135. <xsl:when test="local-name($context) = 'step'">
  1136. <xsl:variable name="sdepth"
  1137. select="count($context/ancestor::substeps)"/>
  1138. <xsl:variable name="stype" select="($sdepth mod $format.length)+1"/>
  1139. <xsl:value-of select="substring($procedure.step.numeration.formats,$stype,1)"/>
  1140. </xsl:when>
  1141. <xsl:otherwise>
  1142. <xsl:message>
  1143. <xsl:text>Unexpected context in procedure.step.numeration: </xsl:text>
  1144. <xsl:value-of select="local-name($context)"/>
  1145. </xsl:message>
  1146. </xsl:otherwise>
  1147. </xsl:choose>
  1148. </xsl:template>
  1149. <xsl:template match="step" mode="number">
  1150. <xsl:param name="rest" select="''"/>
  1151. <xsl:param name="recursive" select="1"/>
  1152. <xsl:variable name="format">
  1153. <xsl:call-template name="procedure.step.numeration"/>
  1154. </xsl:variable>
  1155. <xsl:variable name="num">
  1156. <xsl:number count="step" format="{$format}"/>
  1157. </xsl:variable>
  1158. <xsl:choose>
  1159. <xsl:when test="$recursive != 0 and ancestor::step">
  1160. <xsl:apply-templates select="ancestor::step[1]" mode="number">
  1161. <xsl:with-param name="rest" select="concat('.', $num, $rest)"/>
  1162. </xsl:apply-templates>
  1163. </xsl:when>
  1164. <xsl:otherwise>
  1165. <xsl:value-of select="concat($num, $rest)"/>
  1166. </xsl:otherwise>
  1167. </xsl:choose>
  1168. </xsl:template>
  1169. <!-- ====================================================================== -->
  1170. <!-- OrderedList Numeration -->
  1171. <xsl:template name="orderedlist-starting-number">
  1172. <xsl:param name="list" select="."/>
  1173. <!-- Need a neutral dbxxx -->
  1174. <xsl:variable name="pi-html-start">
  1175. <xsl:call-template name="pi-attribute">
  1176. <xsl:with-param name="pis"
  1177. select="$list/processing-instruction('dbhtml')"/>
  1178. <xsl:with-param name="attribute" select="'start'"/>
  1179. </xsl:call-template>
  1180. </xsl:variable>
  1181. <xsl:variable name="pi-fo-start">
  1182. <xsl:call-template name="pi-attribute">
  1183. <xsl:with-param name="pis"
  1184. select="$list/processing-instruction('dbfo')"/>
  1185. <xsl:with-param name="attribute" select="'start'"/>
  1186. </xsl:call-template>
  1187. </xsl:variable>
  1188. <xsl:choose>
  1189. <xsl:when test="not($list/@continuation = 'continues')">
  1190. <xsl:choose>
  1191. <xsl:when test="@startingnumber">
  1192. <xsl:value-of select="@startingnumber"/>
  1193. </xsl:when>
  1194. <xsl:when test="$pi-html-start != ''">
  1195. <xsl:value-of select="$pi-html-start"/>
  1196. </xsl:when>
  1197. <xsl:when test="$pi-fo-start != ''">
  1198. <xsl:value-of select="$pi-fo-start"/>
  1199. </xsl:when>
  1200. <xsl:otherwise>1</xsl:otherwise>
  1201. </xsl:choose>
  1202. </xsl:when>
  1203. <xsl:otherwise>
  1204. <xsl:variable name="prevlist"
  1205. select="$list/preceding::orderedlist[1]"/>
  1206. <xsl:choose>
  1207. <xsl:when test="count($prevlist) = 0">2</xsl:when>
  1208. <xsl:otherwise>
  1209. <xsl:variable name="prevlength" select="count($prevlist/listitem)"/>
  1210. <xsl:variable name="prevstart">
  1211. <xsl:call-template name="orderedlist-starting-number">
  1212. <xsl:with-param name="list" select="$prevlist"/>
  1213. </xsl:call-template>
  1214. </xsl:variable>
  1215. <xsl:value-of select="$prevstart + $prevlength"/>
  1216. </xsl:otherwise>
  1217. </xsl:choose>
  1218. </xsl:otherwise>
  1219. </xsl:choose>
  1220. </xsl:template>
  1221. <xsl:template name="orderedlist-item-number">
  1222. <!-- context node must be a listitem in an orderedlist -->
  1223. <xsl:param name="node" select="."/>
  1224. <xsl:choose>
  1225. <xsl:when test="$node/@override">
  1226. <xsl:value-of select="$node/@override"/>
  1227. </xsl:when>
  1228. <xsl:when test="$node/preceding-sibling::listitem">
  1229. <xsl:variable name="pnum">
  1230. <xsl:call-template name="orderedlist-item-number">
  1231. <xsl:with-param name="node" select="$node/preceding-sibling::listitem[1]"/>
  1232. </xsl:call-template>
  1233. </xsl:variable>
  1234. <xsl:value-of select="$pnum + 1"/>
  1235. </xsl:when>
  1236. <xsl:otherwise>
  1237. <xsl:call-template name="orderedlist-starting-number">
  1238. <xsl:with-param name="list" select="parent::*"/>
  1239. </xsl:call-template>
  1240. </xsl:otherwise>
  1241. </xsl:choose>
  1242. </xsl:template>
  1243. <xsl:template name="next.numeration">
  1244. <xsl:param name="numeration" select="'default'"/>
  1245. <xsl:choose>
  1246. <!-- Change this list if you want to change the order of numerations -->
  1247. <xsl:when test="$numeration = 'arabic'">loweralpha</xsl:when>
  1248. <xsl:when test="$numeration = 'loweralpha'">lowerroman</xsl:when>
  1249. <xsl:when test="$numeration = 'lowerroman'">upperalpha</xsl:when>
  1250. <xsl:when test="$numeration = 'upperalpha'">upperroman</xsl:when>
  1251. <xsl:when test="$numeration = 'upperroman'">arabic</xsl:when>
  1252. <xsl:otherwise>arabic</xsl:otherwise>
  1253. </xsl:choose>
  1254. </xsl:template>
  1255. <xsl:template name="list.numeration">
  1256. <xsl:param name="node" select="."/>
  1257. <xsl:choose>
  1258. <xsl:when test="$node/@numeration">
  1259. <xsl:value-of select="$node/@numeration"/>
  1260. </xsl:when>
  1261. <xsl:otherwise>
  1262. <xsl:choose>
  1263. <xsl:when test="$node/ancestor::orderedlist">
  1264. <xsl:call-template name="next.numeration">
  1265. <xsl:with-param name="numeration">
  1266. <xsl:call-template name="list.numeration">
  1267. <xsl:with-param name="node" select="$node/ancestor::orderedlist[1]"/>
  1268. </xsl:call-template>
  1269. </xsl:with-param>
  1270. </xsl:call-template>
  1271. </xsl:when>
  1272. <xsl:otherwise>
  1273. <xsl:call-template name="next.numeration"/>
  1274. </xsl:otherwise>
  1275. </xsl:choose>
  1276. </xsl:otherwise>
  1277. </xsl:choose>
  1278. </xsl:template>
  1279. <!-- ====================================================================== -->
  1280. <!-- ItemizedList "Numeration" -->
  1281. <xsl:template name="next.itemsymbol">
  1282. <xsl:param name="itemsymbol" select="'default'"/>
  1283. <xsl:choose>
  1284. <!-- Change this list if you want to change the order of symbols -->
  1285. <xsl:when test="$itemsymbol = 'disc'">circle</xsl:when>
  1286. <xsl:when test="$itemsymbol = 'circle'">square</xsl:when>
  1287. <xsl:otherwise>disc</xsl:otherwise>
  1288. </xsl:choose>
  1289. </xsl:template>
  1290. <xsl:template name="list.itemsymbol">
  1291. <xsl:param name="node" select="."/>
  1292. <xsl:choose>
  1293. <xsl:when test="@override">
  1294. <xsl:value-of select="@override"/>
  1295. </xsl:when>
  1296. <xsl:when test="$node/@mark">
  1297. <xsl:value-of select="$node/@mark"/>
  1298. </xsl:when>
  1299. <xsl:otherwise>
  1300. <xsl:choose>
  1301. <xsl:when test="$node/ancestor::itemizedlist">
  1302. <xsl:call-template name="next.itemsymbol">
  1303. <xsl:with-param name="itemsymbol">
  1304. <xsl:call-template name="list.itemsymbol">
  1305. <xsl:with-param name="node" select="$node/ancestor::itemizedlist[1]"/>
  1306. </xsl:call-template>
  1307. </xsl:with-param>
  1308. </xsl:call-template>
  1309. </xsl:when>
  1310. <xsl:otherwise>
  1311. <xsl:call-template name="next.itemsymbol"/>
  1312. </xsl:otherwise>
  1313. </xsl:choose>
  1314. </xsl:otherwise>
  1315. </xsl:choose>
  1316. </xsl:template>
  1317. <!-- ====================================================================== -->
  1318. <doc:template name="copyright.years" xmlns="">
  1319. <refpurpose>Print a set of years with collapsed ranges</refpurpose>
  1320. <refdescription id="copyright.years-desc">
  1321. <para>This template prints a list of year elements with consecutive
  1322. years printed as a range. In other words:</para>
  1323. <screen><![CDATA[<year>1992</year>
  1324. <year>1993</year>
  1325. <year>1994</year>]]></screen>
  1326. <para>is printed <quote>1992-1994</quote>, whereas:</para>
  1327. <screen><![CDATA[<year>1992</year>
  1328. <year>1994</year>]]></screen>
  1329. <para>is printed <quote>1992, 1994</quote>.</para>
  1330. <para>This template assumes that all the year elements contain only
  1331. decimal year numbers, that the elements are sorted in increasing
  1332. numerical order, that there are no duplicates, and that all the years
  1333. are expressed in full <quote>century+year</quote>
  1334. (<quote>1999</quote> not <quote>99</quote>) notation.</para>
  1335. </refdescription>
  1336. <refparameter id="copyright.years-params">
  1337. <variablelist>
  1338. <varlistentry><term>years</term>
  1339. <listitem>
  1340. <para>The initial set of year elements.</para>
  1341. </listitem>
  1342. </varlistentry>
  1343. <varlistentry><term>print.ranges</term>
  1344. <listitem>
  1345. <para>If non-zero, multi-year ranges are collapsed. If zero, all years
  1346. are printed discretely.</para>
  1347. </listitem>
  1348. </varlistentry>
  1349. <varlistentry><term>single.year.ranges</term>
  1350. <listitem>
  1351. <para>If non-zero, two consecutive years will be printed as a range,
  1352. otherwise, they will be printed discretely. In other words, a single
  1353. year range is <quote>1991-1992</quote> but discretely it's
  1354. <quote>1991, 1992</quote>.</para>
  1355. </listitem>
  1356. </varlistentry>
  1357. </variablelist>
  1358. </refparameter>
  1359. <refreturn id="copyright.years-returns">
  1360. <para>This template returns the formatted list of years.</para>
  1361. </refreturn>
  1362. </doc:template>
  1363. <xsl:template name="copyright.years">
  1364. <xsl:param name="years"/>
  1365. <xsl:param name="print.ranges" select="1"/>
  1366. <xsl:param name="single.year.ranges" select="0"/>
  1367. <xsl:param name="firstyear" select="0"/>
  1368. <xsl:param name="nextyear" select="0"/>
  1369. <!--
  1370. <xsl:message terminate="no">
  1371. <xsl:text>CY: </xsl:text>
  1372. <xsl:value-of select="count($years)"/>
  1373. <xsl:text>, </xsl:text>
  1374. <xsl:value-of select="$firstyear"/>
  1375. <xsl:text>, </xsl:text>
  1376. <xsl:value-of select="$nextyear"/>
  1377. <xsl:text>, </xsl:text>
  1378. <xsl:value-of select="$print.ranges"/>
  1379. <xsl:text>, </xsl:text>
  1380. <xsl:value-of select="$single.year.ranges"/>
  1381. <xsl:text> (</xsl:text>
  1382. <xsl:value-of select="$years[1]"/>
  1383. <xsl:text>)</xsl:text>
  1384. </xsl:message>
  1385. -->
  1386. <xsl:choose>
  1387. <xsl:when test="$print.ranges = 0 and count($years) &gt; 0">
  1388. <xsl:choose>
  1389. <xsl:when test="count($years) = 1">
  1390. <xsl:apply-templates select="$years[1]" mode="titlepage.mode"/>
  1391. </xsl:when>
  1392. <xsl:otherwise>
  1393. <xsl:apply-templates select="$years[1]" mode="titlepage.mode"/>
  1394. <xsl:text>, </xsl:text>
  1395. <xsl:call-template name="copyright.years">
  1396. <xsl:with-param name="years"
  1397. select="$years[position() &gt; 1]"/>
  1398. <xsl:with-param name="print.ranges" select="$print.ranges"/>
  1399. <xsl:with-param name="single.year.ranges"
  1400. select="$single.year.ranges"/>
  1401. </xsl:call-template>
  1402. </xsl:otherwise>
  1403. </xsl:choose>
  1404. </xsl:when>
  1405. <xsl:when test="count($years) = 0">
  1406. <xsl:variable name="lastyear" select="$nextyear - 1"/>
  1407. <xsl:choose>
  1408. <xsl:when test="$firstyear = 0">
  1409. <!-- there weren't any years at all -->
  1410. </xsl:when>
  1411. <xsl:when test="$firstyear = $lastyear">
  1412. <xsl:value-of select="$firstyear"/>
  1413. </xsl:when>
  1414. <xsl:when test="$single.year.ranges = 0
  1415. and $lastyear = $firstyear + 1">
  1416. <xsl:value-of select="$firstyear"/>
  1417. <xsl:text>, </xsl:text>
  1418. <xsl:value-of select="$lastyear"/>
  1419. </xsl:when>
  1420. <xsl:otherwise>
  1421. <xsl:value-of select="$firstyear"/>
  1422. <xsl:text>-</xsl:text>
  1423. <xsl:value-of select="$lastyear"/>
  1424. </xsl:otherwise>
  1425. </xsl:choose>
  1426. </xsl:when>
  1427. <xsl:when test="$firstyear = 0">
  1428. <xsl:call-template name="copyright.years">
  1429. <xsl:with-param name="years"
  1430. select="$years[position() &gt; 1]"/>
  1431. <xsl:with-param name="firstyear" select="$years[1]"/>
  1432. <xsl:with-param name="nextyear" select="$years[1] + 1"/>
  1433. <xsl:with-param name="print.ranges" select="$print.ranges"/>
  1434. <xsl:with-param name="single.year.ranges"
  1435. select="$single.year.ranges"/>
  1436. </xsl:call-template>
  1437. </xsl:when>
  1438. <xsl:when test="$nextyear = $years[1]">
  1439. <xsl:call-template name="copyright.years">
  1440. <xsl:with-param name="years"
  1441. select="$years[position() &gt; 1]"/>
  1442. <xsl:with-param name="firstyear" select="$firstyear"/>
  1443. <xsl:with-param name="nextyear" select="$nextyear + 1"/>
  1444. <xsl:with-param name="print.ranges" select="$print.ranges"/>
  1445. <xsl:with-param name="single.year.ranges"
  1446. select="$single.year.ranges"/>
  1447. </xsl:call-template>
  1448. </xsl:when>
  1449. <xsl:otherwise>
  1450. <!-- we have years left, but they aren't in the current range -->
  1451. <xsl:choose>
  1452. <xsl:when test="$nextyear = $firstyear + 1">
  1453. <xsl:value-of select="$firstyear"/>
  1454. <xsl:text>, </xsl:text>
  1455. </xsl:when>
  1456. <xsl:when test="$single.year.ranges = 0
  1457. and $nextyear = $firstyear + 2">
  1458. <xsl:value-of select="$firstyear"/>
  1459. <xsl:text>, </xsl:text>
  1460. <xsl:value-of select="$nextyear - 1"/>
  1461. <xsl:text>, </xsl:text>
  1462. </xsl:when>
  1463. <xsl:otherwise>
  1464. <xsl:value-of select="$firstyear"/>
  1465. <xsl:text>-</xsl:text>
  1466. <xsl:value-of select="$nextyear - 1"/>
  1467. <xsl:text>, </xsl:text>
  1468. </xsl:otherwise>
  1469. </xsl:choose>
  1470. <xsl:call-template name="copyright.years">
  1471. <xsl:with-param name="years"
  1472. select="$years[position() &gt; 1]"/>
  1473. <xsl:with-param name="firstyear" select="$years[1]"/>
  1474. <xsl:with-param name="nextyear" select="$years[1] + 1"/>
  1475. <xsl:with-param name="print.ranges" select="$print.ranges"/>
  1476. <xsl:with-param name="single.year.ranges"
  1477. select="$single.year.ranges"/>
  1478. </xsl:call-template>
  1479. </xsl:otherwise>
  1480. </xsl:choose>
  1481. </xsl:template>
  1482. <!-- ====================================================================== -->
  1483. <doc:template name="find.path.params" xmlns="">
  1484. <refpurpose>Search in a table for the "best" match for the node</refpurpose>
  1485. <refdescription id="find.path.params-desc">
  1486. <para>This template searches in a table for the value that most-closely
  1487. (in the typical best-match sense of XSLT) matches the current (element)
  1488. node location.</para>
  1489. </refdescription>
  1490. </doc:template>
  1491. <xsl:template name="find.path.params">
  1492. <xsl:param name="node" select="."/>
  1493. <xsl:param name="table" select="''"/>
  1494. <xsl:param name="location">
  1495. <xsl:call-template name="xpath.location">
  1496. <xsl:with-param name="node" select="$node"/>
  1497. </xsl:call-template>
  1498. </xsl:param>
  1499. <xsl:variable name="value">
  1500. <xsl:call-template name="lookup.key">
  1501. <xsl:with-param name="key" select="$location"/>
  1502. <xsl:with-param name="table" select="$table"/>
  1503. </xsl:call-template>
  1504. </xsl:variable>
  1505. <xsl:choose>
  1506. <xsl:when test="$value != ''">
  1507. <xsl:value-of select="$value"/>
  1508. </xsl:when>
  1509. <xsl:when test="contains($location, '/')">
  1510. <xsl:call-template name="find.path.params">
  1511. <xsl:with-param name="node" select="$node"/>
  1512. <xsl:with-param name="table" select="$table"/>
  1513. <xsl:with-param name="location" select="substring-after($location, '/')"/>
  1514. </xsl:call-template>
  1515. </xsl:when>
  1516. </xsl:choose>
  1517. </xsl:template>
  1518. <xsl:template name="relative-uri">
  1519. <xsl:param name="filename" select="."/>
  1520. <xsl:param name="destdir" select="''"/>
  1521. <xsl:variable name="srcurl">
  1522. <xsl:call-template name="strippath">
  1523. <xsl:with-param name="filename">
  1524. <xsl:call-template name="xml.base.dirs">
  1525. <xsl:with-param name="base.elem"
  1526. select="$filename/ancestor-or-self::*
  1527. [@xml:base != ''][1]"/>
  1528. </xsl:call-template>
  1529. <xsl:value-of select="$filename"/>
  1530. </xsl:with-param>
  1531. </xsl:call-template>
  1532. </xsl:variable>
  1533. <xsl:variable name="srcurl.trimmed">
  1534. <xsl:call-template name="trim.common.uri.paths">
  1535. <xsl:with-param name="uriA" select="$srcurl"/>
  1536. <xsl:with-param name="uriB" select="$destdir"/>
  1537. <xsl:with-param name="return" select="'A'"/>
  1538. </xsl:call-template>
  1539. </xsl:variable>
  1540. <xsl:variable name="destdir.trimmed">
  1541. <xsl:call-template name="trim.common.uri.paths">
  1542. <xsl:with-param name="uriA" select="$srcurl"/>
  1543. <xsl:with-param name="uriB" select="$destdir"/>
  1544. <xsl:with-param name="return" select="'B'"/>
  1545. </xsl:call-template>
  1546. </xsl:variable>
  1547. <xsl:variable name="depth">
  1548. <xsl:call-template name="count.uri.path.depth">
  1549. <xsl:with-param name="filename" select="$destdir.trimmed"/>
  1550. </xsl:call-template>
  1551. </xsl:variable>
  1552. <xsl:call-template name="copy-string">
  1553. <xsl:with-param name="string" select="'../'"/>
  1554. <xsl:with-param name="count" select="$depth"/>
  1555. </xsl:call-template>
  1556. <xsl:value-of select="$srcurl.trimmed"/>
  1557. </xsl:template>
  1558. <!-- ===================================== -->
  1559. <xsl:template name="xml.base.dirs">
  1560. <xsl:param name="base.elem" select="NONODE"/>
  1561. <!-- Recursively resolve xml:base attributes, up to a
  1562. full path with : in uri -->
  1563. <xsl:if test="$base.elem/ancestor::*[@xml:base != ''] and
  1564. not(contains($base.elem/@xml:base, ':'))">
  1565. <xsl:call-template name="xml.base.dirs">
  1566. <xsl:with-param name="base.elem"
  1567. select="$base.elem/ancestor::*[@xml:base != ''][1]"/>
  1568. </xsl:call-template>
  1569. </xsl:if>
  1570. <xsl:call-template name="getdir">
  1571. <xsl:with-param name="filename" select="$base.elem/@xml:base"/>
  1572. </xsl:call-template>
  1573. </xsl:template>
  1574. <!-- ===================================== -->
  1575. <xsl:template name="strippath">
  1576. <xsl:param name="filename" select="''"/>
  1577. <xsl:choose>
  1578. <!-- Leading .. are not eliminated -->
  1579. <xsl:when test="starts-with($filename, '../')">
  1580. <xsl:value-of select="'../'"/>
  1581. <xsl:call-template name="strippath">
  1582. <xsl:with-param name="filename" select="substring-after($filename, '../')"/>
  1583. </xsl:call-template>
  1584. </xsl:when>
  1585. <xsl:when test="contains($filename, '/../')">
  1586. <xsl:call-template name="strippath">
  1587. <xsl:with-param name="filename">
  1588. <xsl:call-template name="getdir">
  1589. <xsl:with-param name="filename" select="substring-before($filename, '/../')"/>
  1590. </xsl:call-template>
  1591. <xsl:value-of select="substring-after($filename, '/../')"/>
  1592. </xsl:with-param>
  1593. </xsl:call-template>
  1594. </xsl:when>
  1595. <xsl:otherwise>
  1596. <xsl:value-of select="$filename"/>
  1597. </xsl:otherwise>
  1598. </xsl:choose>
  1599. </xsl:template>
  1600. <!-- ===================================== -->
  1601. <xsl:template name="getdir">
  1602. <xsl:param name="filename" select="''"/>
  1603. <xsl:if test="contains($filename, '/')">
  1604. <xsl:value-of select="substring-before($filename, '/')"/>
  1605. <xsl:text>/</xsl:text>
  1606. <xsl:call-template name="getdir">
  1607. <xsl:with-param name="filename" select="substring-after($filename, '/')"/>
  1608. </xsl:call-template>
  1609. </xsl:if>
  1610. </xsl:template>
  1611. <!-- ===================================== -->
  1612. <doc:template name="string.upper" xmlns="">
  1613. <refpurpose>Converts a string to all uppercase letters</refpurpose>
  1614. <refdescription id="string.upper-desc">
  1615. <para>Given a string, this template does a language-aware conversion
  1616. of that string to all uppercase letters, based on the values of the
  1617. <literal>lowercase.alpha</literal> and
  1618. <literal>uppercase.alpha</literal> gentext keys for the current
  1619. locale. It affects only those characters found in the values of
  1620. <literal>lowercase.alpha</literal> and
  1621. <literal>uppercase.alpha</literal>. All other characters are left
  1622. unchanged.</para>
  1623. </refdescription>
  1624. <refparameter id="string.upper-params">
  1625. <variablelist>
  1626. <varlistentry><term>string</term>
  1627. <listitem>
  1628. <para>The string to convert to uppercase.</para>
  1629. </listitem>
  1630. </varlistentry>
  1631. </variablelist>
  1632. </refparameter>
  1633. </doc:template>
  1634. <xsl:template name="string.upper">
  1635. <xsl:param name="string" select="''"/>
  1636. <xsl:variable name="lowercase.alpha">
  1637. <xsl:call-template name="gentext">
  1638. <xsl:with-param name="key" select="'lowercase.alpha'"/>
  1639. </xsl:call-template>
  1640. </xsl:variable>
  1641. <xsl:variable name="uppercase.alpha">
  1642. <xsl:call-template name="gentext">
  1643. <xsl:with-param name="key" select="'uppercase.alpha'"/>
  1644. </xsl:call-template>
  1645. </xsl:variable>
  1646. <xsl:value-of select="translate($string,$lowercase.alpha,$uppercase.alpha)"/>
  1647. </xsl:template>
  1648. <!-- ===================================== -->
  1649. <doc:template name="string.lower" xmlns="">
  1650. <refpurpose>Converts a string to all lowercase letters</refpurpose>
  1651. <refdescription id="string.lower-desc">
  1652. <para>Given a string, this template does a language-aware conversion
  1653. of that string to all lowercase letters, based on the values of the
  1654. <literal>uppercase.alpha</literal> and
  1655. <literal>lowercase.alpha</literal> gentext keys for the current
  1656. locale. It affects only those characters found in the values of
  1657. <literal>uppercase.alpha</literal> and
  1658. <literal>lowercase.alpha</literal>. All other characters are left
  1659. unchanged.</para>
  1660. </refdescription>
  1661. <refparameter id="string.lower-params">
  1662. <variablelist>
  1663. <varlistentry><term>string</term>
  1664. <listitem>
  1665. <para>The string to convert to lowercase.</para>
  1666. </listitem>
  1667. </varlistentry>
  1668. </variablelist>
  1669. </refparameter>
  1670. </doc:template>
  1671. <xsl:template name="string.lower">
  1672. <xsl:param name="string" select="''"/>
  1673. <xsl:variable name="uppercase.alpha">
  1674. <xsl:call-template name="gentext">
  1675. <xsl:with-param name="key" select="'uppercase.alpha'"/>
  1676. </xsl:call-template>
  1677. </xsl:variable>
  1678. <xsl:variable name="lowercase.alpha">
  1679. <xsl:call-template name="gentext">
  1680. <xsl:with-param name="key" select="'lowercase.alpha'"/>
  1681. </xsl:call-template>
  1682. </xsl:variable>
  1683. <xsl:value-of select="translate($string,$uppercase.alpha,$lowercase.alpha)"/>
  1684. </xsl:template>
  1685. <!-- ===================================== -->
  1686. <doc:template name="select.choice.separator" xmlns="">
  1687. <refpurpose>Returns localized choice separator</refpurpose>
  1688. <refdescription id="select.choice.separator-desc">
  1689. <para>This template enables auto-generation of an appropriate
  1690. localized "choice" separator (for example, "and" or "or") before
  1691. the final item in an inline list (though it could also be useful
  1692. for generating choice separators for non-inline lists).</para>
  1693. <para>It currently works by evaluating a processing instruction
  1694. (PI) of the form &lt;?dbchoice&#xa0;choice="foo"?> :
  1695. <itemizedlist>
  1696. <listitem>
  1697. <simpara>if the value of the <sgmltag>choice</sgmltag>
  1698. pseudo-attribute is "and" or "or", returns a localized "and"
  1699. or "or"</simpara>
  1700. </listitem>
  1701. <listitem>
  1702. <simpara>otherwise returns the literal value of the
  1703. <sgmltag>choice</sgmltag> pseudo-attribute</simpara>
  1704. </listitem>
  1705. </itemizedlist>
  1706. The latter is provided only as a temporary workaround because the
  1707. locale files do not currently have translations for the word
  1708. <wordasword>or</wordasword>. So if you want to generate a a
  1709. logical "or" separator in French (for example), you currently need
  1710. to do this:
  1711. <literallayout>&lt;?dbchoice choice="ou"?></literallayout>
  1712. </para>
  1713. <warning>
  1714. <para>The <sgmltag>dbchoice</sgmltag> processing instruction is
  1715. an unfortunate hack; support for it may disappear in the future
  1716. (particularly if and when a more appropriate means for marking
  1717. up "choice" lists becomes available in DocBook).</para>
  1718. </warning>
  1719. </refdescription>
  1720. </doc:template>
  1721. <xsl:template name="select.choice.separator">
  1722. <xsl:variable name="choice">
  1723. <xsl:call-template name="pi-attribute">
  1724. <xsl:with-param name="pis" select="processing-instruction('dbchoice')"/>
  1725. <xsl:with-param name="attribute">choice</xsl:with-param>
  1726. </xsl:call-template>
  1727. </xsl:variable>
  1728. <xsl:choose>
  1729. <!-- if value of $choice is "and" or "or", translate to equivalent in -->
  1730. <!-- current locale -->
  1731. <xsl:when test="$choice = 'and' or $choice = 'or'">
  1732. <xsl:call-template name="gentext">
  1733. <xsl:with-param name="key" select="$choice"/>
  1734. </xsl:call-template>
  1735. </xsl:when>
  1736. <!-- otherwise, just output value of $choice, whatever it is -->
  1737. <xsl:otherwise>
  1738. <xsl:value-of select="$choice"/>
  1739. </xsl:otherwise>
  1740. </xsl:choose>
  1741. </xsl:template>
  1742. <!-- ===================================== -->
  1743. <doc:template name="evaluate.info.profile" xmlns="">
  1744. <refpurpose>Evaluates an info profile</refpurpose>
  1745. <refdescription id="evaluate.info.profile-desc">
  1746. <para>This template evaluates an "info profile" matching the XPath
  1747. expression given by the <parameter>profile</parameter>
  1748. parameter. It relies on the XSLT <function>evaluate()</function>
  1749. extension function.</para>
  1750. <para>The value of the <parameter>profile</parameter> parameter
  1751. can include the literal string <literal>$info</literal>. If found
  1752. in the value of the <parameter>profile</parameter> parameter, the
  1753. literal string <literal>$info</literal> string is replaced with
  1754. the value of the <parameter>info</parameter> parameter, which
  1755. should be a set of <replaceable>*info</replaceable> nodes; the
  1756. expression is then evaluated using the XSLT
  1757. <function>evaluate()</function> extension function.</para>
  1758. </refdescription>
  1759. <refparameter id="evaluate.info.profile-params">
  1760. <variablelist>
  1761. <varlistentry>
  1762. <term>profile</term>
  1763. <listitem>
  1764. <para>A string representing an XPath expression </para>
  1765. </listitem>
  1766. </varlistentry>
  1767. <varlistentry>
  1768. <term>info</term>
  1769. <listitem>
  1770. <para>A set of *info nodes</para>
  1771. </listitem>
  1772. </varlistentry>
  1773. </variablelist>
  1774. </refparameter>
  1775. <refreturn id="evaluate.info.profile-returns">
  1776. <para>Returns a node (the result of evaluating the
  1777. <parameter>profile</parameter> parameter)</para>
  1778. </refreturn>
  1779. </doc:template>
  1780. <xsl:template name="evaluate.info.profile">
  1781. <xsl:param name="profile"/>
  1782. <xsl:param name="info"/>
  1783. <xsl:choose>
  1784. <!-- * xsltproc and Xalan both support dyn:evaluate() -->
  1785. <xsl:when test="function-available('dyn:evaluate')">
  1786. <xsl:apply-templates
  1787. select="dyn:evaluate($profile)" mode="get.refentry.metadata"/>
  1788. </xsl:when>
  1789. <!-- * Saxon has its own evaluate() & doesn't support dyn:evaluate() -->
  1790. <xsl:when test="function-available('saxon:evaluate')">
  1791. <xsl:apply-templates
  1792. select="saxon:evaluate($profile)" mode="get.refentry.metadata"/>
  1793. </xsl:when>
  1794. <xsl:otherwise>
  1795. <xsl:message terminate="yes">
  1796. Error: The "info profiling" mechanism currently requires an XSLT
  1797. engine that supports the evaluate() XSLT extension function. Your XSLT
  1798. engine does not support it.
  1799. </xsl:message>
  1800. </xsl:otherwise>
  1801. </xsl:choose>
  1802. </xsl:template>
  1803. </xsl:stylesheet>