qandaset.xsl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  4. version='1.0'>
  5. <!-- ********************************************************************
  6. $Id$
  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. <!-- ==================================================================== -->
  13. <xsl:template match="qandaset" name="process.qandaset">
  14. <xsl:variable name="id">
  15. <xsl:call-template name="object.id"/>
  16. </xsl:variable>
  17. <xsl:variable name="label-width">
  18. <xsl:call-template name="pi.dbfo_label-width"/>
  19. </xsl:variable>
  20. <xsl:variable name="label-length">
  21. <xsl:choose>
  22. <xsl:when test="$label-width != ''">
  23. <xsl:value-of select="$label-width"/>
  24. </xsl:when>
  25. <xsl:when test="descendant::label">
  26. <xsl:call-template name="longest.term">
  27. <xsl:with-param name="terms" select="descendant::label"/>
  28. <xsl:with-param name="maxlength" select="20"/>
  29. </xsl:call-template>
  30. <xsl:text>em * 0.50</xsl:text>
  31. </xsl:when>
  32. <xsl:otherwise>2.5em</xsl:otherwise>
  33. </xsl:choose>
  34. </xsl:variable>
  35. <xsl:variable name="toc">
  36. <xsl:call-template name="pi.dbfo_toc"/>
  37. </xsl:variable>
  38. <xsl:variable name="toc.params">
  39. <xsl:call-template name="find.path.params">
  40. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  41. </xsl:call-template>
  42. </xsl:variable>
  43. <xsl:variable name="content">
  44. <fo:block id="{$id}">
  45. <xsl:choose>
  46. <xsl:when test="parent::*">
  47. <xsl:if test="blockinfo/title|info/title|title">
  48. <xsl:apply-templates select="(blockinfo/title|
  49. info/title|title)[1]"/>
  50. </xsl:if>
  51. </xsl:when>
  52. <!-- If it is the root element -->
  53. <xsl:otherwise>
  54. <xsl:call-template name="qandaset.titlepage"/>
  55. </xsl:otherwise>
  56. </xsl:choose>
  57. <xsl:if test="(contains($toc.params, 'toc') and $toc != '0')
  58. or $toc = '1'">
  59. <xsl:call-template name="qandaset.toc">
  60. <xsl:with-param name="toc.title.p"
  61. select="contains($toc.params, 'title')"/>
  62. </xsl:call-template>
  63. </xsl:if>
  64. <xsl:call-template name="qandaset.toc.separator"/>
  65. <xsl:apply-templates select="*[local-name(.) != 'title'
  66. and local-name(.) != 'titleabbrev'
  67. and local-name(.) != 'qandadiv'
  68. and local-name(.) != 'qandaentry']"/>
  69. <xsl:apply-templates select="qandadiv"/>
  70. <xsl:if test="qandaentry">
  71. <fo:list-block xsl:use-attribute-sets="list.block.spacing"
  72. provisional-label-separation="0.2em">
  73. <xsl:attribute name="provisional-distance-between-starts">
  74. <xsl:choose>
  75. <xsl:when test="$label-length != ''">
  76. <xsl:value-of select="$label-length"/>
  77. </xsl:when>
  78. <xsl:otherwise>2.5em</xsl:otherwise>
  79. </xsl:choose>
  80. </xsl:attribute>
  81. <xsl:apply-templates select="qandaentry"/>
  82. </fo:list-block>
  83. </xsl:if>
  84. </fo:block>
  85. </xsl:variable>
  86. <xsl:choose>
  87. <xsl:when test="parent::*">
  88. <xsl:copy-of select="$content"/>
  89. </xsl:when>
  90. <!-- Otherwise create a page sequence -->
  91. <xsl:otherwise>
  92. <xsl:apply-templates select="." mode="page.sequence">
  93. <xsl:with-param name="content" select="$content"/>
  94. <xsl:with-param name="master-reference" select="'body'"/>
  95. </xsl:apply-templates>
  96. </xsl:otherwise>
  97. </xsl:choose>
  98. </xsl:template>
  99. <xsl:template match="qandaset/blockinfo/title|qandset/info/title|qandaset/title">
  100. <xsl:variable name="enclsect" select="(ancestor::section
  101. | ancestor::simplesect
  102. | ancestor::sect5
  103. | ancestor::sect4
  104. | ancestor::sect3
  105. | ancestor::sect2
  106. | ancestor::sect1
  107. | ancestor::refsect3
  108. | ancestor::refsect2
  109. | ancestor::refsect1)[last()]"/>
  110. <xsl:variable name="sectlvl">
  111. <xsl:call-template name="section.level">
  112. <xsl:with-param name="node" select="$enclsect"/>
  113. </xsl:call-template>
  114. </xsl:variable>
  115. <xsl:call-template name="qanda.heading">
  116. <xsl:with-param name="level" select="$sectlvl + 1"/>
  117. <xsl:with-param name="marker" select="0"/>
  118. <xsl:with-param name="title">
  119. <xsl:apply-templates/>
  120. </xsl:with-param>
  121. </xsl:call-template>
  122. </xsl:template>
  123. <xsl:template match="qandaset/blockinfo|qandaset/info">
  124. <!-- what should this template really do? -->
  125. <xsl:apply-templates select="legalnotice" mode="titlepage.mode"/>
  126. </xsl:template>
  127. <xsl:template match="qandadiv">
  128. <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
  129. <xsl:variable name="label-width">
  130. <xsl:call-template name="pi.dbfo_label-width"/>
  131. </xsl:variable>
  132. <xsl:variable name="label-length">
  133. <xsl:choose>
  134. <xsl:when test="$label-width != ''">
  135. <xsl:value-of select="$label-width"/>
  136. </xsl:when>
  137. <xsl:when test="descendant::label">
  138. <xsl:call-template name="longest.term">
  139. <xsl:with-param name="terms" select="descendant::label"/>
  140. <xsl:with-param name="maxlength" select="20"/>
  141. </xsl:call-template>
  142. <xsl:text>*0.6em</xsl:text>
  143. </xsl:when>
  144. <xsl:otherwise>2.5em</xsl:otherwise>
  145. </xsl:choose>
  146. </xsl:variable>
  147. <fo:block id="{$id}">
  148. <xsl:apply-templates select="(blockinfo/title|info/title|title)[1]"/>
  149. <xsl:apply-templates select="*[local-name(.) != 'title'
  150. and local-name(.) != 'titleabbrev'
  151. and local-name(.) != 'qandadiv'
  152. and local-name(.) != 'qandaentry']"/>
  153. <fo:block>
  154. <xsl:apply-templates select="qandadiv"/>
  155. <xsl:if test="qandaentry">
  156. <fo:list-block xsl:use-attribute-sets="list.block.spacing"
  157. provisional-label-separation="0.2em">
  158. <xsl:attribute name="provisional-distance-between-starts">
  159. <xsl:choose>
  160. <xsl:when test="$label-length != ''">
  161. <xsl:value-of select="$label-length"/>
  162. </xsl:when>
  163. <xsl:otherwise>2.5em</xsl:otherwise>
  164. </xsl:choose>
  165. </xsl:attribute>
  166. <xsl:apply-templates select="qandaentry"/>
  167. </fo:list-block>
  168. </xsl:if>
  169. </fo:block>
  170. </fo:block>
  171. </xsl:template>
  172. <xsl:template match="qandadiv/blockinfo/title|qandadiv/info/title|qandadiv/title">
  173. <xsl:variable name="enclsect" select="(ancestor::section
  174. | ancestor::simplesect
  175. | ancestor::sect5
  176. | ancestor::sect4
  177. | ancestor::sect3
  178. | ancestor::sect2
  179. | ancestor::sect1
  180. | ancestor::refsect3
  181. | ancestor::refsect2
  182. | ancestor::refsect1)[last()]"/>
  183. <xsl:variable name="sectlvl">
  184. <xsl:call-template name="section.level">
  185. <xsl:with-param name="node" select="$enclsect"/>
  186. </xsl:call-template>
  187. </xsl:variable>
  188. <xsl:call-template name="qanda.heading">
  189. <xsl:with-param name="level" select="$sectlvl + 1 + count(ancestor::qandadiv)"/>
  190. <xsl:with-param name="marker" select="0"/>
  191. <xsl:with-param name="title">
  192. <xsl:apply-templates select="parent::qandadiv" mode="label.markup"/>
  193. <xsl:if test="$qandadiv.autolabel != 0">
  194. <xsl:apply-templates select="." mode="intralabel.punctuation"/>
  195. <xsl:text> </xsl:text>
  196. </xsl:if>
  197. <xsl:apply-templates/>
  198. </xsl:with-param>
  199. </xsl:call-template>
  200. </xsl:template>
  201. <xsl:template match="qandaentry">
  202. <!-- Omit revhistory from fo:list-block because it is a table -->
  203. <xsl:apply-templates select="question|answer"/>
  204. </xsl:template>
  205. <xsl:template match="question">
  206. <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
  207. <xsl:variable name="entry.id">
  208. <xsl:call-template name="object.id">
  209. <xsl:with-param name="object" select="parent::*"/>
  210. </xsl:call-template>
  211. </xsl:variable>
  212. <xsl:variable name="deflabel">
  213. <xsl:choose>
  214. <xsl:when test="ancestor-or-self::*[@defaultlabel]">
  215. <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
  216. /@defaultlabel"/>
  217. </xsl:when>
  218. <xsl:otherwise>
  219. <xsl:value-of select="$qanda.defaultlabel"/>
  220. </xsl:otherwise>
  221. </xsl:choose>
  222. </xsl:variable>
  223. <xsl:variable name="label.content">
  224. <xsl:apply-templates select="." mode="label.markup"/>
  225. <xsl:if test="$deflabel = 'number' and not(label)">
  226. <xsl:apply-templates select="." mode="intralabel.punctuation"/>
  227. </xsl:if>
  228. </xsl:variable>
  229. <fo:list-item id="{$entry.id}" xsl:use-attribute-sets="list.item.spacing">
  230. <fo:list-item-label id="{$id}" end-indent="label-end()">
  231. <xsl:if test="string-length($label.content) &gt; 0">
  232. <fo:block font-weight="bold">
  233. <xsl:copy-of select="$label.content"/>
  234. </fo:block>
  235. </xsl:if>
  236. </fo:list-item-label>
  237. <fo:list-item-body start-indent="body-start()">
  238. <xsl:choose>
  239. <xsl:when test="$deflabel = 'none' and not(label)">
  240. <fo:block font-weight="bold">
  241. <xsl:apply-templates select="*[local-name(.)!='label']"/>
  242. </fo:block>
  243. </xsl:when>
  244. <xsl:otherwise>
  245. <xsl:apply-templates select="*[local-name(.)!='label']"/>
  246. </xsl:otherwise>
  247. </xsl:choose>
  248. <!-- Uncomment this line to get revhistory output in the question -->
  249. <!-- <xsl:apply-templates select="preceding-sibling::revhistory"/> -->
  250. </fo:list-item-body>
  251. </fo:list-item>
  252. </xsl:template>
  253. <xsl:template match="answer">
  254. <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
  255. <xsl:variable name="entry.id">
  256. <xsl:call-template name="object.id">
  257. <xsl:with-param name="object" select="parent::*"/>
  258. </xsl:call-template>
  259. </xsl:variable>
  260. <xsl:variable name="deflabel">
  261. <xsl:choose>
  262. <xsl:when test="ancestor-or-self::*[@defaultlabel]">
  263. <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
  264. /@defaultlabel"/>
  265. </xsl:when>
  266. <xsl:otherwise>
  267. <xsl:value-of select="$qanda.defaultlabel"/>
  268. </xsl:otherwise>
  269. </xsl:choose>
  270. </xsl:variable>
  271. <xsl:variable name="answer.label">
  272. <xsl:apply-templates select="." mode="label.markup"/>
  273. </xsl:variable>
  274. <fo:list-item xsl:use-attribute-sets="list.item.spacing">
  275. <fo:list-item-label id="{$id}" end-indent="label-end()">
  276. <xsl:choose>
  277. <xsl:when test="string-length($answer.label) &gt; 0">
  278. <fo:block font-weight="bold">
  279. <xsl:copy-of select="$answer.label"/>
  280. </fo:block>
  281. </xsl:when>
  282. <xsl:otherwise>
  283. <fo:block/>
  284. </xsl:otherwise>
  285. </xsl:choose>
  286. </fo:list-item-label>
  287. <fo:list-item-body start-indent="body-start()">
  288. <xsl:apply-templates select="*[local-name(.)!='label' and local-name(.) != 'qandaentry']"/>
  289. <!-- * handle nested answer/qandaentry instances -->
  290. <!-- * (bug 1509043 from Daniel Leidert) -->
  291. <xsl:if test="descendant::question">
  292. <xsl:call-template name="process.qandaset"/>
  293. </xsl:if>
  294. </fo:list-item-body>
  295. </fo:list-item>
  296. </xsl:template>
  297. <xsl:template match="label">
  298. <xsl:apply-templates/>
  299. </xsl:template>
  300. <xsl:template name="qanda.heading">
  301. <xsl:param name="level" select="1"/>
  302. <xsl:param name="marker" select="0"/>
  303. <xsl:param name="title"/>
  304. <xsl:param name="titleabbrev"/>
  305. <fo:block xsl:use-attribute-sets="qanda.title.properties">
  306. <xsl:if test="$marker != 0">
  307. <fo:marker marker-class-name="section.head.marker">
  308. <xsl:choose>
  309. <xsl:when test="$titleabbrev = ''">
  310. <xsl:value-of select="$title"/>
  311. </xsl:when>
  312. <xsl:otherwise>
  313. <xsl:value-of select="$titleabbrev"/>
  314. </xsl:otherwise>
  315. </xsl:choose>
  316. </fo:marker>
  317. </xsl:if>
  318. <xsl:choose>
  319. <xsl:when test="$level=1">
  320. <fo:block xsl:use-attribute-sets="qanda.title.level1.properties">
  321. <xsl:copy-of select="$title"/>
  322. </fo:block>
  323. </xsl:when>
  324. <xsl:when test="$level=2">
  325. <fo:block xsl:use-attribute-sets="qanda.title.level2.properties">
  326. <xsl:copy-of select="$title"/>
  327. </fo:block>
  328. </xsl:when>
  329. <xsl:when test="$level=3">
  330. <fo:block xsl:use-attribute-sets="qanda.title.level3.properties">
  331. <xsl:copy-of select="$title"/>
  332. </fo:block>
  333. </xsl:when>
  334. <xsl:when test="$level=4">
  335. <fo:block xsl:use-attribute-sets="qanda.title.level4.properties">
  336. <xsl:copy-of select="$title"/>
  337. </fo:block>
  338. </xsl:when>
  339. <xsl:when test="$level=5">
  340. <fo:block xsl:use-attribute-sets="qanda.title.level5.properties">
  341. <xsl:copy-of select="$title"/>
  342. </fo:block>
  343. </xsl:when>
  344. <xsl:otherwise>
  345. <fo:block xsl:use-attribute-sets="qanda.title.level6.properties">
  346. <xsl:copy-of select="$title"/>
  347. </fo:block>
  348. </xsl:otherwise>
  349. </xsl:choose>
  350. </fo:block>
  351. </xsl:template>
  352. </xsl:stylesheet>