common.xsl 76 KB

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