qandaset.xsl 14 KB

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