qandaset.xsl 14 KB

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