dbk2pages.xsl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <xsl:stylesheet version="1.0"
  2. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:sfa="http://developer.apple.com/namespaces/sfa"
  4. xmlns:sf="http://developer.apple.com/namespaces/sf"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xmlns:sl="http://developer.apple.com/namespaces/sl"
  7. xmlns:xi="http://www.w3.org/2001/XInclude"
  8. xmlns:doc='http://docbook.org/ns/docbook'
  9. xmlns:rnd='http://docbook.org/ns/docbook/roundtrip'
  10. exclude-result-prefixes='doc rnd xi'>
  11. <xsl:import href='dbk2wp.xsl'/>
  12. <xsl:output method="xml" indent='yes' encoding='ascii'/>
  13. <!-- ********************************************************************
  14. $Id: dbk2pages.xsl 9396 2012-06-02 21:56:19Z bobstayton $
  15. ********************************************************************
  16. This file is part of the XSL DocBook Stylesheet distribution.
  17. See ../README or http://docbook.sf.net/release/xsl/current/ for
  18. copyright and other information.
  19. ******************************************************************** -->
  20. <xsl:include href='../VERSION.xsl'/>
  21. <xsl:include href='param.xsl'/>
  22. <xsl:variable name='templatedoc' select='document($pages.template)'/>
  23. <!-- Find all tables in the document once,
  24. as we will be iterating over them in more than one place.
  25. -->
  26. <xsl:variable name='rnd:pages-tables'
  27. select='//doc:table|//doc:informaltable'/>
  28. <!-- Lookup style identifiers from their user-visible name -->
  29. <xsl:variable name='paragraph-styles'
  30. select='$templatedoc//sf:paragraphstyle'/>
  31. <xsl:variable name='character-styles'
  32. select='$templatedoc//sf:characterstyle'/>
  33. <xsl:template match="/" name='pages.top'>
  34. <xsl:param name='doc' select='/'/>
  35. <xsl:if test='not($pages.template)'>
  36. <xsl:message terminate='yes'>Please specify the template document with the "pages.template" parameter</xsl:message>
  37. </xsl:if>
  38. <xsl:if test='not($templatedoc)'>
  39. <xsl:message terminate='yes'>Unable to open template document "<xsl:value-of select='$pages.template'/>"</xsl:message>
  40. </xsl:if>
  41. <sl:document
  42. sfa:ID="SLPublicationModel-0"
  43. sl:version="72007061400"
  44. sl:generator="slingshot"
  45. sl:app_build_date="Sep 26 2007, 14:46:11">
  46. <xsl:apply-templates select='$templatedoc/sl:document/*[not(self::sf:text-storage)]'
  47. mode='doc:copy'/>
  48. <xsl:apply-templates select='$doc/*'
  49. mode='doc:toplevel'/>
  50. <xsl:apply-templates select='$templatedoc/sl:document/sf:text-storage/following-sibling::*'
  51. mode='doc:copy'/>
  52. </sl:document>
  53. </xsl:template>
  54. <xsl:template match='sf:calc-engine' mode='doc:copy'>
  55. <xsl:copy>
  56. <xsl:apply-templates select='@*' mode='doc:copy'/>
  57. <xsl:choose>
  58. <xsl:when test='not(sf:calc-engine-entities)'>
  59. <xsl:call-template name='rnd:pages-make-calc-engine-entities'/>
  60. <xsl:apply-templates mode='doc:copy'/>
  61. </xsl:when>
  62. <xsl:otherwise>
  63. <xsl:apply-templates mode='doc:copy'/>
  64. </xsl:otherwise>
  65. </xsl:choose>
  66. </xsl:copy>
  67. </xsl:template>
  68. <xsl:template name='rnd:pages-make-calc-engine-entities'
  69. match='sf:calc-engine-entities' mode='doc:copy'>
  70. <sf:calc-engine-entities>
  71. <xsl:choose>
  72. <xsl:when test='self::calc-engine-entities'>
  73. <xsl:apply-templates select='@*' mode='doc:copy'/>
  74. <xsl:apply-templates mode='doc:copy'/>
  75. </xsl:when>
  76. <xsl:otherwise>
  77. <xsl:attribute name='sfa:ID'>
  78. <xsl:text>DocBookRoundtrip-1</xsl:text>
  79. </xsl:attribute>
  80. </xsl:otherwise>
  81. </xsl:choose>
  82. <xsl:for-each select='$rnd:pages-tables'>
  83. <xsl:variable name='num' select='position()'/>
  84. <xsl:variable name='num-cells'
  85. select='count(doc:tgroup/*/doc:row/doc:entry)'/>
  86. <xsl:variable name='num-rows' select='count(doc:tgroup/*/doc:row)'/>
  87. <xsl:variable name='num-cols' select='$num-cells div $num-rows'/>
  88. <sf:tabular-model sfa:ID='SFTTableModel-{$num}' sf:name='Unnamed Table'
  89. sfa:id=''
  90. sf:num-header-rows='{count(doc:tgroup/doc:thead/doc:row)}' sf:num-footer-rows='{count(doc:tgroup/doc:tfoot/doc:row)}'
  91. sf:num-header-columns='0' sf:name-is-visible='false' sf:grouping-enabled='false'>
  92. <sf:grid sfa:ID='SFTTableGrid-{$num}'
  93. sf:ocnt='{$num-cells}'
  94. sf:numcols='{$num-cols}'
  95. sf:numrows='{$num-rows}'
  96. sf:hiddennumcols='0' sf:hiddennumrows='0'>
  97. <sf:columns sf:count='{$num-cols}'>
  98. <xsl:apply-templates select='doc:tgroup/doc:colspec'
  99. mode='rnd:pages-table-colspec'/>
  100. </sf:columns>
  101. <sf:vertical-gridline-styles sf:array-size='0'/> <!-- TODO: borders -->
  102. <sf:rows sf:count='{$num-rows}'>
  103. <xsl:call-template name='rnd:pages-make-table-rowspecs'>
  104. <xsl:with-param name='number' select='$num-rows'/>
  105. </xsl:call-template>
  106. </sf:rows>
  107. <sf:horizontal-gridline-styles sf:array-size='0'/> <!-- TODO: borders -->
  108. <sf:datasource sfa:ID='SFTConcreteTableDataSource-{$num}'>
  109. <xsl:apply-templates select='doc:tgroup/doc:thead/doc:row'
  110. mode='rnd:pages-table-data'>
  111. <xsl:with-param name='start-row' select='0'/>
  112. </xsl:apply-templates>
  113. <xsl:apply-templates select='doc:tgroup/doc:tbody/doc:row'
  114. mode='rnd:pages-table-data'>
  115. <xsl:with-param name='start-row' select='count(doc:tgroup/doc:thead/doc:row)'/>
  116. </xsl:apply-templates>
  117. <xsl:apply-templates select='doc:tgroup/doc:tfoot/doc:row'
  118. mode='rnd:pages-table-data'>
  119. <xsl:with-param name='start-row' select='count(doc:tgroup/doc:thead/doc:row) + count(doc:tgroup/doc:tbody/doc:row)'/>
  120. </xsl:apply-templates>
  121. </sf:datasource>
  122. <sf:sort sfa:ID='DocBookPagesTableNSArray-{$num}'>
  123. <sf:sort-spec sfa:ID='SFTTableSortSpec-{$num}'
  124. sf:sort-col='0' sf:sort-order='true'/>
  125. </sf:sort>
  126. <sf:filterset sfa:ID='SFTTableFilterSet-{$num}'
  127. sf:type='0' sf:enabled='false' sf:spec-count='1'>
  128. <sf:filterspec sfa:ID='SFTTableFilterSpec-{$num}'
  129. sf:filtercol='0' sf:predicate='1' sf:keyscale='0' sf:key1=''/>
  130. </sf:filterset>
  131. <sf:cell-comment-mapping sfa:ID='DocBookPagesTableCellCommentNSMutableDictionary-{$num}'/>
  132. <sf:error_warning_mapping sfa:ID='DocBookPagesTableErrorWarningNSMutableDictionary-{$num}'/>
  133. </sf:grid>
  134. </sf:tabular-model>
  135. </xsl:for-each>
  136. </sf:calc-engine-entities>
  137. </xsl:template>
  138. <xsl:template match='doc:row' mode='rnd:pages-table-data'>
  139. <xsl:param name='start-row' select='0'/>
  140. <xsl:apply-templates mode='rnd:pages-table-data'>
  141. <xsl:with-param name='row'
  142. select='$start-row + count(preceding-sibling::doc:row)'/>
  143. </xsl:apply-templates>
  144. </xsl:template>
  145. <xsl:template match='doc:entry' mode='rnd:pages-table-data'>
  146. <xsl:param name='row' select='0'/>
  147. <sf:text-cell sf:flags='4' sf:col='{count(preceding-sibling::doc:entry)}' sf:row='{$row}'>
  148. <sf:cell-style-ref sfa:IDREF='SFTCellStyle-3'/>
  149. <sf:content-size sfa:w='60' sfa:h='25'/>
  150. <sf:cell-text>
  151. <xsl:choose>
  152. <xsl:when test='count(.//*) > 2'>
  153. <sf:cell-storage>
  154. <sf:stylesheet-ref sfa:IDREF="SFSStylesheet-1"/>
  155. <sf:text-body>
  156. <xsl:apply-templates/>
  157. </sf:text-body>
  158. </sf:cell-storage>
  159. </xsl:when>
  160. <xsl:otherwise>
  161. <xsl:attribute name='sfa:string'>
  162. <xsl:apply-templates mode='rnd:pages-table-text'/>
  163. </xsl:attribute>
  164. </xsl:otherwise>
  165. </xsl:choose>
  166. </sf:cell-text>
  167. </sf:text-cell>
  168. </xsl:template>
  169. <xsl:template name='rnd:pages-make-table-rowspecs'>
  170. <xsl:param name='number' select='0'/>
  171. <xsl:choose>
  172. <xsl:when test='$number &lt;= 0'/>
  173. <xsl:otherwise>
  174. <sf:grid-row sf:height='25' sf:fitting-height='25'/>
  175. <xsl:call-template name='rnd:pages-make-table-rowspecs'>
  176. <xsl:with-param name='number' select='$number - 1'/>
  177. </xsl:call-template>
  178. </xsl:otherwise>
  179. </xsl:choose>
  180. </xsl:template>
  181. <xsl:template match='doc:colspec' mode='rnd:pages-table-colspec'>
  182. <sf:grid-column sf:width='{@colwidth}' sf:preferred-width='{@colwidth}'
  183. sf:fitting-width='{@colwidth}'/>
  184. </xsl:template>
  185. <xsl:template name='doc:make-body'>
  186. <xsl:param name='content'>
  187. <xsl:apply-templates mode='doc:body'/>
  188. </xsl:param>
  189. <sf:text-storage sf:kind='body' sfa:ID='SFWPStorage-7'>
  190. <sf:stylesheet-ref sfa:IDREF='SFSStylesheet-1'/>
  191. <xsl:if test='$rnd:pages-tables'>
  192. <sf:attachments>
  193. <xsl:for-each select='$rnd:pages-tables'>
  194. <xsl:variable name='num' select='position()'/>
  195. <sf:attachment sfa:ID='SFTTableAttachment-{$num}'
  196. sfa:sfclass='' sf:kind='tabular-attachment'>
  197. <sf:tabular-info sfa:ID='SFTTableInfo-{$num}'>
  198. <sf:geometry sfa:ID='DocBookAffineGeometry-{$num}'
  199. sf:sizesLocked='true'>
  200. <sf:naturalSize sfa:w='480' sfa:h='126'/>
  201. <sf:size sfa:w='480' sfa:h='126'/>
  202. <sf:position sfa:x='0' sfa:y='0'/>
  203. </sf:geometry>
  204. <sf:style>
  205. <sf:tabular-style-ref sfa:IDREF='SFTTableStyle-0'/>
  206. </sf:style>
  207. <sf:tabular-model-ref sfa:IDREF='SFTTableModel-{$num}'/>
  208. </sf:tabular-info>
  209. <sf:position sfa:x='0' sfa:y='0'/>
  210. </sf:attachment>
  211. </xsl:for-each>
  212. </sf:attachments>
  213. </xsl:if>
  214. <sf:text-body>
  215. <sf:page-start sf:page-index='0'/>
  216. <sf:container-hint sf:page-index="0" sf:cindex="0" sf:sindex="0" sf:lindex="0" sf:frame-x="56.692913055419922" sf:frame-y="56.692913055419922" sf:frame-w="481.61416625976562" sf:frame-h="714" sf:anchor-loc="0"/>
  217. <sf:section sf:name="Chapter 1" sf:style="section-style-0">
  218. <sf:layout sf:style="layout-style-20">
  219. <xsl:copy-of select='$content'/>
  220. </sf:layout>
  221. </sf:section>
  222. </sf:text-body>
  223. </sf:text-storage>
  224. </xsl:template>
  225. <xsl:template name='doc:make-subsection'>
  226. <xsl:param name='content'>
  227. <xsl:apply-templates mode='doc:body'/>
  228. </xsl:param>
  229. <xsl:copy-of select='$content'/>
  230. </xsl:template>
  231. <xsl:template name='doc:make-paragraph'>
  232. <xsl:param name='style' select='"unknown"'/>
  233. <xsl:param name='content'>
  234. <xsl:apply-templates mode='doc:body'/>
  235. </xsl:param>
  236. <xsl:param name='outline.level' select='0'/>
  237. <xsl:param name='attributes.node' select='.'/>
  238. <sf:p>
  239. <xsl:if test='$style != ""'>
  240. <xsl:attribute name='sf:style'>
  241. <xsl:call-template name='doc:lookup-paragraph-style'>
  242. <xsl:with-param name='style' select='$style'/>
  243. </xsl:call-template>
  244. </xsl:attribute>
  245. </xsl:if>
  246. <xsl:call-template name='attributes'>
  247. <xsl:with-param name='node' select='$attributes.node'/>
  248. </xsl:call-template>
  249. <xsl:copy-of select='$content'/>
  250. <sf:br/>
  251. </sf:p>
  252. </xsl:template>
  253. <xsl:template name='doc:make-phrase'>
  254. <xsl:param name='style' select='""'/>
  255. <xsl:param name='italic' select='0'/>
  256. <xsl:param name='bold' select='0'/>
  257. <xsl:param name='content'>
  258. <xsl:apply-templates mode='doc:phrase'/>
  259. </xsl:param>
  260. <!-- TODO: handle italic and bold parameters -->
  261. <xsl:choose>
  262. <xsl:when test='$style != ""'>
  263. <sf:span>
  264. <xsl:attribute name='sf:style'>
  265. <xsl:call-template name='doc:lookup-character-style'>
  266. <xsl:with-param name='style' select='$style'/>
  267. </xsl:call-template>
  268. </xsl:attribute>
  269. <xsl:copy-of select='$content'/>
  270. </sf:span>
  271. </xsl:when>
  272. <xsl:otherwise>
  273. <xsl:copy-of select='$content'/>
  274. </xsl:otherwise>
  275. </xsl:choose>
  276. </xsl:template>
  277. <xsl:template name='doc:make-hyperlink'>
  278. <xsl:param name='target'/>
  279. <xsl:param name='content'>
  280. <xsl:apply-templates mode='doc:body'/>
  281. </xsl:param>
  282. <sf:link href='{$target}'>
  283. <sf:span>
  284. <xsl:attribute name='sf:style'>
  285. <xsl:call-template name='doc:lookup-character-style'>
  286. <xsl:with-param name='style'>email</xsl:with-param>
  287. </xsl:call-template>
  288. </xsl:attribute>
  289. <xsl:copy-of select='$content'/>
  290. </sf:span>
  291. </sf:link>
  292. </xsl:template>
  293. <xsl:template name='doc:make-table'>
  294. <xsl:param name='columns'/>
  295. <xsl:param name='content'>
  296. <xsl:apply-templates mode='doc:body'/>
  297. </xsl:param>
  298. <xsl:variable name='this' select='.'/>
  299. <sf:p>
  300. <xsl:attribute name='sf:style'>
  301. <xsl:call-template name='doc:lookup-paragraph-style'>
  302. <xsl:with-param name='style' select='"para"'/>
  303. </xsl:call-template>
  304. </xsl:attribute>
  305. <sf:attachment-ref sf:kind='tabular-attachment'>
  306. <xsl:attribute name='sfa:IDREF'>
  307. <xsl:text>SFTTableAttachment-</xsl:text>
  308. <xsl:for-each select='$rnd:pages-tables'>
  309. <xsl:if test='generate-id() = generate-id($this)'>
  310. <xsl:value-of select='position()'/>
  311. </xsl:if>
  312. </xsl:for-each>
  313. </xsl:attribute>
  314. </sf:attachment-ref>
  315. <sf:br/>
  316. </sf:p>
  317. </xsl:template>
  318. <xsl:template name='doc:make-column'>
  319. <xsl:param name='width' select='0'/>
  320. </xsl:template>
  321. <xsl:template name='doc:make-table-row'>
  322. <xsl:param name='content'>
  323. <xsl:apply-templates mode='doc:body'/>
  324. </xsl:param>
  325. <xsl:param name='is-header' select='false()'/>
  326. </xsl:template>
  327. <xsl:template name='doc:make-table-cell'>
  328. <xsl:param name='width' select='0'/>
  329. <xsl:param name='hidden' select='false()'/>
  330. <xsl:param name='rowspan' select='1'/>
  331. <xsl:param name='colspan' select='1'/>
  332. <xsl:param name='content'>
  333. <xsl:apply-templates mode='doc:body'/>
  334. </xsl:param>
  335. </xsl:template>
  336. <xsl:template name='doc:make-soft-break'>
  337. <sf:br/>
  338. </xsl:template>
  339. <xsl:template name='attributes'>
  340. <xsl:param name='node' select='.'/>
  341. <xsl:for-each select='$node/@*'>
  342. <sf:span>
  343. <xsl:attribute name='sf:style'>
  344. <xsl:call-template name='doc:lookup-character-style'>
  345. <xsl:with-param name='style'>attribute-name</xsl:with-param>
  346. </xsl:call-template>
  347. </xsl:attribute>
  348. <xsl:value-of select='name()'/>
  349. </sf:span>
  350. <sf:span>
  351. <xsl:attribute name='sf:style'>
  352. <xsl:call-template name='doc:lookup-character-style'>
  353. <xsl:with-param name='style'>attribute-value</xsl:with-param>
  354. </xsl:call-template>
  355. </xsl:attribute>
  356. <xsl:value-of select='.'/>
  357. </sf:span>
  358. </xsl:for-each>
  359. </xsl:template>
  360. <xsl:template name='doc:lookup-paragraph-style'>
  361. <xsl:param name='style'/>
  362. <xsl:variable name='style.cooked'>
  363. <xsl:choose>
  364. <xsl:when test='$style = "Normal"'>para</xsl:when>
  365. <xsl:otherwise>
  366. <xsl:value-of select='$style'/>
  367. </xsl:otherwise>
  368. </xsl:choose>
  369. </xsl:variable>
  370. <xsl:if test='not($paragraph-styles[@sf:name = $style.cooked])'>
  371. <xsl:message>unable to find paragraph style "<xsl:value-of select='$style.cooked'/>"</xsl:message>
  372. </xsl:if>
  373. <xsl:value-of select='$paragraph-styles[@sf:name = $style.cooked]/@sf:ident'/>
  374. </xsl:template>
  375. <xsl:template name='doc:lookup-character-style'>
  376. <xsl:param name='style'/>
  377. <xsl:if test='not($character-styles[@sf:name = $style])'>
  378. <xsl:message>unable to find character style "<xsl:value-of select='$style'/>"</xsl:message>
  379. </xsl:if>
  380. <xsl:value-of select='$character-styles[@sf:name = $style]/@sf:ident'/>
  381. </xsl:template>
  382. </xsl:stylesheet>