html.xsl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <?xml version="1.0" encoding="ASCII"?>
  2. <!--This file was created automatically by html2xhtml-->
  3. <!--from the HTML stylesheets.-->
  4. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
  5. <!-- ********************************************************************
  6. $Id: html.xsl 9306 2012-04-28 03:49:00Z bobstayton $
  7. ********************************************************************
  8. This file is part of the XSL DocBook Stylesheet distribution.
  9. See ../README or http://docbook.sf.net/release/xsl/current/ for
  10. copyright and other information.
  11. ******************************************************************** -->
  12. <!-- These variables set the align attribute value for HTML output based on
  13. the writing-mode specified in the gentext file for the document's lang. -->
  14. <xsl:variable name="direction.align.start">
  15. <xsl:choose>
  16. <xsl:when test="starts-with($writing.mode, 'lr')">left</xsl:when>
  17. <xsl:when test="starts-with($writing.mode, 'rl')">right</xsl:when>
  18. <xsl:otherwise>left</xsl:otherwise>
  19. </xsl:choose>
  20. </xsl:variable>
  21. <xsl:variable name="direction.align.end">
  22. <xsl:choose>
  23. <xsl:when test="starts-with($writing.mode, 'lr')">right</xsl:when>
  24. <xsl:when test="starts-with($writing.mode, 'rl')">left</xsl:when>
  25. <xsl:otherwise>right</xsl:otherwise>
  26. </xsl:choose>
  27. </xsl:variable>
  28. <xsl:variable name="direction.mode">
  29. <xsl:choose>
  30. <xsl:when test="starts-with($writing.mode, 'lr')">ltr</xsl:when>
  31. <xsl:when test="starts-with($writing.mode, 'rl')">rtl</xsl:when>
  32. <xsl:otherwise>ltr</xsl:otherwise>
  33. </xsl:choose>
  34. </xsl:variable>
  35. <!-- Support switching to <section> for HTML5 stylesheet -->
  36. <!-- This is an internal variable that does not need to be set by a user -->
  37. <xsl:variable name="div.element">div</xsl:variable>
  38. <!-- Support turning off table border with border="" for HTML5 -->
  39. <xsl:variable name="table.border.off">0</xsl:variable>
  40. <!-- The generate.html.title template is currently used for generating HTML -->
  41. <!-- "title" attributes for some inline elements only, but not for any -->
  42. <!-- block elements. It is called in eleven places in the inline.xsl -->
  43. <!-- file. But it's called by all the inline.* templates (e.g., -->
  44. <!-- inline.boldseq), which in turn are called by other (element) -->
  45. <!-- templates, so it results, currently, in supporting generation of the -->
  46. <!-- HTML "title" attribute for a total of about 92 elements. -->
  47. <!-- You can use mode="html.title.attribute" to get a title for -->
  48. <!-- an element specified by a param, including targets of cross references. -->
  49. <xsl:template name="generate.html.title">
  50. <xsl:apply-templates select="." mode="html.title.attribute"/>
  51. </xsl:template>
  52. <xsl:template match="acronym|abbrev" mode="html.title.attribute">
  53. <xsl:if test="alt">
  54. <xsl:attribute name="title">
  55. <xsl:value-of select="normalize-space(alt)"/>
  56. </xsl:attribute>
  57. </xsl:if>
  58. </xsl:template>
  59. <!-- Generate a title attribute for the context node -->
  60. <!-- This may be the target of an xref -->
  61. <xsl:template match="*" mode="html.title.attribute">
  62. <xsl:variable name="is.title">
  63. <xsl:call-template name="gentext.template.exists">
  64. <xsl:with-param name="context" select="'title'"/>
  65. <xsl:with-param name="name" select="local-name(.)"/>
  66. <xsl:with-param name="lang">
  67. <xsl:call-template name="l10n.language"/>
  68. </xsl:with-param>
  69. </xsl:call-template>
  70. </xsl:variable>
  71. <xsl:variable name="is.title-numbered">
  72. <xsl:call-template name="gentext.template.exists">
  73. <xsl:with-param name="context" select="'title-numbered'"/>
  74. <xsl:with-param name="name" select="local-name(.)"/>
  75. <xsl:with-param name="lang">
  76. <xsl:call-template name="l10n.language"/>
  77. </xsl:with-param>
  78. </xsl:call-template>
  79. </xsl:variable>
  80. <xsl:variable name="is.title-unnumbered">
  81. <xsl:call-template name="gentext.template.exists">
  82. <xsl:with-param name="context" select="'title-unnumbered'"/>
  83. <xsl:with-param name="name" select="local-name(.)"/>
  84. <xsl:with-param name="lang">
  85. <xsl:call-template name="l10n.language"/>
  86. </xsl:with-param>
  87. </xsl:call-template>
  88. </xsl:variable>
  89. <xsl:variable name="has.title.markup">
  90. <xsl:apply-templates select="." mode="title.markup">
  91. <xsl:with-param name="verbose" select="0"/>
  92. </xsl:apply-templates>
  93. </xsl:variable>
  94. <xsl:variable name="gentext.title">
  95. <xsl:if test="$has.title.markup != '???TITLE???' and ($is.title != 0 or $is.title-numbered != 0 or $is.title-unnumbered != 0)">
  96. <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
  97. </xsl:if>
  98. </xsl:variable>
  99. <xsl:choose>
  100. <xsl:when test="string-length($gentext.title) != 0">
  101. <xsl:attribute name="title">
  102. <xsl:value-of select="$gentext.title"/>
  103. </xsl:attribute>
  104. </xsl:when>
  105. <!-- Fall back to alt if available -->
  106. <xsl:when test="alt">
  107. <xsl:attribute name="title">
  108. <xsl:value-of select="normalize-space(alt)"/>
  109. </xsl:attribute>
  110. </xsl:when>
  111. </xsl:choose>
  112. </xsl:template>
  113. <xsl:template match="qandaentry" mode="html.title.attribute">
  114. <xsl:apply-templates select="question" mode="html.title.attribute"/>
  115. </xsl:template>
  116. <xsl:template match="question" mode="html.title.attribute">
  117. <xsl:variable name="label.text">
  118. <xsl:apply-templates select="." mode="qanda.label"/>
  119. </xsl:variable>
  120. <xsl:choose>
  121. <xsl:when test="string-length($label.text) != 0">
  122. <xsl:attribute name="title">
  123. <xsl:value-of select="$label.text"/>
  124. </xsl:attribute>
  125. </xsl:when>
  126. <!-- Fall back to alt if available -->
  127. <xsl:when test="alt">
  128. <xsl:attribute name="title">
  129. <xsl:value-of select="normalize-space(alt)"/>
  130. </xsl:attribute>
  131. </xsl:when>
  132. </xsl:choose>
  133. </xsl:template>
  134. <xsl:template name="dir">
  135. <xsl:param name="inherit" select="0"/>
  136. <xsl:variable name="dir">
  137. <xsl:choose>
  138. <xsl:when test="@dir">
  139. <xsl:value-of select="@dir"/>
  140. </xsl:when>
  141. <xsl:when test="$inherit != 0">
  142. <xsl:value-of select="ancestor::*/@dir[1]"/>
  143. </xsl:when>
  144. </xsl:choose>
  145. </xsl:variable>
  146. <xsl:if test="$dir != ''">
  147. <xsl:attribute name="dir">
  148. <xsl:value-of select="$dir"/>
  149. </xsl:attribute>
  150. </xsl:if>
  151. </xsl:template>
  152. <xsl:template name="anchor">
  153. <xsl:param name="node" select="."/>
  154. <xsl:param name="conditional" select="1"/>
  155. <xsl:choose>
  156. <xsl:when test="$generate.id.attributes != 0">
  157. <!-- No named anchors output when this param is set -->
  158. </xsl:when>
  159. <xsl:when test="$conditional = 0 or $node/@id or $node/@xml:id">
  160. <a>
  161. <xsl:attribute name="id">
  162. <xsl:call-template name="object.id">
  163. <xsl:with-param name="object" select="$node"/>
  164. </xsl:call-template>
  165. </xsl:attribute>
  166. </a>
  167. </xsl:when>
  168. </xsl:choose>
  169. </xsl:template>
  170. <xsl:template name="id.attribute">
  171. <xsl:param name="node" select="."/>
  172. <xsl:param name="conditional" select="1"/>
  173. <xsl:choose>
  174. <xsl:when test="$generate.id.attributes = 0">
  175. <!-- No id attributes when this param is zero -->
  176. </xsl:when>
  177. <xsl:when test="$conditional = 0 or $node/@id or $node/@xml:id">
  178. <xsl:attribute name="id">
  179. <xsl:call-template name="object.id">
  180. <xsl:with-param name="object" select="$node"/>
  181. </xsl:call-template>
  182. </xsl:attribute>
  183. </xsl:when>
  184. </xsl:choose>
  185. </xsl:template>
  186. <xsl:template name="href.target.uri">
  187. <xsl:param name="context" select="."/>
  188. <xsl:param name="object" select="."/>
  189. <xsl:text>#</xsl:text>
  190. <xsl:call-template name="object.id">
  191. <xsl:with-param name="object" select="$object"/>
  192. </xsl:call-template>
  193. </xsl:template>
  194. <xsl:template name="href.target">
  195. <xsl:param name="context" select="."/>
  196. <xsl:param name="object" select="."/>
  197. <xsl:text>#</xsl:text>
  198. <xsl:call-template name="object.id">
  199. <xsl:with-param name="object" select="$object"/>
  200. </xsl:call-template>
  201. </xsl:template>
  202. <xsl:template name="href.target.with.base.dir">
  203. <xsl:param name="context" select="."/>
  204. <xsl:param name="object" select="."/>
  205. <xsl:if test="$manifest.in.base.dir = 0">
  206. <xsl:value-of select="$chunk.base.dir"/>
  207. </xsl:if>
  208. <xsl:call-template name="href.target">
  209. <xsl:with-param name="context" select="$context"/>
  210. <xsl:with-param name="object" select="$object"/>
  211. </xsl:call-template>
  212. </xsl:template>
  213. <xsl:template name="dingbat">
  214. <xsl:param name="dingbat">bullet</xsl:param>
  215. <xsl:call-template name="dingbat.characters">
  216. <xsl:with-param name="dingbat" select="$dingbat"/>
  217. </xsl:call-template>
  218. </xsl:template>
  219. <xsl:template name="dingbat.characters">
  220. <!-- now that I'm using the real serializer, all that dingbat malarky -->
  221. <!-- isn't necessary anymore... -->
  222. <xsl:param name="dingbat">bullet</xsl:param>
  223. <xsl:choose>
  224. <xsl:when test="$dingbat='bullet'">&#8226;</xsl:when>
  225. <xsl:when test="$dingbat='copyright'">&#169;</xsl:when>
  226. <xsl:when test="$dingbat='trademark'">&#8482;</xsl:when>
  227. <xsl:when test="$dingbat='trade'">&#8482;</xsl:when>
  228. <xsl:when test="$dingbat='registered'">&#174;</xsl:when>
  229. <xsl:when test="$dingbat='service'">(SM)</xsl:when>
  230. <xsl:when test="$dingbat='nbsp'">&#160;</xsl:when>
  231. <xsl:when test="$dingbat='ldquo'">&#8220;</xsl:when>
  232. <xsl:when test="$dingbat='rdquo'">&#8221;</xsl:when>
  233. <xsl:when test="$dingbat='lsquo'">&#8216;</xsl:when>
  234. <xsl:when test="$dingbat='rsquo'">&#8217;</xsl:when>
  235. <xsl:when test="$dingbat='em-dash'">&#8212;</xsl:when>
  236. <xsl:when test="$dingbat='mdash'">&#8212;</xsl:when>
  237. <xsl:when test="$dingbat='en-dash'">&#8211;</xsl:when>
  238. <xsl:when test="$dingbat='ndash'">&#8211;</xsl:when>
  239. <xsl:otherwise>
  240. <xsl:text>&#8226;</xsl:text>
  241. </xsl:otherwise>
  242. </xsl:choose>
  243. </xsl:template>
  244. <xsl:template name="id.warning">
  245. <xsl:if test="$id.warnings != 0 and not(@id) and not(@xml:id) and parent::*">
  246. <xsl:variable name="title">
  247. <xsl:choose>
  248. <xsl:when test="title">
  249. <xsl:value-of select="title[1]"/>
  250. </xsl:when>
  251. <xsl:when test="substring(local-name(*[1]), string-length(local-name(*[1])-3) = 'info') and *[1]/title">
  252. <xsl:value-of select="*[1]/title[1]"/>
  253. </xsl:when>
  254. <xsl:when test="refmeta/refentrytitle">
  255. <xsl:value-of select="refmeta/refentrytitle"/>
  256. </xsl:when>
  257. <xsl:when test="refnamediv/refname">
  258. <xsl:value-of select="refnamediv/refname[1]"/>
  259. </xsl:when>
  260. </xsl:choose>
  261. </xsl:variable>
  262. <xsl:message>
  263. <xsl:text>ID recommended on </xsl:text>
  264. <xsl:value-of select="local-name(.)"/>
  265. <xsl:if test="$title != ''">
  266. <xsl:text>: </xsl:text>
  267. <xsl:choose>
  268. <xsl:when test="string-length($title) &gt; 40">
  269. <xsl:value-of select="substring($title,1,40)"/>
  270. <xsl:text>...</xsl:text>
  271. </xsl:when>
  272. <xsl:otherwise>
  273. <xsl:value-of select="$title"/>
  274. </xsl:otherwise>
  275. </xsl:choose>
  276. </xsl:if>
  277. </xsl:message>
  278. </xsl:if>
  279. </xsl:template>
  280. <xsl:template name="generate.class.attribute">
  281. <xsl:param name="class" select="local-name(.)"/>
  282. <xsl:apply-templates select="." mode="class.attribute">
  283. <xsl:with-param name="class" select="$class"/>
  284. </xsl:apply-templates>
  285. </xsl:template>
  286. <xsl:template match="*" mode="class.attribute">
  287. <xsl:param name="class" select="local-name(.)"/>
  288. <!-- permit customization of class attributes -->
  289. <!-- Use element name by default -->
  290. <xsl:variable name="class.value">
  291. <xsl:apply-templates select="." mode="class.value">
  292. <xsl:with-param name="class" select="$class"/>
  293. </xsl:apply-templates>
  294. </xsl:variable>
  295. <xsl:if test="string-length(normalize-space($class.value)) != 0">
  296. <xsl:attribute name="class">
  297. <xsl:value-of select="$class.value"/>
  298. </xsl:attribute>
  299. </xsl:if>
  300. </xsl:template>
  301. <xsl:template match="*" mode="class.value">
  302. <xsl:param name="class" select="local-name(.)"/>
  303. <!-- permit customization of class value only -->
  304. <!-- Use element name by default -->
  305. <xsl:value-of select="$class"/>
  306. </xsl:template>
  307. <!-- Apply common attributes such as class, lang, dir -->
  308. <xsl:template name="common.html.attributes">
  309. <xsl:param name="inherit" select="0"/>
  310. <xsl:param name="class" select="local-name(.)"/>
  311. <xsl:apply-templates select="." mode="common.html.attributes">
  312. <xsl:with-param name="class" select="$class"/>
  313. <xsl:with-param name="inherit" select="$inherit"/>
  314. </xsl:apply-templates>
  315. </xsl:template>
  316. <xsl:template match="*" mode="common.html.attributes">
  317. <xsl:param name="class" select="local-name(.)"/>
  318. <xsl:param name="inherit" select="0"/>
  319. <xsl:call-template name="generate.html.lang"/>
  320. <xsl:call-template name="dir">
  321. <xsl:with-param name="inherit" select="$inherit"/>
  322. </xsl:call-template>
  323. <xsl:apply-templates select="." mode="class.attribute">
  324. <xsl:with-param name="class" select="$class"/>
  325. </xsl:apply-templates>
  326. </xsl:template>
  327. <!-- Apply common attributes not including class -->
  328. <xsl:template name="locale.html.attributes">
  329. <xsl:apply-templates select="." mode="locale.html.attributes"/>
  330. </xsl:template>
  331. <xsl:template match="*" mode="locale.html.attributes">
  332. <xsl:call-template name="generate.html.lang"/>
  333. <xsl:call-template name="dir"/>
  334. </xsl:template>
  335. <!-- Pass through any lang attributes -->
  336. <xsl:template name="generate.html.lang">
  337. <xsl:apply-templates select="." mode="html.lang.attribute"/>
  338. </xsl:template>
  339. <xsl:template match="*" mode="html.lang.attribute">
  340. <!-- match the attribute name to the output type -->
  341. <xsl:choose>
  342. <xsl:when test="@lang and $stylesheet.result.type = 'html'">
  343. <xsl:attribute name="lang">
  344. <xsl:value-of select="@lang"/>
  345. </xsl:attribute>
  346. </xsl:when>
  347. <xsl:when test="@lang and $stylesheet.result.type = 'xhtml'">
  348. <xsl:attribute name="xml:lang">
  349. <xsl:value-of select="@lang"/>
  350. </xsl:attribute>
  351. </xsl:when>
  352. <xsl:when test="@xml:lang and $stylesheet.result.type = 'html'">
  353. <xsl:attribute name="lang">
  354. <xsl:value-of select="@xml:lang"/>
  355. </xsl:attribute>
  356. </xsl:when>
  357. <xsl:when test="@xml:lang and $stylesheet.result.type = 'xhtml'">
  358. <xsl:attribute name="xml:lang">
  359. <xsl:value-of select="@xml:lang"/>
  360. </xsl:attribute>
  361. </xsl:when>
  362. </xsl:choose>
  363. </xsl:template>
  364. <!-- ==================================================================== -->
  365. <!-- Insert link to css or insert literal CSS in head element -->
  366. <xsl:template name="generate.css">
  367. <xsl:choose>
  368. <xsl:when test="$generate.css.header = 0">
  369. <xsl:call-template name="generate.css.links"/>
  370. </xsl:when>
  371. <xsl:otherwise>
  372. <xsl:call-template name="generate.css.headers"/>
  373. </xsl:otherwise>
  374. </xsl:choose>
  375. </xsl:template>
  376. <xsl:template name="generate.css.headers">
  377. <xsl:call-template name="generate.default.css.header"/>
  378. <xsl:call-template name="generate.custom.css.header"/>
  379. </xsl:template>
  380. <xsl:template name="generate.default.css.header">
  381. <xsl:if test="$make.clean.html != 0 and $docbook.css.source != ''">
  382. <!-- Select default file relative to stylesheet -->
  383. <xsl:variable name="css.node" select="document($docbook.css.source)/*[1]"/>
  384. <xsl:call-template name="output.css.header">
  385. <xsl:with-param name="css.node" select="$css.node"/>
  386. </xsl:call-template>
  387. </xsl:if>
  388. </xsl:template>
  389. <xsl:template name="generate.custom.css.header">
  390. <xsl:if test="$custom.css.source != ''">
  391. <!-- Select custom file relative to document -->
  392. <xsl:variable name="css.node" select="document($custom.css.source,.)/*[1]"/>
  393. <xsl:call-template name="output.css.header">
  394. <xsl:with-param name="css.node" select="$css.node"/>
  395. </xsl:call-template>
  396. </xsl:if>
  397. </xsl:template>
  398. <xsl:template name="output.css.header">
  399. <xsl:param name="css.node"/>
  400. <xsl:choose>
  401. <xsl:when test="count($css.node) = 0">
  402. </xsl:when>
  403. <xsl:otherwise>
  404. <style type="text/css">
  405. <xsl:copy-of select="$css.node/text()"/>
  406. </style>
  407. </xsl:otherwise>
  408. </xsl:choose>
  409. </xsl:template>
  410. <!-- ==================================================================== -->
  411. <xsl:template name="generate.css.links">
  412. <xsl:call-template name="generate.default.css.link"/>
  413. <xsl:call-template name="generate.custom.css.link"/>
  414. </xsl:template>
  415. <xsl:template name="generate.default.css.link">
  416. <xsl:if test="$make.clean.html != 0 and $docbook.css.link != 0 and $docbook.css.source != ''">
  417. <xsl:variable name="filename">
  418. <xsl:call-template name="css.output.filename">
  419. <xsl:with-param name="src" select="$docbook.css.source"/>
  420. </xsl:call-template>
  421. </xsl:variable>
  422. <xsl:call-template name="make.css.link">
  423. <xsl:with-param name="css.filename" select="$filename"/>
  424. </xsl:call-template>
  425. </xsl:if>
  426. </xsl:template>
  427. <xsl:template name="generate.custom.css.link">
  428. <xsl:if test="$custom.css.source != ''">
  429. <xsl:variable name="filename">
  430. <xsl:call-template name="css.output.filename">
  431. <xsl:with-param name="src" select="$custom.css.source"/>
  432. </xsl:call-template>
  433. </xsl:variable>
  434. <xsl:call-template name="make.css.link">
  435. <xsl:with-param name="css.filename" select="$filename"/>
  436. </xsl:call-template>
  437. </xsl:if>
  438. </xsl:template>
  439. <!-- a CSS link reference must take into account the relative
  440. path to a CSS file when chunked HTML is output to more than one directory -->
  441. <xsl:template name="make.css.link">
  442. <xsl:param name="css.filename" select="''"/>
  443. <xsl:variable name="href">
  444. <xsl:call-template name="relative.path.link">
  445. <xsl:with-param name="target.pathname" select="$css.filename"/>
  446. </xsl:call-template>
  447. </xsl:variable>
  448. <xsl:if test="string-length($css.filename) != 0">
  449. <link rel="stylesheet" type="text/css" href="{$href}"/>
  450. </xsl:if>
  451. </xsl:template>
  452. <!-- And the same applies to script links -->
  453. <xsl:template name="make.script.link">
  454. <xsl:param name="script.filename" select="''"/>
  455. <xsl:variable name="src">
  456. <xsl:call-template name="relative.path.link">
  457. <xsl:with-param name="target.pathname" select="$script.filename"/>
  458. </xsl:call-template>
  459. </xsl:variable>
  460. <xsl:if test="string-length($script.filename) != 0">
  461. <script>
  462. <xsl:attribute name="src">
  463. <xsl:value-of select="$src"/>
  464. </xsl:attribute>
  465. <xsl:attribute name="type">
  466. <xsl:value-of select="$html.script.type"/>
  467. </xsl:attribute>
  468. <xsl:call-template name="other.script.attributes">
  469. <xsl:with-param name="script.filename" select="$script.filename"/>
  470. </xsl:call-template>
  471. </script>
  472. </xsl:if>
  473. </xsl:template>
  474. <xsl:template name="other.script.attributes">
  475. <xsl:param name="script.filename"/>
  476. <!-- Placeholder template to allow customization to
  477. insert additional script element attributes if needed -->
  478. </xsl:template>
  479. <xsl:template name="relative.path.link">
  480. <xsl:param name="target.pathname"/>
  481. <xsl:variable name="href.to.uri" select="$target.pathname"/>
  482. <xsl:variable name="href.from.uri">
  483. <xsl:call-template name="href.target.uri">
  484. <xsl:with-param name="object" select="."/>
  485. </xsl:call-template>
  486. </xsl:variable>
  487. <xsl:variable name="href.to">
  488. <xsl:call-template name="trim.common.uri.paths">
  489. <xsl:with-param name="uriA" select="$href.to.uri"/>
  490. <xsl:with-param name="uriB" select="$href.from.uri"/>
  491. <xsl:with-param name="return" select="'A'"/>
  492. </xsl:call-template>
  493. </xsl:variable>
  494. <xsl:variable name="href.from">
  495. <xsl:call-template name="trim.common.uri.paths">
  496. <xsl:with-param name="uriA" select="$href.to.uri"/>
  497. <xsl:with-param name="uriB" select="$href.from.uri"/>
  498. <xsl:with-param name="return" select="'B'"/>
  499. </xsl:call-template>
  500. </xsl:variable>
  501. <xsl:variable name="depth">
  502. <xsl:call-template name="count.uri.path.depth">
  503. <xsl:with-param name="filename" select="$href.from"/>
  504. </xsl:call-template>
  505. </xsl:variable>
  506. <xsl:variable name="href">
  507. <xsl:call-template name="copy-string">
  508. <xsl:with-param name="string" select="'../'"/>
  509. <xsl:with-param name="count" select="$depth"/>
  510. </xsl:call-template>
  511. <xsl:value-of select="$href.to"/>
  512. </xsl:variable>
  513. <xsl:value-of select="$href"/>
  514. </xsl:template>
  515. <!-- ==================================================================== -->
  516. <xsl:template name="generate.css.files">
  517. <xsl:call-template name="generate.default.css.file"/>
  518. <xsl:call-template name="generate.custom.css.file"/>
  519. </xsl:template>
  520. <xsl:template name="generate.default.css.file">
  521. <xsl:if test="$make.clean.html != 0 and $generate.css.header = 0 and $docbook.css.source != ''">
  522. <!-- Select default file relative to stylesheet -->
  523. <xsl:variable name="css.node" select="document($docbook.css.source)/*[1]"/>
  524. <xsl:call-template name="generate.css.file">
  525. <xsl:with-param name="src" select="$docbook.css.source"/>
  526. <xsl:with-param name="css.node" select="$css.node"/>
  527. </xsl:call-template>
  528. </xsl:if>
  529. </xsl:template>
  530. <xsl:template name="generate.custom.css.file">
  531. <xsl:if test="$custom.css.source != '' and $generate.css.header = 0">
  532. <!-- Select custom file relative to document -->
  533. <xsl:variable name="css.node" select="document($custom.css.source,.)/*[1]"/>
  534. <xsl:call-template name="generate.css.file">
  535. <xsl:with-param name="src" select="$custom.css.source"/>
  536. <xsl:with-param name="css.node" select="$css.node"/>
  537. </xsl:call-template>
  538. </xsl:if>
  539. </xsl:template>
  540. <xsl:template name="generate.css.file">
  541. <xsl:param name="css.node"/>
  542. <xsl:param name="src" select="''"/>
  543. <xsl:variable name="css.text" select="$css.node/text()"/>
  544. <xsl:choose>
  545. <xsl:when test="count($css.node) = 0">
  546. <xsl:message>
  547. <xsl:text>ERROR: no root element for CSS source file'</xsl:text>
  548. <xsl:value-of select="$src"/>
  549. <xsl:text>'.</xsl:text>
  550. </xsl:message>
  551. </xsl:when>
  552. <xsl:otherwise>
  553. <xsl:variable name="filename">
  554. <xsl:call-template name="css.output.pathname">
  555. <xsl:with-param name="src" select="$src"/>
  556. <xsl:with-param name="content" select="$css.node"/>
  557. </xsl:call-template>
  558. </xsl:variable>
  559. <xsl:call-template name="write.text.chunk">
  560. <xsl:with-param name="filename" select="$filename"/>
  561. <xsl:with-param name="content" select="$css.text"/>
  562. </xsl:call-template>
  563. </xsl:otherwise>
  564. </xsl:choose>
  565. </xsl:template>
  566. <xsl:template name="css.output.filename">
  567. <xsl:param name="content"/>
  568. <xsl:param name="src" select="''"/>
  569. <xsl:variable name="candidate">
  570. <xsl:choose>
  571. <xsl:when test="string-length($src) = 0">
  572. <xsl:message>
  573. <xsl:text>ERROR: missing CSS input filename.</xsl:text>
  574. </xsl:message>
  575. </xsl:when>
  576. <xsl:when test="substring($src,string-length($src)-3) = '.xml'">
  577. <xsl:value-of select="substring($src, 1, string-length($src) - 4)"/>
  578. </xsl:when>
  579. <xsl:otherwise>
  580. <xsl:value-of select="$src"/>
  581. </xsl:otherwise>
  582. </xsl:choose>
  583. </xsl:variable>
  584. <xsl:value-of select="$candidate"/>
  585. </xsl:template>
  586. <xsl:template name="css.output.pathname">
  587. <xsl:param name="content"/>
  588. <xsl:param name="src" select="''"/>
  589. <xsl:variable name="file">
  590. <xsl:call-template name="css.output.filename">
  591. <xsl:with-param name="content" select="$content"/>
  592. <xsl:with-param name="src" select="$src"/>
  593. </xsl:call-template>
  594. </xsl:variable>
  595. <xsl:variable name="path" select="concat($chunk.base.dir, $file)"/>
  596. <xsl:value-of select="$path"/>
  597. </xsl:template>
  598. </xsl:stylesheet>