common.xsl 72 KB

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