common.xsl 70 KB

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