html.xsl 23 KB

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