blocks2dbk.xsl 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  1. <!DOCTYPE xsl:stylesheet [
  2. <!-- External DTD defines entities:
  3. components :- QNames of component-level elements
  4. blocks :- QNames of block-level elements
  5. metadata-content :- XPath expression matching metadata styles
  6. author-content :- XPath expression matching author styles
  7. admonition :- XPath expression matching admonition styles
  8. admonition-title :- XPath expression matching admonition title styles
  9. -->
  10. <!ENTITY % ext SYSTEM "blocks2dbk.dtd">
  11. %ext;
  12. ]>
  13. <xsl:stylesheet version="1.0"
  14. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  15. xmlns:dbk='http://docbook.org/ns/docbook'
  16. xmlns:rnd='http://docbook.org/ns/docbook/roundtrip'
  17. xmlns:xlink='http://www.w3.org/1999/xlink'>
  18. <!-- $Id: blocks2dbk.xsl 8137 2008-10-09 03:37:56Z balls $ -->
  19. <!-- Stylesheet to convert word processing docs to DocBook -->
  20. <!-- This stylesheet processes the output of sections2blocks.xsl -->
  21. <xsl:output indent="yes" method="xml"
  22. cdata-section-elements='dbk:programlisting dbk:literallayout'/>
  23. <!-- ================================================== -->
  24. <!-- Parameters -->
  25. <!-- ================================================== -->
  26. <xsl:param name='docbook5'>0</xsl:param>
  27. <xsl:param name="nest.sections">1</xsl:param>
  28. <xsl:strip-space elements='*'/>
  29. <xsl:preserve-space elements='dbk:para dbk:emphasis'/>
  30. <xsl:template match="&components; |
  31. &blocks;">
  32. <xsl:choose>
  33. <xsl:when test='self::dbk:article and
  34. count(dbk:book) = 1 and
  35. count(dbk:info|dbk:book) &lt;= 2'>
  36. <xsl:apply-templates select='dbk:book'/>
  37. </xsl:when>
  38. <xsl:when test='self::dbk:article and
  39. *[1][self::dbk:para] and
  40. *[1]/@rnd:style != "article-title" and
  41. contains(*[1]/@rnd:style, "-title")'>
  42. <xsl:variable name='element-name'
  43. select='substring-before(*[1]/@rnd:style, "-title")'/>
  44. <xsl:element name='{$element-name}'
  45. namespace='http://docbook.org/ns/docbook'>
  46. <dbk:info>
  47. <xsl:apply-templates select='*[1]'
  48. mode='rnd:metadata'/>
  49. </dbk:info>
  50. <xsl:apply-templates/>
  51. </xsl:element>
  52. </xsl:when>
  53. <xsl:otherwise>
  54. <xsl:copy>
  55. <xsl:call-template name='rnd:attributes'/>
  56. <xsl:variable name='metadata'>
  57. <xsl:apply-templates select='*[1]'
  58. mode='rnd:metadata'/>
  59. </xsl:variable>
  60. <xsl:if test='$metadata'>
  61. <dbk:info>
  62. <xsl:copy-of select='$metadata'/>
  63. </dbk:info>
  64. </xsl:if>
  65. <xsl:apply-templates/>
  66. </xsl:copy>
  67. </xsl:otherwise>
  68. </xsl:choose>
  69. </xsl:template>
  70. <xsl:template match='dbk:book-component'>
  71. <xsl:variable name='element-name'
  72. select='substring-before(*[1]/@rnd:style, "-title")'/>
  73. <xsl:element name='{$element-name}'
  74. namespace='http://docbook.org/ns/docbook'>
  75. <dbk:info>
  76. <xsl:apply-templates select='*[1]'
  77. mode='rnd:metadata'/>
  78. </dbk:info>
  79. <xsl:apply-templates/>
  80. </xsl:element>
  81. </xsl:template>
  82. <xsl:template match="dbk:para" name='rnd:para'>
  83. <!-- Some elements are normally suppressed,
  84. since they are processed in a different context.
  85. If this parameter is false then the element will be processed normally.
  86. -->
  87. <xsl:param name='suppress' select='true()'/>
  88. <!-- This paragraph may be in a sidebar -->
  89. <xsl:variable name='sidebar'
  90. select='preceding-sibling::*[self::dbk:para and @rnd:style = "sidebar-title"][1]'/>
  91. <!-- This paragraph may be in the textobject of a table or figure -->
  92. <xsl:variable name='table'
  93. select='preceding-sibling::dbk:informaltable[1]'/>
  94. <xsl:variable name='figure'
  95. select='preceding-sibling::dbk:para[@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")][1]'/>
  96. <xsl:variable name='caption'
  97. select='following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"]'/>
  98. <xsl:choose>
  99. <!-- continue style paragraphs are handled in context -->
  100. <xsl:when test='$suppress and
  101. @rnd:style = "para-continue"'/>
  102. <!-- Certain elements gather the following paragraph -->
  103. <xsl:when test='$suppress and
  104. preceding-sibling::*[1][self::dbk:para and
  105. @rnd:style = "example-title"]'/>
  106. <xsl:when test='$suppress and
  107. $sidebar and
  108. not(preceding-sibling::dbk:para[(not(@rnd:style) or @rnd:style = "") and
  109. preceding-sibling::*[preceding-sibling::*[generate-id() = generate-id($sidebar)]]])'/>
  110. <!-- Separate processing is performed for table/figure titles and captions -->
  111. <xsl:when test='$suppress and
  112. @rnd:style = "table-title" and
  113. following-sibling::*[1][self::dbk:informaltable|self::dbk:para[@rnd:style = "informalfigure-imagedata"]|self::dbk:para[dbk:inlinemediaobject and count(*) = 1 and normalize-space() = ""]]'/>
  114. <xsl:when test='$suppress and
  115. @rnd:style = "figure-title" and
  116. following-sibling::*[1][self::dbk:para][@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")]'/>
  117. <xsl:when test='$suppress and
  118. (@rnd:style = "caption" or @rnd:style = "Caption") and
  119. (preceding-sibling::*[self::dbk:informaltable] or
  120. preceding-sibling::*[self::dbk:para][@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")])'/>
  121. <xsl:when test='$suppress and
  122. $table and
  123. $caption and
  124. generate-id($caption/preceding-sibling::dbk:informaltable[1]) = generate-id($table)'/>
  125. <xsl:when test='$suppress and
  126. $figure and
  127. $caption and
  128. generate-id($caption/preceding-sibling::dbk:para[@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")][1]) = generate-id($figure)'/>
  129. <xsl:when test='@rnd:style = "imagedata-metadata" or
  130. @rnd:style = "table-metadata"'/>
  131. <!-- Ignore empty paragraphs -->
  132. <xsl:when test='(not(@rnd:style) or
  133. @rnd:style = "") and
  134. normalize-space(.) = "" and
  135. not(*)'/>
  136. <!-- Image inline or block? -->
  137. <xsl:when test='(not(@rnd:style) or
  138. @rnd:style = "") and
  139. normalize-space(.) = "" and
  140. count(*) = 1 and
  141. dbk:inlinemediaobject'>
  142. <xsl:apply-templates/>
  143. </xsl:when>
  144. <xsl:when test='not(@rnd:style) or
  145. @rnd:style = "" or
  146. @rnd:style = "para-continue"'>
  147. <dbk:para>
  148. <xsl:call-template name='rnd:attributes'/>
  149. <xsl:apply-templates/>
  150. </dbk:para>
  151. </xsl:when>
  152. <xsl:when test='@rnd:style = "xinclude"'
  153. xmlns:xi='http://www.w3.org/2001/XInclude'>
  154. <xi:include>
  155. <xsl:attribute name='href'>
  156. <xsl:apply-templates mode='rnd:xinclude'/>
  157. </xsl:attribute>
  158. </xi:include>
  159. </xsl:when>
  160. <xsl:when test='$suppress and
  161. preceding-sibling::*[1]/self::dbk:para[&admonition-title;]'/>
  162. <xsl:when test='&admonition-title;'>
  163. <xsl:element name='{substring-before(@rnd:style, "-title")}'
  164. namespace='http://docbook.org/ns/docbook'>
  165. <xsl:call-template name='rnd:attributes'/>
  166. <dbk:title>
  167. <xsl:apply-templates/>
  168. </dbk:title>
  169. <xsl:apply-templates select='following-sibling::*[1]'>
  170. <xsl:with-param name='suppress' select='false()'/>
  171. </xsl:apply-templates>
  172. <xsl:apply-templates select='following-sibling::*[2]'
  173. mode='rnd:continue'/>
  174. </xsl:element>
  175. </xsl:when>
  176. <xsl:when test='starts-with(@rnd:style, "itemizedlist") or
  177. starts-with(@rnd:style, "orderedlist")'>
  178. <xsl:variable name='stop.node'
  179. select='following-sibling::dbk:para[not(@rnd:style) or
  180. (not(starts-with(@rnd:style, "itemizedlist") or starts-with(@rnd:style, "orderedlist")) and @rnd:style != "para-continue")][1]'/>
  181. <xsl:choose>
  182. <xsl:when test='translate(substring-after(@rnd:style, "list"), "0123456789", "") != "" or
  183. substring-after(@rnd:style, "list") = ""'>
  184. <xsl:call-template name='rnd:error'>
  185. <xsl:with-param name='code' select='"list-bad-level"'/>
  186. <xsl:with-param name='message'>style "<xsl:value-of select='@rnd:style'/>" is not a valid list style</xsl:with-param>
  187. </xsl:call-template>
  188. </xsl:when>
  189. <!-- TODO: the previous para-continue may not be associated with a list -->
  190. <!-- NB. Look back at the previous paragraph. There may be intervening tables or images. -->
  191. <xsl:when test='preceding-sibling::dbk:para[1][starts-with(@rnd:style, "itemizedlist") or starts-with(@rnd:style, "orderedlist") or @rnd:style = "para-continue"]'/>
  192. <xsl:when test='substring-after(@rnd:style, "list") != 1'>
  193. <xsl:call-template name='rnd:error'>
  194. <xsl:with-param name='code'>list-wrong-level</xsl:with-param>
  195. <xsl:with-param name='message'>list started at the wrong level</xsl:with-param>
  196. </xsl:call-template>
  197. </xsl:when>
  198. <xsl:when test='$stop.node'>
  199. <xsl:element name='{substring-before(@rnd:style, "1")}'
  200. namespace='http://docbook.org/ns/docbook'>
  201. <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = current()/@rnd:style][following-sibling::*[generate-id() = generate-id($stop.node)]]'
  202. mode='rnd:listitem'/>
  203. </xsl:element>
  204. </xsl:when>
  205. <xsl:otherwise>
  206. <xsl:element name='{substring-before(@rnd:style, "1")}'
  207. namespace='http://docbook.org/ns/docbook'>
  208. <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = current()/@rnd:style]'
  209. mode='rnd:listitem'/>
  210. </xsl:element>
  211. </xsl:otherwise>
  212. </xsl:choose>
  213. </xsl:when>
  214. <xsl:when test='@rnd:style = "programlisting" and
  215. preceding-sibling::*[1][self::dbk:para and @rnd:style = "programlisting"]'/>
  216. <xsl:when test='@rnd:style = "literallayout" and
  217. preceding-sibling::*[1][self::dbk:para and @rnd:style = "literallayout"]'/>
  218. <xsl:when test='@rnd:style = "programlisting" or
  219. @rnd:style = "literallayout"'>
  220. <xsl:variable name='stop.node'
  221. select='following-sibling::dbk:para[@rnd:style != current()/@rnd:style][1]'/>
  222. <xsl:element name='{@rnd:style}'
  223. namespace='http://docbook.org/ns/docbook'>
  224. <xsl:apply-templates/>
  225. <xsl:choose>
  226. <xsl:when test='$stop.node'>
  227. <xsl:apply-templates select='following-sibling::dbk:para[following-sibling::*[generate-id() = generate-id($stop.node)]]'
  228. mode='rnd:programlisting'/>
  229. </xsl:when>
  230. <xsl:otherwise>
  231. <xsl:apply-templates select='following-sibling::dbk:para'
  232. mode='rnd:programlisting'/>
  233. </xsl:otherwise>
  234. </xsl:choose>
  235. </xsl:element>
  236. </xsl:when>
  237. <xsl:when test='@rnd:style = "example-title"'>
  238. <xsl:element name='{substring-before(@rnd:style, "-title")}'
  239. namespace='http://docbook.org/ns/docbook'>
  240. <xsl:call-template name='rnd:attributes'/>
  241. <dbk:title>
  242. <xsl:apply-templates/>
  243. </dbk:title>
  244. <xsl:apply-templates select='following-sibling::*[1]'>
  245. <xsl:with-param name='suppress' select='false()'/>
  246. </xsl:apply-templates>
  247. </xsl:element>
  248. </xsl:when>
  249. <xsl:when test='@rnd:style = "sidebar-title"'>
  250. <!-- TODO: next sidebar should stop this sidebar -->
  251. <xsl:variable name='stop.node'
  252. select='following-sibling::dbk:para[(not(@rnd:style) or @rnd:style = "") and
  253. normalize-space(.) = ""][1]'/>
  254. <dbk:sidebar>
  255. <xsl:call-template name='rnd:attributes'/>
  256. <dbk:info>
  257. <dbk:title>
  258. <xsl:apply-templates/>
  259. </dbk:title>
  260. </dbk:info>
  261. <xsl:choose>
  262. <xsl:when test='$stop.node'>
  263. <xsl:apply-templates select='following-sibling::*[following-sibling::*[generate-id() = generate-id($stop.node)]]'
  264. mode='rnd:sidebar'/>
  265. </xsl:when>
  266. <xsl:otherwise>
  267. <xsl:apply-templates select='following-sibling::*'
  268. mode='rnd:sidebar'/>
  269. </xsl:otherwise>
  270. </xsl:choose>
  271. </dbk:sidebar>
  272. </xsl:when>
  273. <xsl:when test='&admonition;'>
  274. <xsl:element name='{@rnd:style}'
  275. namespace='http://docbook.org/ns/docbook'>
  276. <xsl:call-template name='rnd:attributes'/>
  277. <dbk:para>
  278. <xsl:apply-templates/>
  279. </dbk:para>
  280. <xsl:apply-templates select='following-sibling::*[1]'
  281. mode='rnd:continue'/>
  282. </xsl:element>
  283. </xsl:when>
  284. <!-- TODO: make sure this is in a bibliography.
  285. If not, create a bibliolist.
  286. -->
  287. <xsl:when test='@rnd:style = "bibliomixed"'>
  288. <dbk:bibliomixed>
  289. <xsl:call-template name='rnd:attributes'/>
  290. <xsl:apply-templates/>
  291. </dbk:bibliomixed>
  292. </xsl:when>
  293. <xsl:when test='@rnd:style = "biblioentry-title"'>
  294. <dbk:biblioentry>
  295. <xsl:call-template name='rnd:attributes'/>
  296. <dbk:title>
  297. <xsl:apply-templates/>
  298. </dbk:title>
  299. <xsl:if test='following-sibling::*[1][&metadata-content;]'>
  300. <xsl:apply-templates select='following-sibling::*[1]'
  301. mode='rnd:metadata'/>
  302. </xsl:if>
  303. </dbk:biblioentry>
  304. </xsl:when>
  305. <xsl:when test='@rnd:style = "blockquote-attribution" and
  306. preceding-sibling::*[1][self::dbk:para][@rnd:style = "blockquote-title" or @rnd:style = "blockquote"]'/>
  307. <xsl:when test='@rnd:style = "blockquote-attribution"'>
  308. <xsl:call-template name='rnd:error'>
  309. <xsl:with-param name='code'>improper-blockquote-attribution</xsl:with-param>
  310. <xsl:with-param name='message'>blockquote attribution must follow a blockquote title</xsl:with-param>
  311. </xsl:call-template>
  312. </xsl:when>
  313. <xsl:when test='@rnd:style = "blockquote" or
  314. @rnd:style = "blockquote-title"'>
  315. <xsl:choose>
  316. <xsl:when test='@rnd:style = "blockquote" and
  317. preceding-sibling::*[1][self::dbk:para][starts-with(@rnd:style, "blockquote")]'/>
  318. <xsl:otherwise>
  319. <xsl:variable name='stop.node'
  320. select='following-sibling::*[not(@rnd:style = "blockquote" or
  321. @rnd:style = "blockquote-attribution")][1]'/>
  322. <dbk:blockquote>
  323. <xsl:call-template name='rnd:attributes'/>
  324. <xsl:if test='@rnd:style = "blockquote-title"'>
  325. <dbk:info>
  326. <dbk:title>
  327. <xsl:apply-templates/>
  328. </dbk:title>
  329. </dbk:info>
  330. </xsl:if>
  331. <xsl:choose>
  332. <xsl:when test='$stop.node'>
  333. <xsl:apply-templates select='following-sibling::*[following-sibling::*[generate-id() = generate-id($stop.node)]][@rnd:style = "blockquote-attribution"]' mode='rnd:blockquote-attribution'/>
  334. <xsl:apply-templates select='self::*[@rnd:style = "blockquote"] |
  335. following-sibling::*[following-sibling::*[generate-id() = generate-id($stop.node)]]'
  336. mode='rnd:blockquote'/>
  337. </xsl:when>
  338. <xsl:otherwise>
  339. <xsl:apply-templates select='following-sibling::*[@rnd:style = "blockquote-attribution"]' mode='rnd:blockquote-attribution'/>
  340. <xsl:apply-templates select='self::*[@rnd:style = "blockquote"] |
  341. following-sibling::*'
  342. mode='rnd:blockquote'/>
  343. </xsl:otherwise>
  344. </xsl:choose>
  345. </dbk:blockquote>
  346. </xsl:otherwise>
  347. </xsl:choose>
  348. </xsl:when>
  349. <xsl:when test='@rnd:style = "bridgehead"'>
  350. <xsl:element name='{@rnd:style}'
  351. namespace='http://docbook.org/ns/docbook'>
  352. <xsl:call-template name='rnd:attributes'/>
  353. <xsl:apply-templates/>
  354. </xsl:element>
  355. </xsl:when>
  356. <xsl:when test='@rnd:style = "formalpara-title"'>
  357. <dbk:formalpara>
  358. <dbk:title>
  359. <xsl:call-template name='rnd:attributes'/>
  360. <xsl:apply-templates/>
  361. </dbk:title>
  362. <xsl:choose>
  363. <xsl:when test='following-sibling::*[1][self::dbk:para][@rnd:style = "formalpara"]'>
  364. <dbk:para>
  365. <xsl:call-template name='rnd:attributes'>
  366. <xsl:with-param name='node'
  367. select='following-sibling::*[1]'/>
  368. </xsl:call-template>
  369. <xsl:apply-templates select='following-sibling::*[1]/node()'/>
  370. </dbk:para>
  371. </xsl:when>
  372. </xsl:choose>
  373. </dbk:formalpara>
  374. </xsl:when>
  375. <xsl:when test='@rnd:style = "formalpara" and
  376. preceding-sibling::*[1][self::dbk:para][@rnd:style = "formalpara-title"]'/>
  377. <xsl:when test='@rnd:style = "formalpara"'>
  378. <xsl:call-template name='rnd:error'>
  379. <xsl:with-param name='code'>formalpara-notitle</xsl:with-param>
  380. <xsl:with-param name='message'>formalpara used without a title</xsl:with-param>
  381. </xsl:call-template>
  382. </xsl:when>
  383. <xsl:when test='@rnd:style = "informalfigure-imagedata"'>
  384. <xsl:variable name='caption.next'
  385. select='following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"][1]'/>
  386. <xsl:variable name='metadata'
  387. select='preceding-sibling::*[1][self::dbk:para][@rnd:style = "imagedata-metadata"]'/>
  388. <xsl:choose>
  389. <xsl:when test='preceding-sibling::*[1][self::dbk:para][@rnd:style = "figure-title"] or
  390. ($metadata and preceding-sibling::*[2][self::dbk:para][@rnd:style = "figure-title"])'>
  391. <dbk:figure>
  392. <xsl:call-template name='rnd:attributes'/>
  393. <dbk:info>
  394. <dbk:title>
  395. <xsl:choose>
  396. <xsl:when test='$metadata'>
  397. <xsl:apply-templates
  398. select='preceding-sibling::*[2]/node()'/>
  399. </xsl:when>
  400. <xsl:otherwise>
  401. <xsl:apply-templates
  402. select='preceding-sibling::*[1]/node()'/>
  403. </xsl:otherwise>
  404. </xsl:choose>
  405. </dbk:title>
  406. </dbk:info>
  407. <dbk:mediaobject>
  408. <dbk:imageobject>
  409. <dbk:imagedata>
  410. <xsl:attribute name='fileref'>
  411. <xsl:choose>
  412. <xsl:when test='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref != ""'>
  413. <xsl:value-of select='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref'/>
  414. </xsl:when>
  415. <xsl:otherwise>
  416. <xsl:value-of select='.'/>
  417. </xsl:otherwise>
  418. </xsl:choose>
  419. </xsl:attribute>
  420. <xsl:call-template name='rnd:imagedata-attributes'>
  421. <xsl:with-param name='metadata' select='$metadata'/>
  422. </xsl:call-template>
  423. </dbk:imagedata>
  424. </dbk:imageobject>
  425. </dbk:mediaobject>
  426. <xsl:call-template name='rnd:figure-text-caption'>
  427. <xsl:with-param name='caption' select='$caption.next'/>
  428. </xsl:call-template>
  429. </dbk:figure>
  430. </xsl:when>
  431. <xsl:when test='preceding-sibling::*[1][self::dbk:para][@rnd:style = "table-title"] or
  432. ($metadata and preceding-sibling::*[2][self::dbk:para][@rnd:style = "table-title"])'>
  433. <dbk:table>
  434. <xsl:call-template name='rnd:attributes'/>
  435. <dbk:info>
  436. <dbk:title>
  437. <xsl:choose>
  438. <xsl:when test='$metadata'>
  439. <xsl:apply-templates
  440. select='preceding-sibling::*[2]/node()'/>
  441. </xsl:when>
  442. <xsl:otherwise>
  443. <xsl:apply-templates
  444. select='preceding-sibling::*[1]/node()'/>
  445. </xsl:otherwise>
  446. </xsl:choose>
  447. </dbk:title>
  448. </dbk:info>
  449. <dbk:mediaobject>
  450. <dbk:imageobject>
  451. <dbk:imagedata>
  452. <xsl:attribute name='fileref'>
  453. <xsl:choose>
  454. <xsl:when test='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref != ""'>
  455. <xsl:value-of select='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref'/>
  456. </xsl:when>
  457. <xsl:otherwise>
  458. <xsl:value-of select='.'/>
  459. </xsl:otherwise>
  460. </xsl:choose>
  461. </xsl:attribute>
  462. <xsl:call-template name='rnd:imagedata-attributes'>
  463. <xsl:with-param name='metadata' select='$metadata'/>
  464. </xsl:call-template>
  465. </dbk:imagedata>
  466. </dbk:imageobject>
  467. </dbk:mediaobject>
  468. <xsl:call-template name='rnd:figure-text-caption'>
  469. <xsl:with-param name='caption' select='$caption.next'/>
  470. </xsl:call-template>
  471. </dbk:table>
  472. </xsl:when>
  473. <xsl:otherwise>
  474. <dbk:informalfigure>
  475. <xsl:call-template name='rnd:attributes'/>
  476. <dbk:mediaobject>
  477. <dbk:imageobject>
  478. <dbk:imagedata>
  479. <xsl:attribute name='fileref'>
  480. <xsl:choose>
  481. <xsl:when test='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref != ""'>
  482. <xsl:value-of select='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref'/>
  483. </xsl:when>
  484. <xsl:otherwise>
  485. <xsl:value-of select='.'/>
  486. </xsl:otherwise>
  487. </xsl:choose>
  488. </xsl:attribute>
  489. <xsl:call-template name='rnd:imagedata-attributes'>
  490. <xsl:with-param name='metadata' select='$metadata'/>
  491. </xsl:call-template>
  492. </dbk:imagedata>
  493. </dbk:imageobject>
  494. </dbk:mediaobject>
  495. <xsl:call-template name='rnd:figure-text-caption'>
  496. <xsl:with-param name='caption' select='$caption.next'/>
  497. </xsl:call-template>
  498. </dbk:informalfigure>
  499. </xsl:otherwise>
  500. </xsl:choose>
  501. </xsl:when>
  502. <xsl:when test='(@rnd:style = "caption" or @rnd:style = "Caption") and
  503. preceding-sibling::*[(self::dbk:para and contains(@rnd:style, "imagedata")) or self::dbk:informaltable]'/>
  504. <xsl:when test='@rnd:style = "caption" or @rnd:style = "Caption"'>
  505. <xsl:call-template name='rnd:error'>
  506. <xsl:with-param name='code'>bad-caption</xsl:with-param>
  507. <xsl:with-param name='message'>caption does not follow table or figure</xsl:with-param>
  508. </xsl:call-template>
  509. </xsl:when>
  510. <xsl:when test='(contains(@rnd:style, "-title") or
  511. contains(@rnd:style, "-titleabbrev") or
  512. contains(@rnd:style, "-subtitle")) and
  513. not(starts-with(@rnd:style, "blockquote") or starts-with(@rnd:style, "formal"))'>
  514. <!-- TODO: check that no non-metadata elements occur before this paragraph -->
  515. </xsl:when>
  516. <!-- Metadata elements are handled in rnd:metadata mode -->
  517. <!-- TODO: check that no non-metadata elements occur before this paragraph -->
  518. <xsl:when test='&metadata-content;'/>
  519. <xsl:otherwise>
  520. <xsl:call-template name='rnd:error'>
  521. <xsl:with-param name='code'>unknown-style</xsl:with-param>
  522. <xsl:with-param name='message'>unknown paragraph style "<xsl:value-of select='@rnd:style'/>" encountered</xsl:with-param>
  523. </xsl:call-template>
  524. </xsl:otherwise>
  525. </xsl:choose>
  526. </xsl:template>
  527. <!-- Determine if the caption belongs to the current figure.
  528. If so, then process the textobject content and the caption.
  529. -->
  530. <xsl:template name='rnd:figure-text-caption'>
  531. <xsl:param name='caption' select='/..'/>
  532. <xsl:variable name='textobjs'
  533. select='following-sibling::*[following-sibling::*[generate-id() = generate-id($caption)]]'/>
  534. <xsl:choose>
  535. <xsl:when test='not($caption)'/> <!-- nothing to do -->
  536. <xsl:when test='$textobjs[self::dbk:informaltable |
  537. self::dbk:inlinemediaobject |
  538. self::dbk:para[@rnd:style = "informalfigure-imagedata" or
  539. @rnd:style = "mediaobject-imagedata"]]'/> <!-- caption belongs to something else -->
  540. <xsl:otherwise>
  541. <xsl:apply-templates select='$textobjs' mode='rnd:textobject'/>
  542. <xsl:apply-templates select='$caption' mode='rnd:caption'/>
  543. </xsl:otherwise>
  544. </xsl:choose>
  545. </xsl:template>
  546. <xsl:template match='dbk:para' mode='rnd:caption'>
  547. <dbk:caption>
  548. <xsl:call-template name='rnd:attributes'/>
  549. <xsl:apply-templates/>
  550. </dbk:caption>
  551. </xsl:template>
  552. <xsl:template name='rnd:imagedata-attributes'>
  553. <xsl:param name='metadata' select='""'/>
  554. <xsl:choose>
  555. <xsl:when test='not($metadata)'/>
  556. <xsl:when test='contains($metadata, " ")'>
  557. <xsl:call-template name='rnd:imagedata-attributes'>
  558. <xsl:with-param name='metadata'
  559. select='substring-before($metadata, " ")'/>
  560. </xsl:call-template>
  561. <xsl:call-template name='rnd:imagedata-attributes'>
  562. <xsl:with-param name='metadata'
  563. select='substring-after($metadata, " ")'/>
  564. </xsl:call-template>
  565. </xsl:when>
  566. <xsl:when test='not(contains($metadata, "="))'>
  567. <xsl:call-template name='rnd:warning'>
  568. <xsl:with-param name='code' select='"imagedata-missing-value"'/>
  569. <xsl:with-param name='message'>
  570. <xsl:text>imagedata-metadata missing value for attribute "</xsl:text>
  571. <xsl:value-of select='$metadata'/>
  572. <xsl:text>"</xsl:text>
  573. </xsl:with-param>
  574. </xsl:call-template>
  575. </xsl:when>
  576. <xsl:otherwise>
  577. <xsl:variable name='name'
  578. select='translate(normalize-space(substring-before($metadata, "=")), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")'/>
  579. <xsl:variable name='value'
  580. select='translate(normalize-space(substring-after($metadata, "=")), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")'/>
  581. <xsl:choose>
  582. <xsl:when test='$name = "scalefit"'>
  583. <xsl:attribute name='scalefit'>
  584. <xsl:choose>
  585. <xsl:when test='$value = "1" or
  586. $value = "yes" or
  587. $value = "true"'>1</xsl:when>
  588. <xsl:otherwise>0</xsl:otherwise>
  589. </xsl:choose>
  590. </xsl:attribute>
  591. </xsl:when>
  592. <xsl:when test='$name = "align" or
  593. $name = "contentdepth" or
  594. $name = "contentwidth" or
  595. $name = "depth" or
  596. $name = "scale" or
  597. $name = "valign" or
  598. $name = "width"'>
  599. <!-- TODO: check enumerate values-->
  600. <xsl:attribute name='{$name}'>
  601. <xsl:value-of select='$value'/>
  602. </xsl:attribute>
  603. </xsl:when>
  604. <xsl:otherwise>
  605. <xsl:call-template name='rnd:error'>
  606. <xsl:with-param name='code' select='"imagedata-unknown-attribute"'/>
  607. <xsl:with-param name='message'>
  608. <xsl:text>imagedata-metadata unknown attribute "</xsl:text>
  609. <xsl:value-of select='$name'/>
  610. <xsl:text>"</xsl:text>
  611. </xsl:with-param>
  612. </xsl:call-template>
  613. </xsl:otherwise>
  614. </xsl:choose>
  615. </xsl:otherwise>
  616. </xsl:choose>
  617. </xsl:template>
  618. <xsl:template match='dbk:emphasis'>
  619. <xsl:choose>
  620. <xsl:when test='not(@rnd:style) and @role = "italic"'>
  621. <xsl:copy>
  622. <xsl:apply-templates mode='rnd:copy'/>
  623. </xsl:copy>
  624. </xsl:when>
  625. <xsl:when test='not(@rnd:style) or @role'>
  626. <xsl:copy>
  627. <xsl:call-template name='rnd:attributes'/>
  628. <xsl:apply-templates mode='rnd:copy'/>
  629. </xsl:copy>
  630. </xsl:when>
  631. <xsl:when test='@rnd:style = preceding-sibling::node()[1][self::dbk:emphasis]/@rnd:style'/>
  632. <xsl:when test='@rnd:style = "emphasis"'>
  633. <xsl:copy>
  634. <xsl:call-template name='rnd:attributes'/>
  635. <xsl:apply-templates mode='rnd:copy'/>
  636. <xsl:apply-templates select='following-sibling::node()[1]'
  637. mode='rnd:emphasis'/>
  638. </xsl:copy>
  639. </xsl:when>
  640. <xsl:when test='@rnd:style = "emphasis-bold" or
  641. @rnd:style = "emphasis-strong"'>
  642. <xsl:copy>
  643. <xsl:attribute name='role'>bold</xsl:attribute>
  644. <xsl:call-template name='rnd:attributes'/>
  645. <xsl:apply-templates mode='rnd:copy'/>
  646. <xsl:apply-templates select='following-sibling::node()[1]'
  647. mode='rnd:emphasis'/>
  648. </xsl:copy>
  649. </xsl:when>
  650. <xsl:when test='@rnd:style = "emphasis-underline"'>
  651. <xsl:copy>
  652. <xsl:attribute name='role'>underline</xsl:attribute>
  653. <xsl:call-template name='rnd:attributes'/>
  654. <xsl:apply-templates mode='rnd:copy'/>
  655. <xsl:apply-templates select='following-sibling::node()[1]'
  656. mode='rnd:emphasis'/>
  657. </xsl:copy>
  658. </xsl:when>
  659. <xsl:when test='@rnd:style = "citetitle" or
  660. @rnd:style = "literal" or
  661. @rnd:style = "sgmltag"'>
  662. <xsl:element name='{@rnd:style}'
  663. namespace='http://docbook.org/ns/docbook'>
  664. <xsl:call-template name='rnd:attributes'/>
  665. <xsl:apply-templates/>
  666. <xsl:apply-templates select='following-sibling::node()[1]'
  667. mode='rnd:emphasis'/>
  668. </xsl:element>
  669. </xsl:when>
  670. <xsl:when test='@rnd:style = "Hyperlink" and
  671. parent::dbk:link'>
  672. <!-- This occurs in a hyperlink; parent should be dbk:link -->
  673. <xsl:apply-templates/>
  674. </xsl:when>
  675. <xsl:when test='@rnd:style = "Hyperlink"'>
  676. <!-- dbk:link is missing -->
  677. <dbk:link xlink:href='{.}'>
  678. <xsl:apply-templates/>
  679. </dbk:link>
  680. </xsl:when>
  681. <!-- In rare circumstances, Word inserts an empty element that appears to be something like a space in the editor -->
  682. <xsl:when test='(@rnd:style = "EndnoteReference" or
  683. @rnd:style = "FootnoteReference") and
  684. . = ""'>
  685. <xsl:text> </xsl:text>
  686. </xsl:when>
  687. <xsl:otherwise>
  688. <xsl:call-template name='rnd:error'>
  689. <xsl:with-param name='code'>unknown-style</xsl:with-param>
  690. <xsl:with-param name='message'>unknown character span style "<xsl:value-of select='@rnd:style'/>" encountered</xsl:with-param>
  691. </xsl:call-template>
  692. </xsl:otherwise>
  693. </xsl:choose>
  694. </xsl:template>
  695. <!-- Coalesce emphasis elements into a single element -->
  696. <xsl:template match='dbk:emphasis' mode='rnd:emphasis'>
  697. <xsl:choose>
  698. <xsl:when test='@rnd:style = preceding-sibling::node()[self::dbk:emphasis]/@rnd:style'>
  699. <xsl:apply-templates/>
  700. <xsl:apply-templates select='following-sibling::node()[1]'
  701. mode='rnd:emphasis'/>
  702. </xsl:when>
  703. </xsl:choose>
  704. </xsl:template>
  705. <xsl:template match='*|text()' mode='rnd:emphasis'/>
  706. <xsl:template match='dbk:emphasis' mode='rnd:personname-emphasis'>
  707. <xsl:param name='style'/>
  708. <xsl:choose>
  709. <xsl:when test='@rnd:style = $style'>
  710. <xsl:apply-templates/>
  711. <xsl:apply-templates select='following-sibling::dbk:emphasis[1]'
  712. mode='rnd:personname-emphasis'>
  713. <xsl:with-param name='style' select='$style'/>
  714. </xsl:apply-templates>
  715. </xsl:when>
  716. </xsl:choose>
  717. </xsl:template>
  718. <xsl:template match='*|text()' mode='rnd:emphasis'/>
  719. <xsl:template match='dbk:subscript|dbk:superscript'>
  720. <xsl:copy>
  721. <xsl:apply-templates select='@*' mode='rnd:copy'/>
  722. <xsl:apply-templates/>
  723. </xsl:copy>
  724. </xsl:template>
  725. <!-- Images -->
  726. <xsl:template match='dbk:inlinemediaobject'>
  727. <xsl:choose>
  728. <xsl:when test='not(preceding-sibling::*|following-sibling::*) and
  729. normalize-space(..) = ""'>
  730. <xsl:variable name='next.captioned'
  731. select='ancestor::dbk:para/following-sibling::*[self::dbk:informaltable or self::dbk:para[dbk:inlinemediaobject and count(*) = 1 and normalize-space() = ""]][1]'/>
  732. <xsl:variable name='caption'
  733. select='ancestor::dbk:para/following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"]'/>
  734. <xsl:variable name='metadata'>
  735. <xsl:apply-templates select='ancestor::dbk:para/following-sibling::*[1]'
  736. mode='rnd:metadata'/>
  737. </xsl:variable>
  738. <dbk:figure>
  739. <xsl:if test='ancestor::dbk:para/preceding-sibling::*[1][self::dbk:para][@rnd:style = "figure-title"] or
  740. $metadata'>
  741. <dbk:info>
  742. <xsl:if test='ancestor::dbk:para/preceding-sibling::*[1][self::dbk:para][@rnd:style = "figure-title"]'>
  743. <dbk:title>
  744. <xsl:apply-templates select='ancestor::dbk:para/preceding-sibling::*[1]/node()'/>
  745. </dbk:title>
  746. </xsl:if>
  747. <xsl:copy-of select='$metadata'/>
  748. </dbk:info>
  749. </xsl:if>
  750. <dbk:mediaobject>
  751. <xsl:apply-templates mode='rnd:copy'/>
  752. </dbk:mediaobject>
  753. <xsl:choose>
  754. <xsl:when test='not($caption)'/>
  755. <xsl:when test='not($next.captioned)'>
  756. <xsl:apply-templates select='ancestor::dbk:para/following-sibling::*[following-sibling::*[generate-id() = generate-id($caption)]][not(&metadata-content;)]'
  757. mode='rnd:figure'/>
  758. <xsl:apply-templates select='$caption'
  759. mode='rnd:caption'/>
  760. </xsl:when>
  761. <!-- Does caption belong to this image or next.captioned?
  762. - Only if it belongs to this image do we process it here.
  763. -->
  764. <xsl:when test='$next.captioned[preceding-sibling::*[generate-id() = generate-id($caption)]]'>
  765. <xsl:apply-templates select='ancestor::dbk:para/following-sibling::*[following-sibling::*[generate-id() = generate-id($caption)]][not(&metadata-content;)]'
  766. mode='rnd:figure'/>
  767. <xsl:apply-templates select='$caption'
  768. mode='rnd:caption'/>
  769. </xsl:when>
  770. <!-- otherwise caption does not belong to this figure -->
  771. </xsl:choose>
  772. </dbk:figure>
  773. </xsl:when>
  774. <xsl:otherwise>
  775. <xsl:call-template name='rnd:copy'/>
  776. </xsl:otherwise>
  777. </xsl:choose>
  778. </xsl:template>
  779. <xsl:template match='dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"]'
  780. mode='rnd:caption'>
  781. <dbk:caption>
  782. <dbk:para>
  783. <xsl:apply-templates/>
  784. </dbk:para>
  785. </dbk:caption>
  786. </xsl:template>
  787. <xsl:template match='*' mode='rnd:caption'/>
  788. <xsl:template match='*' mode='rnd:figure'>
  789. <xsl:call-template name='rnd:para'>
  790. <xsl:with-param name='suppress' select='false()'/>
  791. </xsl:call-template>
  792. </xsl:template>
  793. <!-- Sidebars -->
  794. <xsl:template match='*' mode='rnd:sidebar'>
  795. <xsl:call-template name='rnd:para'>
  796. <xsl:with-param name='suppress' select='false()'/>
  797. </xsl:call-template>
  798. </xsl:template>
  799. <!-- Lists -->
  800. <xsl:template match='dbk:para' mode='rnd:listitem'>
  801. <dbk:listitem>
  802. <dbk:para>
  803. <xsl:call-template name='rnd:attributes'/>
  804. <xsl:apply-templates/>
  805. </dbk:para>
  806. <xsl:apply-templates select='following-sibling::*[1]'
  807. mode='rnd:continue'/>
  808. <!-- Handle nested lists -->
  809. <xsl:variable name='list-type'
  810. select='concat(substring-before(@rnd:style, "list"), "list")'/>
  811. <xsl:variable name='list-level'
  812. select='substring-after(@rnd:style, $list-type)'/>
  813. <!-- Assuming only five levels of list nesting.
  814. - This is probably better done in a previous stage using grouping.
  815. -->
  816. <xsl:variable name='stop.node'
  817. select='following-sibling::dbk:para[@rnd:style != concat("itemizedlist", $list-level + 1) and
  818. @rnd:style != concat("orderedlist", $list-level + 1) and
  819. @rnd:style != concat("itemizedlist", $list-level + 2) and
  820. @rnd:style != concat("orderedlist", $list-level + 2) and
  821. @rnd:style != concat("itemizedlist", $list-level + 3) and
  822. @rnd:style != concat("orderedlist", $list-level + 3) and
  823. @rnd:style != "para-continue"][1]'/>
  824. <xsl:variable name='nested'
  825. select='following-sibling::dbk:para[@rnd:style = concat("itemizedlist", $list-level + 1) or @rnd:style = concat("orderedlist", $list-level + 1)][1]'/>
  826. <xsl:choose>
  827. <!-- Is there a nested list at all? -->
  828. <xsl:when test='following-sibling::*[self::dbk:para and @rnd:style != "para-continue"][1][@rnd:style != concat("itemizedlist", $list-level + 1) and @rnd:style != concat("orderedlist", $list-level + 1)]'/>
  829. <xsl:when test='following-sibling::dbk:para[@rnd:style = concat("itemizedlist", $list-level + 1) or @rnd:style = concat("orderedlist", $list-level + 1)] and
  830. $stop.node'>
  831. <xsl:element name='{concat(substring-before($nested/@rnd:style, "list"), "list")}'
  832. namespace='http://docbook.org/ns/docbook'>
  833. <xsl:apply-templates select='following-sibling::dbk:para[@rnd:style = concat("itemizedlist", $list-level + 1) or @rnd:style = concat("orderedlist", $list-level + 1)][following-sibling::*[generate-id() = generate-id($stop.node)]]'
  834. mode='rnd:listitem'/>
  835. </xsl:element>
  836. </xsl:when>
  837. <xsl:when test='following-sibling::dbk:para[@rnd:style = concat("itemizedlist", $list-level + 1) or @rnd:style = concat("orderedlist", $list-level + 1)]'>
  838. <xsl:element name='{concat(substring-before($nested/@rnd:style, "list"), "list")}'
  839. namespace='http://docbook.org/ns/docbook'>
  840. <xsl:apply-templates select='following-sibling::dbk:para[@rnd:style = concat("itemizedlist", $list-level + 1) or @rnd:style = concat("orderedlist", $list-level + 1)]'
  841. mode='rnd:listitem'/>
  842. </xsl:element>
  843. </xsl:when>
  844. </xsl:choose>
  845. </dbk:listitem>
  846. </xsl:template>
  847. <!-- Blockquotes -->
  848. <xsl:template match='dbk:para' mode='rnd:blockquote'>
  849. <xsl:choose>
  850. <xsl:when test='@rnd:style ="blockquote-attribution"'/>
  851. <xsl:when test='@rnd:style ="blockquote-title"'/>
  852. <xsl:otherwise>
  853. <dbk:para>
  854. <xsl:apply-templates/>
  855. </dbk:para>
  856. </xsl:otherwise>
  857. </xsl:choose>
  858. </xsl:template>
  859. <xsl:template match='dbk:para' mode='rnd:blockquote-attribution'>
  860. <xsl:if test='@rnd:style ="blockquote-attribution"'>
  861. <dbk:attribution>
  862. <xsl:apply-templates/>
  863. </dbk:attribution>
  864. </xsl:if>
  865. </xsl:template>
  866. <!-- Metadata -->
  867. <xsl:template match='dbk:para' mode='rnd:metadata'>
  868. <xsl:choose>
  869. <xsl:when test='@rnd:style = "biblioentry-title" and
  870. parent::dbk:bibliography|parent::dbk:bibliodiv'/>
  871. <xsl:when test='@rnd:style = "biblioentry-title"'>
  872. <xsl:call-template name='rnd:error'>
  873. <xsl:with-param name='code'>bad-metadata</xsl:with-param>
  874. <xsl:with-param name='message'>style "<xsl:value-of select='@rnd:style'/>" must not be metadata for parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
  875. </xsl:call-template>
  876. </xsl:when>
  877. <xsl:when test='@rnd:style = "abstract-title" or
  878. @rnd:style = "abstract"'>
  879. <xsl:variable name='stop.node'
  880. select='following-sibling::dbk:para[@rnd:style != "abstract"][1]'/>
  881. <xsl:choose>
  882. <xsl:when test='$stop.node'>
  883. <dbk:abstract>
  884. <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "abstract"][following-sibling::*[generate-id() = generate-id($stop.node)]]'
  885. mode='rnd:abstract'/>
  886. </dbk:abstract>
  887. <xsl:apply-templates select='$stop.node'
  888. mode='rnd:metadata'/>
  889. </xsl:when>
  890. <xsl:otherwise>
  891. <dbk:abstract>
  892. <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "abstract"]' mode='rnd:abstract'/>
  893. </dbk:abstract>
  894. </xsl:otherwise>
  895. </xsl:choose>
  896. </xsl:when>
  897. <xsl:when test='@rnd:style = "legalnotice"'>
  898. <xsl:variable name='stop.node'
  899. select='following-sibling::dbk:para[@rnd:style != "legalnotice"][1]'/>
  900. <xsl:choose>
  901. <xsl:when test='$stop.node'>
  902. <dbk:legalnotice>
  903. <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "legalnotice"][following-sibling::*[generate-id() = generate-id($stop.node)]]'
  904. mode='rnd:legalnotice'/>
  905. </dbk:legalnotice>
  906. <xsl:apply-templates select='$stop.node'
  907. mode='rnd:metadata'/>
  908. </xsl:when>
  909. <xsl:otherwise>
  910. <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "legalnotice"]'
  911. mode='rnd:legalnotice'/>
  912. </xsl:otherwise>
  913. </xsl:choose>
  914. </xsl:when>
  915. <xsl:when test='@rnd:style = "keyword"'>
  916. <xsl:variable name='stop.node'
  917. select='following-sibling::*[not(self::dbk:para) or
  918. (self::dbk:para and @rnd:style != "keyword")][1]'/>
  919. <xsl:choose>
  920. <xsl:when test='$stop.node'>
  921. <dbk:keywordset>
  922. <xsl:call-template name='rnd:keyword'>
  923. <xsl:with-param name='nodes'
  924. select='.|following-sibling::dbk:para[@rnd:style = "keyword"][following-sibling::*[generate-id() = generate-id($stop.node)]]'/>
  925. </xsl:call-template>
  926. </dbk:keywordset>
  927. <xsl:apply-templates select='$stop.node'
  928. mode='rnd:metadata'/>
  929. </xsl:when>
  930. <xsl:otherwise>
  931. <xsl:call-template name='rnd:keyword'>
  932. <xsl:with-param name='nodes'
  933. select='.|following-sibling::dbk:para[@rnd:style = "keyword"]'/>
  934. </xsl:call-template>
  935. </xsl:otherwise>
  936. </xsl:choose>
  937. </xsl:when>
  938. <xsl:when test='@rnd:style = "author"'>
  939. <dbk:author>
  940. <xsl:choose>
  941. <xsl:when test='dbk:emphasis[@rnd:style = "orgname"]'>
  942. <dbk:orgname>
  943. <xsl:apply-templates
  944. select='dbk:emphasis[@rnd:style = "orgname"]'
  945. mode='rnd:orgname'/>
  946. </dbk:orgname>
  947. <xsl:if test='*[not(@rnd:style = "orgname")]'>
  948. <xsl:call-template name='rnd:error'>
  949. <xsl:with-param name='code'>bad-author-orgname-combo</xsl:with-param>
  950. <xsl:with-param name='message'>character span "<xsl:value-of select='dbk:emphasis[@rnd:style != "orgname"][1]/@rnd:style'/>" not allowed in an author paragraph combined with orgname</xsl:with-param>
  951. </xsl:call-template>
  952. </xsl:if>
  953. </xsl:when>
  954. <xsl:otherwise>
  955. <dbk:personname>
  956. <!-- TODO: check style of author; mixed content or structured -->
  957. <xsl:apply-templates mode='rnd:personname'/>
  958. </dbk:personname>
  959. </xsl:otherwise>
  960. </xsl:choose>
  961. <xsl:apply-templates mode='rnd:author-personblurb'/>
  962. <xsl:apply-templates select='following-sibling::*[1]'
  963. mode='rnd:author'/>
  964. </dbk:author>
  965. <xsl:call-template name='rnd:resume-metadata'>
  966. <xsl:with-param name='node' select='following-sibling::*[1]'/>
  967. </xsl:call-template>
  968. </xsl:when>
  969. <xsl:when test='@rnd:style = "personblurb" or
  970. @rnd:style = "address" or
  971. @rnd:style = "affiliation" or
  972. @rnd:style = "contrib" or
  973. @rnd:style = "email"'/>
  974. <xsl:when test='@rnd:style = "releaseinfo" or
  975. @rnd:style = "date" or
  976. @rnd:style = "pubdate" or
  977. @rnd:style = "pagenums" or
  978. @rnd:style = "issuenum" or
  979. @rnd:style = "volumenum" or
  980. @rnd:style = "edition" or
  981. @rnd:style = "editor" or
  982. @rnd:style = "othercredit" or
  983. @rnd:style = "biblioid" or
  984. @rnd:style = "bibliosource" or
  985. @rnd:style = "bibliomisc" or
  986. @rnd:style = "revhistory" or
  987. @rnd:style = "revision"'>
  988. <xsl:element name='{@rnd:style}'
  989. namespace='http://docbook.org/ns/docbook'>
  990. <xsl:apply-templates mode='rnd:metadata'/>
  991. </xsl:element>
  992. <xsl:apply-templates select='following-sibling::*[1]'
  993. mode='rnd:metadata'/>
  994. </xsl:when>
  995. <xsl:when test='contains(@rnd:style, "-titleabbrev")'>
  996. <xsl:variable name='parent'
  997. select='substring-before(@rnd:style, "-titleabbrev")'/>
  998. <xsl:choose>
  999. <xsl:when test='$parent = local-name(..)'>
  1000. <dbk:titleabbrev>
  1001. <xsl:apply-templates mode='rnd:metadata'/>
  1002. </dbk:titleabbrev>
  1003. </xsl:when>
  1004. <xsl:when test='(parent::dbk:article or parent::dbk:book-component) and
  1005. preceding-sibling::dbk:para[@rnd:style = concat($parent, "-title")]'>
  1006. <dbk:titleabbrev>
  1007. <xsl:apply-templates mode='rnd:metadata'/>
  1008. </dbk:titleabbrev>
  1009. </xsl:when>
  1010. <xsl:otherwise>
  1011. <xsl:call-template name='rnd:error'>
  1012. <xsl:with-param name='code'>bad-titleabbrev</xsl:with-param>
  1013. <xsl:with-param name='message'>titleabbrev style "<xsl:value-of select='@rnd:style'/>" mismatches parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
  1014. </xsl:call-template>
  1015. </xsl:otherwise>
  1016. </xsl:choose>
  1017. <xsl:apply-templates select='following-sibling::*[1]'
  1018. mode='rnd:metadata'/>
  1019. </xsl:when>
  1020. <xsl:when test='contains(@rnd:style, "-title")'>
  1021. <xsl:variable name='parent'
  1022. select='substring-before(@rnd:style, "-title")'/>
  1023. <xsl:choose>
  1024. <xsl:when test='$parent = "table" or
  1025. $parent = "figure"'>
  1026. <dbk:title>
  1027. <xsl:apply-templates mode='rnd:metadata'/>
  1028. </dbk:title>
  1029. </xsl:when>
  1030. <xsl:when test='$parent = local-name(..)'>
  1031. <dbk:title>
  1032. <xsl:apply-templates mode='rnd:metadata'/>
  1033. </dbk:title>
  1034. </xsl:when>
  1035. <xsl:when test='parent::dbk:book-component'>
  1036. <dbk:title>
  1037. <xsl:apply-templates mode='rnd:metadata'/>
  1038. </dbk:title>
  1039. </xsl:when>
  1040. <xsl:when test='parent::dbk:article and
  1041. not(../../..)'>
  1042. <dbk:title>
  1043. <xsl:apply-templates mode='rnd:metadata'/>
  1044. </dbk:title>
  1045. </xsl:when>
  1046. <xsl:otherwise>
  1047. <xsl:call-template name='rnd:error'>
  1048. <xsl:with-param name='code'>bad-title</xsl:with-param>
  1049. <xsl:with-param name='message'>title style "<xsl:value-of select='@rnd:style'/>" mismatches parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
  1050. </xsl:call-template>
  1051. </xsl:otherwise>
  1052. </xsl:choose>
  1053. <xsl:apply-templates select='following-sibling::*[1]'
  1054. mode='rnd:metadata'/>
  1055. </xsl:when>
  1056. <!-- Exception to normal subtitle handling is biblioentry-subtitle -->
  1057. <xsl:when test='@rnd:style = "biblioentry-subtitle"'>
  1058. <!-- TODO: check that this is in a biblioentry -->
  1059. <dbk:subtitle>
  1060. <xsl:apply-templates mode='rnd:metadata'/>
  1061. </dbk:subtitle>
  1062. <xsl:apply-templates select='following-sibling::*[1]'
  1063. mode='rnd:metadata'/>
  1064. </xsl:when>
  1065. <xsl:when test='contains(@rnd:style, "-subtitle")'>
  1066. <xsl:variable name='parent'
  1067. select='substring-before(@rnd:style, "-subtitle")'/>
  1068. <xsl:choose>
  1069. <xsl:when test='$parent = local-name(..)'>
  1070. <dbk:subtitle>
  1071. <xsl:apply-templates mode='rnd:metadata'/>
  1072. </dbk:subtitle>
  1073. </xsl:when>
  1074. <xsl:when test='(parent::dbk:article or parent::dbk:book-component) and
  1075. preceding-sibling::dbk:para[@rnd:style = concat($parent, "-title")]'>
  1076. <dbk:subtitle>
  1077. <xsl:apply-templates mode='rnd:metadata'/>
  1078. </dbk:subtitle>
  1079. </xsl:when>
  1080. <xsl:otherwise>
  1081. <xsl:call-template name='rnd:error'>
  1082. <xsl:with-param name='code'>bad-subtitle</xsl:with-param>
  1083. <xsl:with-param name='message'>subtitle style "<xsl:value-of select='@rnd:style'/>" mismatches parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
  1084. </xsl:call-template>
  1085. </xsl:otherwise>
  1086. </xsl:choose>
  1087. <xsl:apply-templates select='following-sibling::*[1]'
  1088. mode='rnd:metadata'/>
  1089. </xsl:when>
  1090. <xsl:when test='@rnd:style = "publisher-address" and
  1091. preceding-sibling::*[1][not(self::dbk:para) or not(@rnd:style = "publisher")]'>
  1092. <xsl:call-template name='rnd:error'>
  1093. <xsl:with-param name='code'>bad-publisher-address</xsl:with-param>
  1094. <xsl:with-param name='message'>publisher-address must follow publisher</xsl:with-param>
  1095. </xsl:call-template>
  1096. <xsl:apply-templates select='following-sibling::*[1]'
  1097. mode='rnd:metadata'/>
  1098. </xsl:when>
  1099. <xsl:when test='@rnd:style = "publisher-address"'>
  1100. <xsl:apply-templates select='following-sibling::*[1]'
  1101. mode='rnd:metadata'/>
  1102. </xsl:when>
  1103. <xsl:when test='@rnd:style = "publisher"'>
  1104. <dbk:publisher>
  1105. <dbk:publishername>
  1106. <xsl:apply-templates/>
  1107. </dbk:publishername>
  1108. <xsl:if test='following-sibling::*[1][@rnd:style = "publisher-address"]'>
  1109. <xsl:apply-templates select='following-sibling::*[1]'
  1110. mode='rnd:publisher'/>
  1111. </xsl:if>
  1112. </dbk:publisher>
  1113. <xsl:apply-templates select='following-sibling::*[1]'
  1114. mode='rnd:metadata'/>
  1115. </xsl:when>
  1116. </xsl:choose>
  1117. </xsl:template>
  1118. <xsl:template name='rnd:keyword'>
  1119. <xsl:param name='nodes' select='/..'/>
  1120. <xsl:choose>
  1121. <xsl:when test='not($nodes)'/>
  1122. <xsl:otherwise>
  1123. <xsl:call-template name='rnd:keyword-phrases'>
  1124. <xsl:with-param name='text' select='$nodes[1]'/>
  1125. </xsl:call-template>
  1126. <xsl:call-template name='rnd:keyword'>
  1127. <xsl:with-param name='nodes' select='$nodes[position() != 1]'/>
  1128. </xsl:call-template>
  1129. </xsl:otherwise>
  1130. </xsl:choose>
  1131. </xsl:template>
  1132. <xsl:template name='rnd:keyword-phrases'>
  1133. <xsl:param name='text'/>
  1134. <xsl:choose>
  1135. <xsl:when test='not($text)'/>
  1136. <xsl:when test='contains($text, ",")'>
  1137. <dbk:keyword>
  1138. <xsl:value-of select='normalize-space(substring-before($text, ","))'/>
  1139. </dbk:keyword>
  1140. <xsl:call-template name='rnd:keyword-phrases'>
  1141. <xsl:with-param name='text' select='substring-after($text, ",")'/>
  1142. </xsl:call-template>
  1143. </xsl:when>
  1144. <xsl:otherwise>
  1145. <dbk:keyword>
  1146. <xsl:value-of select='normalize-space($text)'/>
  1147. </dbk:keyword>
  1148. </xsl:otherwise>
  1149. </xsl:choose>
  1150. </xsl:template>
  1151. <xsl:template match='dbk:emphasis' mode='rnd:metadata'>
  1152. <xsl:choose>
  1153. <xsl:when test='not(@rnd:style)'>
  1154. <xsl:copy>
  1155. <xsl:apply-templates mode='rnd:metadata'/>
  1156. </xsl:copy>
  1157. </xsl:when>
  1158. <xsl:when test='@rnd:style = "Hyperlink" and
  1159. parent::dbk:link'>
  1160. <xsl:apply-templates mode='rnd:metadata'/>
  1161. </xsl:when>
  1162. <xsl:when test='@rnd:style = "Hyperlink"'>
  1163. <dbk:link xlink:href='{.}'>
  1164. <xsl:apply-templates mode='rnd:metadata'/>
  1165. </dbk:link>
  1166. </xsl:when>
  1167. <xsl:otherwise>
  1168. <xsl:element name='{@rnd:style}'
  1169. namespace='http://docbook.org/ns/docbook'>
  1170. <xsl:apply-templates mode='rnd:metadata'/>
  1171. </xsl:element>
  1172. </xsl:otherwise>
  1173. </xsl:choose>
  1174. </xsl:template>
  1175. <xsl:template match='dbk:link' mode='rnd:metadata'>
  1176. <xsl:copy>
  1177. <xsl:apply-templates select='@*' mode='rnd:copy'/>
  1178. <xsl:apply-templates mode='rnd:metadata'/>
  1179. </xsl:copy>
  1180. </xsl:template>
  1181. <xsl:template match='dbk:inlinemediaobject' mode='rnd:metadata'>
  1182. <xsl:call-template name='rnd:copy'/>
  1183. </xsl:template>
  1184. <xsl:template match='*' mode='rnd:metadata'/>
  1185. <xsl:template name='rnd:resume-metadata'>
  1186. <xsl:param name='node' select='/..'/>
  1187. <xsl:choose>
  1188. <xsl:when test='$node[self::dbk:para][&author-content;]'>
  1189. <xsl:call-template name='rnd:resume-metadata'>
  1190. <xsl:with-param name='node' select='$node/following-sibling::*[1]'/>
  1191. </xsl:call-template>
  1192. </xsl:when>
  1193. <xsl:when test='$node[self::dbk:para][&metadata-content;]'>
  1194. <xsl:apply-templates select='$node' mode='rnd:metadata'/>
  1195. </xsl:when>
  1196. </xsl:choose>
  1197. </xsl:template>
  1198. <xsl:template match='dbk:para' mode='rnd:abstract'>
  1199. <xsl:choose>
  1200. <xsl:when test='@rnd:style = "abstract-title"'>
  1201. <dbk:title>
  1202. <xsl:call-template name='rnd:attributes'/>
  1203. <xsl:apply-templates/>
  1204. </dbk:title>
  1205. </xsl:when>
  1206. <xsl:otherwise>
  1207. <dbk:para>
  1208. <xsl:call-template name='rnd:attributes'/>
  1209. <xsl:apply-templates/>
  1210. </dbk:para>
  1211. </xsl:otherwise>
  1212. </xsl:choose>
  1213. </xsl:template>
  1214. <xsl:template match='dbk:para' mode='rnd:legalnotice'>
  1215. <dbk:para>
  1216. <xsl:call-template name='rnd:attributes'/>
  1217. <xsl:apply-templates/>
  1218. </dbk:para>
  1219. </xsl:template>
  1220. <xsl:template match='dbk:footnote' mode='rnd:personname'/>
  1221. <xsl:template match='dbk:emphasis' mode='rnd:personname'>
  1222. <!-- Need to check preceding emphasis for same style,
  1223. but blocks pretty-prints and all text nodes
  1224. are preserved in paragraph content.
  1225. -->
  1226. <xsl:variable name='previous'
  1227. select='preceding-sibling::node()[not(self::text()) or (self::text() and normalize-space() != "")]'/>
  1228. <!--
  1229. <xsl:comment> this style is <xsl:value-of select='@rnd:style'/>, previous style is <xsl:value-of select='$previous[last()]/@rnd:style'/> # previous <xsl:value-of select='count($previous)'/></xsl:comment>
  1230. -->
  1231. <xsl:choose>
  1232. <!-- inlines are coalesced -->
  1233. <xsl:when test='@rnd:style = $previous[last()][self::dbk:emphasis]/@rnd:style'/>
  1234. <xsl:when test='@rnd:style = "honorific" or
  1235. @rnd:style = "firstname" or
  1236. @rnd:style = "lineage" or
  1237. @rnd:style = "othername" or
  1238. @rnd:style = "surname"'>
  1239. <xsl:element name='{@rnd:style}'
  1240. namespace='http://docbook.org/ns/docbook'>
  1241. <xsl:apply-templates/>
  1242. <xsl:apply-templates select='following-sibling::dbk:emphasis[1]'
  1243. mode='rnd:personname-emphasis'>
  1244. <xsl:with-param name='style' select='@rnd:style'/>
  1245. </xsl:apply-templates>
  1246. </xsl:element>
  1247. </xsl:when>
  1248. <xsl:otherwise>
  1249. <xsl:call-template name='rnd:error'>
  1250. <xsl:with-param name='code'>bad-author-inline</xsl:with-param>
  1251. <xsl:with-param name='message'>character span "<xsl:value-of select='@rnd:style'/>" not allowed in an author paragraph</xsl:with-param>
  1252. </xsl:call-template>
  1253. </xsl:otherwise>
  1254. </xsl:choose>
  1255. </xsl:template>
  1256. <xsl:template match='text()' mode='rnd:author-personblurb'/>
  1257. <xsl:template match='dbk:emphasis' mode='rnd:author-personblurb'/>
  1258. <xsl:template match='dbk:footnote' mode='rnd:author-personblurb'>
  1259. <dbk:personblurb>
  1260. <dbk:para>
  1261. <xsl:copy>
  1262. <xsl:apply-templates select='@*' mode='rnd:copy'/>
  1263. <xsl:apply-templates/>
  1264. </xsl:copy>
  1265. </dbk:para>
  1266. </dbk:personblurb>
  1267. </xsl:template>
  1268. <xsl:template match='dbk:para' mode='rnd:author'>
  1269. <xsl:choose>
  1270. <xsl:when test='@rnd:style = "personblurb" and
  1271. preceding-sibling::*[1][self::dbk:para and @rnd:style != "personblurb"]'>
  1272. <dbk:personblurb>
  1273. <xsl:apply-templates select='.'
  1274. mode='rnd:personblurb'/>
  1275. </dbk:personblurb>
  1276. </xsl:when>
  1277. <xsl:when test='@rnd:style = "personblurb"'>
  1278. <xsl:apply-templates select='following-sibling::*[1]'
  1279. mode='rnd:author'/>
  1280. </xsl:when>
  1281. <!-- Web and mail addresses may appear in a simplified form -->
  1282. <xsl:when test='@rnd:style = "address"'>
  1283. <xsl:choose>
  1284. <xsl:when test='dbk:link and
  1285. count(dbk:link) = count(*)'>
  1286. <!-- simplified form -->
  1287. <dbk:otheraddr>
  1288. <xsl:apply-templates select='dbk:link'
  1289. mode='rnd:otheraddr'/>
  1290. </dbk:otheraddr>
  1291. </xsl:when>
  1292. <xsl:otherwise>
  1293. <dbk:address>
  1294. <xsl:apply-templates mode='rnd:author'/>
  1295. </dbk:address>
  1296. <xsl:apply-templates select='following-sibling::*[1]'
  1297. mode='rnd:author'/>
  1298. </xsl:otherwise>
  1299. </xsl:choose>
  1300. </xsl:when>
  1301. <xsl:when test='@rnd:style = "affiliation"'>
  1302. <dbk:affiliation>
  1303. <xsl:choose>
  1304. <xsl:when test='not(*)'>
  1305. <dbk:jobtitle>
  1306. <xsl:apply-templates mode='rnd:author'/>
  1307. </dbk:jobtitle>
  1308. </xsl:when>
  1309. <xsl:otherwise>
  1310. <xsl:apply-templates mode='rnd:author'/>
  1311. </xsl:otherwise>
  1312. </xsl:choose>
  1313. </dbk:affiliation>
  1314. <xsl:apply-templates select='following-sibling::*[1]'
  1315. mode='rnd:author'/>
  1316. </xsl:when>
  1317. <xsl:when test='@rnd:style = "contrib" or
  1318. @rnd:style = "email"'>
  1319. <xsl:element name='{@rnd:style}'
  1320. namespace='http://docbook.org/ns/docbook'>
  1321. <xsl:apply-templates mode='rnd:author'/>
  1322. </xsl:element>
  1323. <xsl:apply-templates select='following-sibling::*[1]'
  1324. mode='rnd:author'/>
  1325. </xsl:when>
  1326. </xsl:choose>
  1327. </xsl:template>
  1328. <xsl:template match='dbk:link' mode='rnd:otheraddr'>
  1329. <xsl:copy>
  1330. <xsl:apply-templates select='@*' mode='rnd:copy'/>
  1331. <xsl:apply-templates mode='rnd:otheraddr'/>
  1332. </xsl:copy>
  1333. </xsl:template>
  1334. <!-- TODO: not all of these inlines are allowed in all elements that are children of author.
  1335. Need to further refine validation of inlines.
  1336. -->
  1337. <xsl:template match='dbk:emphasis' mode='rnd:author'>
  1338. <xsl:choose>
  1339. <xsl:when test='@rnd:style = "city" or
  1340. @rnd:style = "country" or
  1341. @rnd:style = "email" or
  1342. @rnd:style = "fax" or
  1343. @rnd:style = "jobtitle" or
  1344. @rnd:style = "orgdiv" or
  1345. @rnd:style = "orgname" or
  1346. @rnd:style = "otheraddr" or
  1347. @rnd:style = "phone" or
  1348. @rnd:style = "pob" or
  1349. @rnd:style = "postcode" or
  1350. @rnd:style = "shortaffil" or
  1351. @rnd:style = "state" or
  1352. @rnd:style = "street"'>
  1353. <xsl:element name='{@rnd:style}'
  1354. namespace='http://docbook.org/ns/docbook'>
  1355. <xsl:apply-templates/>
  1356. </xsl:element>
  1357. </xsl:when>
  1358. <xsl:otherwise>
  1359. <xsl:call-template name='rnd:error'>
  1360. <xsl:with-param name='code'>metadata-bad-inline</xsl:with-param>
  1361. <xsl:with-param name='message'>character span "<xsl:value-of select='@rnd:style'/>" not allowed in author metadata</xsl:with-param>
  1362. </xsl:call-template>
  1363. </xsl:otherwise>
  1364. </xsl:choose>
  1365. </xsl:template>
  1366. <xsl:template match='dbk:para' mode='rnd:personblurb'>
  1367. <xsl:if test='@rnd:style = "personblurb"'>
  1368. <dbk:para>
  1369. <xsl:apply-templates/>
  1370. </dbk:para>
  1371. <xsl:apply-templates select='following-sibling::*[1]'
  1372. mode='rnd:personblurb'/>
  1373. </xsl:if>
  1374. </xsl:template>
  1375. <xsl:template match='dbk:para' mode='rnd:publisher'>
  1376. <xsl:if test='@rnd:style = "publisher-address"'>
  1377. <dbk:address>
  1378. <xsl:apply-templates/>
  1379. </dbk:address>
  1380. </xsl:if>
  1381. </xsl:template>
  1382. <xsl:template match='dbk:para' mode='rnd:programlisting'>
  1383. <xsl:text>&#xa;</xsl:text>
  1384. <xsl:apply-templates/>
  1385. </xsl:template>
  1386. <!-- Continuing paragraphs -->
  1387. <xsl:template match='*' mode='rnd:continue'/>
  1388. <xsl:template match='dbk:para' mode='rnd:continue'>
  1389. <xsl:if test='@rnd:style = "para-continue"'>
  1390. <dbk:para>
  1391. <xsl:call-template name='rnd:attributes'/>
  1392. <xsl:apply-templates/>
  1393. </dbk:para>
  1394. <xsl:apply-templates select='following-sibling::*[1]'
  1395. mode='rnd:continue'/>
  1396. </xsl:if>
  1397. </xsl:template>
  1398. <xsl:template match='dbk:informaltable' mode='rnd:continue'>
  1399. <xsl:apply-templates select='.'>
  1400. <xsl:with-param name='in-list' select='true()'/>
  1401. </xsl:apply-templates>
  1402. <xsl:apply-templates select='following-sibling::*[1]'
  1403. mode='rnd:continue'/>
  1404. </xsl:template>
  1405. <!-- Tables -->
  1406. <xsl:template match='dbk:informaltable'>
  1407. <xsl:param name='in-list' select='false()'/>
  1408. <xsl:choose>
  1409. <xsl:when test='not($in-list) and
  1410. preceding-sibling::dbk:para[1][starts-with(@rnd:style, "itemizedlist") or starts-with(@rnd:style, "orderedlist") or @rnd:style = "para-continue"]'/>
  1411. <xsl:when test='preceding-sibling::*[1][self::dbk:para][@rnd:style ="table-title"]'>
  1412. <dbk:table>
  1413. <xsl:apply-templates select='@*' mode='rnd:copy'/>
  1414. <dbk:info>
  1415. <xsl:apply-templates select='preceding-sibling::dbk:para[1]'
  1416. mode='rnd:table-title'/>
  1417. </dbk:info>
  1418. <xsl:call-template name='rnd:table-textobject'/>
  1419. <xsl:apply-templates/>
  1420. <xsl:call-template name='rnd:table-caption'/>
  1421. </dbk:table>
  1422. </xsl:when>
  1423. <xsl:otherwise>
  1424. <xsl:copy>
  1425. <xsl:apply-templates select='@*' mode='rnd:copy'/>
  1426. <xsl:call-template name='rnd:table-textobject'/>
  1427. <xsl:apply-templates/>
  1428. <xsl:call-template name='rnd:table-caption'/>
  1429. </xsl:copy>
  1430. </xsl:otherwise>
  1431. </xsl:choose>
  1432. </xsl:template>
  1433. <xsl:template match='dbk:tgroup'>
  1434. <xsl:copy>
  1435. <xsl:apply-templates select='@*' mode='rnd:copy'/>
  1436. <xsl:if test='not(@cols)'>
  1437. <xsl:attribute name='cols'>
  1438. <xsl:call-template name='dbk:max-columns'>
  1439. <xsl:with-param name='rows' select='*/dbk:row'/>
  1440. </xsl:call-template>
  1441. </xsl:attribute>
  1442. </xsl:if>
  1443. <xsl:apply-templates/>
  1444. </xsl:copy>
  1445. </xsl:template>
  1446. <xsl:template name='dbk:max-columns'>
  1447. <xsl:param name='rows' select='/..'/>
  1448. <xsl:param name='max' select='0'/>
  1449. <!-- This is a tail-recursive algorithm.
  1450. Could improve this with other algorithm(s),
  1451. eg. divide-and-conquer.
  1452. -->
  1453. <xsl:choose>
  1454. <xsl:when test='not($rows)'>
  1455. <xsl:value-of select='$max'/>
  1456. </xsl:when>
  1457. <xsl:when test='count($rows[1]/dbk:entry) > $max'>
  1458. <xsl:call-template name='dbk:max-columns'>
  1459. <xsl:with-param name='rows' select='$rows[position() != 1]'/>
  1460. <xsl:with-param name='max' select='count($rows[1]/dbk:entry)'/>
  1461. </xsl:call-template>
  1462. </xsl:when>
  1463. <xsl:otherwise>
  1464. <xsl:call-template name='dbk:max-columns'>
  1465. <xsl:with-param name='rows' select='$rows[position() != 1]'/>
  1466. <xsl:with-param name='max' select='$max'/>
  1467. </xsl:call-template>
  1468. </xsl:otherwise>
  1469. </xsl:choose>
  1470. </xsl:template>
  1471. <xsl:template match='dbk:tbody|dbk:thead|dbk:tfoot|dbk:row|dbk:colspec'>
  1472. <xsl:copy>
  1473. <xsl:apply-templates select='@*' mode='rnd:copy'/>
  1474. <xsl:apply-templates/>
  1475. </xsl:copy>
  1476. </xsl:template>
  1477. <xsl:template match='dbk:entry'>
  1478. <dbk:entry>
  1479. <xsl:apply-templates select='@*' mode='rnd:copy'/>
  1480. <xsl:apply-templates/>
  1481. </dbk:entry>
  1482. </xsl:template>
  1483. <xsl:template match='dbk:para' mode='rnd:table-title'>
  1484. <dbk:title>
  1485. <xsl:apply-templates/>
  1486. </dbk:title>
  1487. </xsl:template>
  1488. <!-- Find the caption associated with this table -->
  1489. <xsl:template name='rnd:table-caption'>
  1490. <xsl:variable name='candidate'
  1491. select='following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"][1]'/>
  1492. <xsl:if test='$candidate != "" and
  1493. generate-id($candidate/preceding-sibling::dbk:informaltable[1]) = generate-id(.)'>
  1494. <dbk:caption>
  1495. <dbk:para>
  1496. <xsl:apply-templates select='$candidate/node()'/>
  1497. </dbk:para>
  1498. </dbk:caption>
  1499. </xsl:if>
  1500. </xsl:template>
  1501. <!-- Find table associated text -->
  1502. <xsl:template name='rnd:table-textobject'>
  1503. <xsl:variable name='caption'
  1504. select='following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"][1]'/>
  1505. <xsl:if test='generate-id($caption/preceding-sibling::dbk:informaltable[1]) = generate-id(.)'>
  1506. <xsl:variable name='content'
  1507. select='following-sibling::*[following-sibling::*[generate-id($caption) = generate-id()]]'/>
  1508. <xsl:if test='$content'>
  1509. <dbk:textobject>
  1510. <xsl:apply-templates select='$content' mode='rnd:textobject'/>
  1511. </dbk:textobject>
  1512. </xsl:if>
  1513. </xsl:if>
  1514. </xsl:template>
  1515. <xsl:template match='dbk:para' mode='rnd:textobject'>
  1516. <xsl:call-template name='rnd:para'>
  1517. <xsl:with-param name='suppress' select='false()'/>
  1518. </xsl:call-template>
  1519. </xsl:template>
  1520. <!-- Footnotes -->
  1521. <xsl:template match='dbk:footnote'>
  1522. <xsl:copy>
  1523. <xsl:apply-templates select='@*' mode='rnd:copy'/>
  1524. <xsl:apply-templates/>
  1525. </xsl:copy>
  1526. </xsl:template>
  1527. <!-- utilities -->
  1528. <!-- rnd:attributes reconstitutes an element's attributes -->
  1529. <xsl:template name='rnd:attributes'>
  1530. <xsl:param name='node' select='.'/>
  1531. <xsl:apply-templates select='$node/@*[namespace-uri() != "http://docbook.org/ns/docbook/roundtrip"]' mode='rnd:copy'/>
  1532. </xsl:template>
  1533. <xsl:template match='*' name='rnd:copy' mode='rnd:copy'>
  1534. <xsl:copy>
  1535. <xsl:apply-templates select='@*' mode='rnd:copy'/>
  1536. <xsl:apply-templates mode='rnd:copy'/>
  1537. </xsl:copy>
  1538. </xsl:template>
  1539. <xsl:template match='@*' mode='rnd:copy'>
  1540. <xsl:copy/>
  1541. </xsl:template>
  1542. <!-- These templates are invoked whenever an error condition is detected in the conversion of a document.
  1543. -->
  1544. <xsl:template name='rnd:error'>
  1545. <xsl:param name='node' select='.'/>
  1546. <xsl:param name='code'/>
  1547. <xsl:param name='message'/>
  1548. <xsl:comment><xsl:value-of select='$message'/></xsl:comment>
  1549. <xsl:message>ERROR "<xsl:value-of select='$code'/>": <xsl:value-of select='$message'/></xsl:message>
  1550. <rnd:error>
  1551. <rnd:code>
  1552. <xsl:value-of select='$code'/>
  1553. </rnd:code>
  1554. <rnd:message>
  1555. <xsl:value-of select='$message'/>
  1556. </rnd:message>
  1557. </rnd:error>
  1558. </xsl:template>
  1559. <xsl:template name='rnd:warning'>
  1560. <xsl:param name='node' select='.'/>
  1561. <xsl:param name='code'/>
  1562. <xsl:param name='message'/>
  1563. <xsl:comment><xsl:value-of select='$message'/></xsl:comment>
  1564. <xsl:message>WARNING "<xsl:value-of select='$code'/>": <xsl:value-of select='$message'/></xsl:message>
  1565. <rnd:warning>
  1566. <rnd:code>
  1567. <xsl:value-of select='$code'/>
  1568. </rnd:code>
  1569. <rnd:message>
  1570. <xsl:value-of select='$message'/>
  1571. </rnd:message>
  1572. </rnd:warning>
  1573. </xsl:template>
  1574. </xsl:stylesheet>