qandaset.xsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. exclude-result-prefixes="doc"
  5. version='1.0'>
  6. <!-- ********************************************************************
  7. $Id: qandaset.xsl 9354 2012-05-12 23:29:36Z bobstayton $
  8. ********************************************************************
  9. This file is part of the XSL DocBook Stylesheet distribution.
  10. See ../README or http://docbook.sf.net/release/xsl/current/ for
  11. copyright and other information.
  12. ******************************************************************** -->
  13. <!-- ==================================================================== -->
  14. <xsl:template match="qandaset">
  15. <xsl:variable name="title" select="(blockinfo/title|info/title|title)[1]"/>
  16. <xsl:variable name="preamble" select="*[local-name(.) != 'title'
  17. and local-name(.) != 'titleabbrev'
  18. and local-name(.) != 'qandadiv'
  19. and local-name(.) != 'qandaentry']"/>
  20. <xsl:variable name="toc">
  21. <xsl:call-template name="pi.dbhtml_toc"/>
  22. </xsl:variable>
  23. <xsl:variable name="toc.params">
  24. <xsl:call-template name="find.path.params">
  25. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  26. </xsl:call-template>
  27. </xsl:variable>
  28. <div>
  29. <xsl:apply-templates select="." mode="common.html.attributes"/>
  30. <xsl:call-template name="id.attribute">
  31. <xsl:with-param name="conditional" select="0"/>
  32. </xsl:call-template>
  33. <xsl:apply-templates select="$title"/>
  34. <xsl:if test="not($title)">
  35. <!-- andhor is output on title if there is one -->
  36. <xsl:call-template name="anchor">
  37. <xsl:with-param name="conditional" select="0"/>
  38. </xsl:call-template>
  39. </xsl:if>
  40. <xsl:if test="((contains($toc.params, 'toc') and $toc != '0') or $toc = '1')
  41. and not(ancestor::answer and not($qanda.nested.in.toc=0))">
  42. <xsl:call-template name="process.qanda.toc"/>
  43. </xsl:if>
  44. <xsl:apply-templates select="$preamble"/>
  45. <xsl:call-template name="process.qandaset"/>
  46. </div>
  47. </xsl:template>
  48. <xsl:template match="qandaset/blockinfo/title|
  49. qandaset/info/title|
  50. qandaset/title">
  51. <xsl:variable name="qalevel">
  52. <xsl:call-template name="qanda.section.level"/>
  53. </xsl:variable>
  54. <xsl:element name="h{string(number($qalevel)+1)}">
  55. <xsl:apply-templates select="." mode="class.attribute"/>
  56. <xsl:call-template name="anchor">
  57. <xsl:with-param name="node" select=".."/>
  58. <xsl:with-param name="conditional" select="0"/>
  59. </xsl:call-template>
  60. <xsl:apply-templates/>
  61. </xsl:element>
  62. </xsl:template>
  63. <xsl:template match="qandaset/blockinfo|qandaset/info">
  64. <!-- what should this template really do? -->
  65. <xsl:apply-templates select="legalnotice" mode="titlepage.mode"/>
  66. </xsl:template>
  67. <xsl:template match="qandadiv">
  68. <xsl:variable name="preamble" select="*[local-name(.) != 'title'
  69. and local-name(.) != 'titleabbrev'
  70. and local-name(.) != 'qandadiv'
  71. and local-name(.) != 'qandaentry']"/>
  72. <xsl:if test="blockinfo/title|info/title|title">
  73. <tr class="qandadiv">
  74. <td align="{$direction.align.start}" valign="top" colspan="2">
  75. <xsl:apply-templates select="(blockinfo/title|info/title|title)[1]"/>
  76. </td>
  77. </tr>
  78. </xsl:if>
  79. <xsl:variable name="toc">
  80. <xsl:call-template name="pi.dbhtml_toc"/>
  81. </xsl:variable>
  82. <xsl:variable name="toc.params">
  83. <xsl:call-template name="find.path.params">
  84. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  85. </xsl:call-template>
  86. </xsl:variable>
  87. <xsl:if test="(contains($toc.params, 'toc') and $toc != '0') or $toc = '1'">
  88. <tr class="toc">
  89. <td align="{$direction.align.start}" valign="top" colspan="2">
  90. <xsl:call-template name="process.qanda.toc"/>
  91. </td>
  92. </tr>
  93. </xsl:if>
  94. <xsl:if test="$preamble">
  95. <tr class="toc">
  96. <td align="{$direction.align.start}" valign="top" colspan="2">
  97. <xsl:apply-templates select="$preamble"/>
  98. </td>
  99. </tr>
  100. </xsl:if>
  101. <xsl:apply-templates select="qandadiv|qandaentry"/>
  102. </xsl:template>
  103. <xsl:template match="qandadiv/blockinfo/title|
  104. qandadiv/info/title|
  105. qandadiv/title">
  106. <xsl:variable name="qalevel">
  107. <xsl:call-template name="qandadiv.section.level"/>
  108. </xsl:variable>
  109. <xsl:element name="h{string(number($qalevel)+1)}">
  110. <xsl:apply-templates select="." mode="class.attribute"/>
  111. <xsl:call-template name="id.attribute">
  112. <xsl:with-param name="node" select=".."/>
  113. <xsl:with-param name="conditional" select="0"/>
  114. </xsl:call-template>
  115. <xsl:call-template name="anchor">
  116. <xsl:with-param name="node" select=".."/>
  117. <xsl:with-param name="conditional" select="0"/>
  118. </xsl:call-template>
  119. <xsl:apply-templates select="parent::qandadiv" mode="label.markup"/>
  120. <xsl:if test="$qandadiv.autolabel != 0">
  121. <xsl:apply-templates select="." mode="intralabel.punctuation"/>
  122. <xsl:text> </xsl:text>
  123. </xsl:if>
  124. <xsl:apply-templates/>
  125. </xsl:element>
  126. </xsl:template>
  127. <xsl:template match="qandaentry">
  128. <xsl:apply-templates/>
  129. </xsl:template>
  130. <xsl:template match="question">
  131. <xsl:variable name="deflabel">
  132. <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
  133. </xsl:variable>
  134. <tr>
  135. <xsl:apply-templates select="." mode="common.html.attributes"/>
  136. <!-- capture the id of the quandaentry -->
  137. <xsl:call-template name="id.attribute">
  138. <xsl:with-param name="node" select=".."/>
  139. <xsl:with-param name="conditional" select="0"/>
  140. </xsl:call-template>
  141. <td align="{$direction.align.start}" valign="top">
  142. <!-- and the id of the question too -->
  143. <xsl:call-template name="id.attribute">
  144. <xsl:with-param name="conditional" select="0"/>
  145. </xsl:call-template>
  146. <xsl:call-template name="anchor">
  147. <xsl:with-param name="node" select=".."/>
  148. <xsl:with-param name="conditional" select="0"/>
  149. </xsl:call-template>
  150. <xsl:call-template name="anchor">
  151. <xsl:with-param name="conditional" select="0"/>
  152. </xsl:call-template>
  153. <xsl:variable name="label.content">
  154. <xsl:apply-templates select="." mode="qanda.label"/>
  155. </xsl:variable>
  156. <xsl:if test="string-length($label.content) &gt; 0">
  157. <p><b>
  158. <xsl:copy-of select="$label.content"/>
  159. </b></p>
  160. </xsl:if>
  161. </td>
  162. <td align="{$direction.align.start}" valign="top">
  163. <xsl:choose>
  164. <xsl:when test="$deflabel = 'none' and not(label)">
  165. <b><xsl:apply-templates select="*[local-name(.) != 'label']"/></b>
  166. </xsl:when>
  167. <xsl:otherwise>
  168. <xsl:apply-templates select="*[local-name(.) != 'label']"/>
  169. </xsl:otherwise>
  170. </xsl:choose>
  171. </td>
  172. </tr>
  173. </xsl:template>
  174. <xsl:template match="*" mode="qanda.defaultlabel">
  175. <xsl:choose>
  176. <xsl:when test="ancestor-or-self::*[@defaultlabel]">
  177. <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
  178. /@defaultlabel"/>
  179. </xsl:when>
  180. <xsl:otherwise>
  181. <xsl:value-of select="$qanda.defaultlabel"/>
  182. </xsl:otherwise>
  183. </xsl:choose>
  184. </xsl:template>
  185. <xsl:template match="question" mode="qanda.label">
  186. <xsl:variable name="deflabel">
  187. <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
  188. </xsl:variable>
  189. <xsl:apply-templates select="." mode="label.markup"/>
  190. <xsl:if test="contains($deflabel, 'number') and not(label)">
  191. <xsl:apply-templates select="." mode="intralabel.punctuation"/>
  192. </xsl:if>
  193. </xsl:template>
  194. <xsl:template match="answer">
  195. <xsl:variable name="deflabel">
  196. <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
  197. </xsl:variable>
  198. <tr>
  199. <xsl:apply-templates select="." mode="common.html.attributes"/>
  200. <xsl:call-template name="id.attribute"/>
  201. <td align="{$direction.align.start}" valign="top">
  202. <xsl:call-template name="anchor"/>
  203. <xsl:variable name="answer.label">
  204. <xsl:apply-templates select="." mode="label.markup"/>
  205. </xsl:variable>
  206. <xsl:if test="string-length($answer.label) &gt; 0">
  207. <p><b>
  208. <xsl:copy-of select="$answer.label"/>
  209. </b></p>
  210. </xsl:if>
  211. </td>
  212. <td align="{$direction.align.start}" valign="top">
  213. <xsl:apply-templates select="*[local-name(.) != 'label'
  214. and local-name(.) != 'qandaentry']"/>
  215. <!-- * handle nested answer/qandaentry instances -->
  216. <!-- * (bug 1509043 from Daniel Leidert) -->
  217. <xsl:if test="descendant::question">
  218. <xsl:call-template name="process.qandaset"/>
  219. </xsl:if>
  220. </td>
  221. </tr>
  222. </xsl:template>
  223. <xsl:template match="answer" mode="qanda.label">
  224. <xsl:apply-templates select="." mode="label.markup"/>
  225. </xsl:template>
  226. <xsl:template match="label">
  227. <xsl:apply-templates/>
  228. </xsl:template>
  229. <!-- ==================================================================== -->
  230. <xsl:template name="process.qanda.toc">
  231. <!-- * if user wants nested qandaset and qandaentry in main Qandaset TOC, -->
  232. <!-- * then don't also include the nested stuff in the sub TOCs -->
  233. <dl>
  234. <xsl:apply-templates select="qandadiv" mode="qandatoc.mode"/>
  235. <xsl:apply-templates select="qandaset|qandaentry" mode="qandatoc.mode"/>
  236. </dl>
  237. </xsl:template>
  238. <xsl:template match="qandadiv" mode="qandatoc.mode">
  239. <dt><xsl:apply-templates select="title" mode="qandatoc.mode"/></dt>
  240. <dd><xsl:call-template name="process.qanda.toc"/></dd>
  241. </xsl:template>
  242. <xsl:template match="qandadiv/blockinfo/title|
  243. qandadiv/info/title|
  244. qandadiv/title" mode="qandatoc.mode">
  245. <xsl:variable name="qalevel">
  246. <xsl:call-template name="qandadiv.section.level"/>
  247. </xsl:variable>
  248. <xsl:variable name="id">
  249. <xsl:call-template name="object.id">
  250. <xsl:with-param name="object" select="parent::*"/>
  251. </xsl:call-template>
  252. </xsl:variable>
  253. <xsl:variable name="div.label">
  254. <xsl:apply-templates select="parent::qandadiv" mode="label.markup"/>
  255. </xsl:variable>
  256. <xsl:if test="string-length($div.label) != 0">
  257. <xsl:copy-of select="$div.label"/>
  258. <xsl:value-of select="$autotoc.label.separator"/>
  259. </xsl:if>
  260. <xsl:text> </xsl:text>
  261. <a>
  262. <xsl:attribute name="href">
  263. <xsl:call-template name="href.target">
  264. <xsl:with-param name="object" select="parent::*"/>
  265. </xsl:call-template>
  266. </xsl:attribute>
  267. <xsl:apply-templates/>
  268. </a>
  269. </xsl:template>
  270. <xsl:template match="qandaset" mode="qandatoc.mode">
  271. <xsl:for-each select="qandaentry">
  272. <xsl:apply-templates select="." mode="qandatoc.mode"/>
  273. </xsl:for-each>
  274. </xsl:template>
  275. <xsl:template match="qandaentry" mode="qandatoc.mode">
  276. <xsl:apply-templates select="question" mode="qandatoc.mode"/>
  277. </xsl:template>
  278. <xsl:template match="question" mode="qandatoc.mode">
  279. <xsl:variable name="firstch">
  280. <!-- Use a titleabbrev or title if available -->
  281. <xsl:choose>
  282. <xsl:when test="../blockinfo/titleabbrev">
  283. <xsl:apply-templates select="../blockinfo/titleabbrev[1]/node()"/>
  284. </xsl:when>
  285. <xsl:when test="../blockinfo/title">
  286. <xsl:apply-templates select="../blockinfo/title[1]/node()"/>
  287. </xsl:when>
  288. <xsl:when test="../info/titleabbrev">
  289. <xsl:apply-templates select="../info/titleabbrev[1]/node()"/>
  290. </xsl:when>
  291. <xsl:when test="../titleabbrev">
  292. <xsl:apply-templates select="../titleabbrev[1]/node()"/>
  293. </xsl:when>
  294. <xsl:when test="../info/title">
  295. <xsl:apply-templates select="../info/title[1]/node()"/>
  296. </xsl:when>
  297. <xsl:when test="../title">
  298. <xsl:apply-templates select="../title[1]/node()"/>
  299. </xsl:when>
  300. <xsl:otherwise>
  301. <xsl:apply-templates select="(*[local-name(.)!='label'])[1]/node()"/>
  302. </xsl:otherwise>
  303. </xsl:choose>
  304. </xsl:variable>
  305. <xsl:variable name="deflabel">
  306. <xsl:choose>
  307. <xsl:when test="ancestor-or-self::*[@defaultlabel]">
  308. <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
  309. /@defaultlabel"/>
  310. </xsl:when>
  311. <xsl:otherwise>
  312. <xsl:value-of select="$qanda.defaultlabel"/>
  313. </xsl:otherwise>
  314. </xsl:choose>
  315. </xsl:variable>
  316. <dt>
  317. <xsl:apply-templates select="." mode="label.markup"/>
  318. <xsl:if test="contains($deflabel,'number') and not(label)">
  319. <xsl:apply-templates select="." mode="intralabel.punctuation"/>
  320. </xsl:if>
  321. <xsl:text> </xsl:text>
  322. <a>
  323. <xsl:attribute name="href">
  324. <xsl:call-template name="href.target">
  325. <xsl:with-param name="object" select=".."/>
  326. </xsl:call-template>
  327. </xsl:attribute>
  328. <xsl:value-of select="$firstch"/>
  329. </a>
  330. </dt>
  331. <!-- * include nested qandaset/qandaentry in TOC if user wants it -->
  332. <xsl:if test="not($qanda.nested.in.toc = 0)">
  333. <xsl:apply-templates select="following-sibling::answer" mode="qandatoc.mode"/>
  334. </xsl:if>
  335. </xsl:template>
  336. <xsl:template match="answer" mode="qandatoc.mode">
  337. <xsl:if test="descendant::question">
  338. <dd>
  339. <xsl:call-template name="process.qanda.toc"/>
  340. </dd>
  341. </xsl:if>
  342. </xsl:template>
  343. <!-- ==================================================================== -->
  344. <xsl:template name="process.qandaset">
  345. <xsl:variable name="deflabel">
  346. <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
  347. </xsl:variable>
  348. <xsl:variable name="label-width">
  349. <xsl:call-template name="pi.dbhtml_label-width"/>
  350. </xsl:variable>
  351. <xsl:variable name="table-summary">
  352. <xsl:call-template name="pi.dbhtml_table-summary"/>
  353. </xsl:variable>
  354. <xsl:variable name="cellpadding">
  355. <xsl:call-template name="pi.dbhtml_cellpadding"/>
  356. </xsl:variable>
  357. <xsl:variable name="cellspacing">
  358. <xsl:call-template name="pi.dbhtml_cellspacing"/>
  359. </xsl:variable>
  360. <table border="{$table.border.off}">
  361. <xsl:if test="$css.decoration != 0">
  362. <xsl:attribute name="style">width: 100%;</xsl:attribute>
  363. </xsl:if>
  364. <xsl:if test="$table-summary != ''">
  365. <xsl:attribute name="summary">
  366. <xsl:value-of select="$table-summary"/>
  367. </xsl:attribute>
  368. </xsl:if>
  369. <xsl:if test="$cellpadding != ''">
  370. <xsl:attribute name="cellpadding">
  371. <xsl:value-of select="$cellpadding"/>
  372. </xsl:attribute>
  373. </xsl:if>
  374. <xsl:if test="$cellspacing != ''">
  375. <xsl:attribute name="cellspacing">
  376. <xsl:value-of select="$cellspacing"/>
  377. </xsl:attribute>
  378. </xsl:if>
  379. <colgroup>
  380. <col align="{$direction.align.start}">
  381. <xsl:attribute name="width">
  382. <xsl:choose>
  383. <xsl:when test="$label-width != ''">
  384. <xsl:value-of select="$label-width"/>
  385. </xsl:when>
  386. <xsl:otherwise>
  387. <xsl:text>1%</xsl:text>
  388. </xsl:otherwise>
  389. </xsl:choose>
  390. </xsl:attribute>
  391. </col>
  392. <col/>
  393. </colgroup>
  394. <tbody>
  395. <xsl:apply-templates select="qandaentry|qandadiv"/>
  396. </tbody>
  397. </table>
  398. </xsl:template>
  399. <!-- ==================================================================== -->
  400. <xsl:template match="*" mode="no.wrapper.mode">
  401. <xsl:apply-templates/>
  402. </xsl:template>
  403. <!-- ==================================================================== -->
  404. </xsl:stylesheet>