sofftodocbookheadings.xsl 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. <?xml version='1.0' encoding="UTF-8"?>
  2. <!--
  3. * This file is part of the LibreOffice project.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. *
  9. * This file incorporates work covered by the following license notice:
  10. *
  11. * Licensed to the Apache Software Foundation (ASF) under one or more
  12. * contributor license agreements. See the NOTICE file distributed
  13. * with this work for additional information regarding copyright
  14. * ownership. The ASF licenses this file to you under the Apache
  15. * License, Version 2.0 (the "License"); you may not use this file
  16. * except in compliance with the License. You may obtain a copy of
  17. * the License at http://www.apache.org/licenses/LICENSE-2.0 .
  18. -->
  19. <xsl:stylesheet version="1.0" xmlns:style="http://openoffice.org/2000/style" xmlns:text="http://openoffice.org/2000/text" xmlns:office="http://openoffice.org/2000/office" xmlns:table="http://openoffice.org/2000/table" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="http://openoffice.org/2000/meta" xmlns:number="http://openoffice.org/2000/datastyle" xmlns:svg="http://www.w3.org/2000/svg" xmlns:chart="http://openoffice.org/2000/chart" xmlns:dr3d="http://openoffice.org/2000/dr3d" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="http://openoffice.org/2000/form" xmlns:script="http://openoffice.org/2000/script" xmlns:config="http://openoffice.org/2001/config" office:class="text" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="office meta table number dc fo xlink chart math script xsl draw svg dr3d form config text style">
  20. <xsl:output method="xml" indent="yes" omit-xml-declaration="no" version="1.0" encoding="UTF-8" doctype-public="-//OASIS//DTD DocBook XML V4.1.2//EN" doctype-system="http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"/>
  21. <!-- Heading will be mapped to sections.
  22. In OpenDocument headings are not nested, they do not embrace their related content, the XML hierarchy has to be restructured.
  23. Example of OpenDocument content:
  24. <office:body>
  25. <text:h text:style-name="Heading 1" text:level="1">Heading 1</text:h>
  26. <text:p text:style-name="Text body">Heading 1 Content</text:p>
  27. <text:h text:style-name="Heading 2" text:level="2">Heading 2</text:h>
  28. <text:p text:style-name="Text body">Heading 2 Content</text:p>
  29. <office:body>
  30. Example of DocBook content:
  31. <article lang="en-US">
  32. <sect1>
  33. <title>Heading 1</title>
  34. <para>Heading 1 Content</para>
  35. <sect2>
  36. <title>Heading 2</title>
  37. <para>Heading 2 Content</para>
  38. </sect2>
  39. </sect1>
  40. </article>
  41. -->
  42. <!-- The key function "nestedContent" returns all ODF elements that are children of the current heading (i.e. text:h) or their parent office:body in case there is no text:h.
  43. It works by matching all ODF elements, that text:h refer to (it's sibling or office:body childring)
  44. Various keyed element sets of these matched elements are being generated. A set is identified by having the same last (closest) preceding text:h or if none existent the parent document.
  45. All those elements, that have the current heading as last preceding heading (text:h) are returned as a nodeset.
  46. -->
  47. <xsl:key name="nestedContent"
  48. match="text:p | table:table | text:span | text:ordered-list | office:annotation | text:unordered-list | text:footnote | text:a | text:list-item | draw:plugin | draw:text-box | text:footnote-body | text:section"
  49. use="generate-id((.. | preceding::text:h)[last()])"/>
  50. <!-- The key function "nestedHeadings" returns a nodeset of all heading (text:h) elements, which belong to this heading (follow and have a higher outline number than the current text:h, which ID is given to the function) -->
  51. <xsl:key name="nestedHeadings"
  52. match="text:h"
  53. use="generate-id(preceding::text:h[@text:level &lt; current()/@text:level][1])"/>
  54. <!-- The key function "getHeadingsByOutline" returns all headings of a certain outline level -->
  55. <xsl:key name="getHeadingsByOutline"
  56. match="text:h"
  57. use="@text:level"/>
  58. <!-- A further problem during mapping of Heading to sections is the quantity of levels. In OpenDocument there can exist more than 4 hierarchies (outline levels).
  59. Furthermore an OpenDocument have not to start with heading outline level 1 nor does an outline level 2 have to follow.
  60. Therefore all possible existing heading outline levels from 1 to 10 have to be mapped to the section1 to section4 in DocBook.
  61. The lowest outline number is mapped section1, second is section2... until fourth and higher are all mapped to section4 -->
  62. <!-- Each global variable hold the outline level which has been mapped to one of the four sections in DocBook -->
  63. <xsl:variable name="section1_OutlineLevel">
  64. <xsl:call-template name="findOutlineLevel">
  65. <xsl:with-param name="candidateOutlineLevel" select="1"/>
  66. </xsl:call-template>
  67. </xsl:variable>
  68. <xsl:variable name="section2_OutlineLevel">
  69. <xsl:call-template name="findOutlineLevel">
  70. <xsl:with-param name="candidateOutlineLevel" select="$section1_OutlineLevel + 1"/>
  71. </xsl:call-template>
  72. </xsl:variable>
  73. <xsl:variable name="section3_OutlineLevel">
  74. <xsl:call-template name="findOutlineLevel">
  75. <xsl:with-param name="candidateOutlineLevel" select="$section2_OutlineLevel + 1"/>
  76. </xsl:call-template>
  77. </xsl:variable>
  78. <xsl:variable name="section4_OutlineLevel">
  79. <xsl:call-template name="findOutlineLevel">
  80. <xsl:with-param name="candidateOutlineLevel" select="$section3_OutlineLevel + 1"/>
  81. </xsl:call-template>
  82. </xsl:variable>
  83. <!-- get the minimum available heading outline level (usually '1') -->
  84. <xsl:template name="findOutlineLevel">
  85. <xsl:param name="candidateOutlineLevel"/>
  86. <xsl:choose>
  87. <xsl:when test="key('getHeadingsByOutline', $candidateOutlineLevel)[1]/@text:level != ''">
  88. <xsl:value-of select="$candidateOutlineLevel"/>
  89. </xsl:when>
  90. <xsl:otherwise>
  91. <xsl:if test="$candidateOutlineLevel &lt; 11">
  92. <xsl:call-template name="findOutlineLevel">
  93. <xsl:with-param name="candidateOutlineLevel" select="$candidateOutlineLevel + 1"/>
  94. </xsl:call-template>
  95. </xsl:if>
  96. </xsl:otherwise>
  97. </xsl:choose>
  98. </xsl:template>
  99. <!-- START -->
  100. <xsl:template match="/*">
  101. <xsl:element name="article">
  102. <xsl:attribute name="lang">
  103. <xsl:value-of select="/*/office:meta/dc:language"/>
  104. </xsl:attribute>
  105. <!-- page style header -->
  106. <xsl:call-template name="page-style">
  107. <xsl:with-param name="area" select="'header'"/>
  108. </xsl:call-template>
  109. <xsl:apply-templates select="office:body"/>
  110. <!-- page style footer -->
  111. <xsl:call-template name="page-style"/>
  112. </xsl:element>
  113. </xsl:template>
  114. <xsl:key match="style:master-page" name="styleMasterPage" use="@style:name" />
  115. <!-- using a simple heuristic for "standard" page-style heading/footer from page styles -->
  116. <xsl:template name="page-style">
  117. <xsl:param name="area"/>
  118. <xsl:variable name="defaultPageStyle" select="key('styleMasterPage', 'Standard')"/>
  119. <xsl:choose>
  120. <xsl:when test="$area = 'header'">
  121. <xsl:apply-templates select="$defaultPageStyle/style:header/*"/>
  122. </xsl:when>
  123. <xsl:otherwise>
  124. <xsl:apply-templates select="$defaultPageStyle/style:footer/*"/>
  125. </xsl:otherwise>
  126. </xsl:choose>
  127. </xsl:template>
  128. <xsl:template match="office:body">
  129. <!-- here all children of office:body before the first heading are matched -->
  130. <xsl:apply-templates select="key('nestedContent', generate-id())"/>
  131. <!-- have to be descendant as text:h can be in a list:item in some list -->
  132. <xsl:variable name="firstHeading" select="descendant::text:h[1]"/>
  133. <!-- changing the context node from office:body to text:h as required for used key functions -->
  134. <xsl:for-each select="descendant::text:h[@text:level=$section1_OutlineLevel][1]">
  135. <!-- if the first heading is not of the section1 level -->
  136. <xsl:if test="generate-id(.) != generate-id($firstHeading)">
  137. <!-- create an anonymous section1 and embrace all headings preceding the first real existent section1 -->
  138. <xsl:element name="sect1">
  139. <title></title>
  140. <!-- create sections for all the first section1 preluding headings -->
  141. <xsl:for-each select="key('getHeadingsByOutline', $section1_OutlineLevel)[1]/preceding::text:h">
  142. <xsl:call-template name="make-section">
  143. <xsl:with-param name="previousSectionLevel" select="$section1_OutlineLevel"/>
  144. <xsl:with-param name="currentSectionLevel">
  145. <xsl:call-template name="getSectionLevel">
  146. <xsl:with-param name="outlineLevel" select="@text:level"/>
  147. </xsl:call-template>
  148. </xsl:with-param>
  149. </xsl:call-template>
  150. </xsl:for-each>
  151. </xsl:element>
  152. </xsl:if>
  153. </xsl:for-each>
  154. <!-- match all headings, which are mapped to section1 to create a nested section structure used in docbook (see first comment after copyright) -->
  155. <xsl:apply-templates mode="recreateStructure" select="descendant::text:h[@text:level = $section1_OutlineLevel]"/>
  156. </xsl:template>
  157. <xsl:template match="text:h" mode="recreateStructure">
  158. <!-- relate the current ODF outline level of the heading to one of the four docbook section levels-->
  159. <xsl:variable name="currentSectionLevel">
  160. <xsl:call-template name="getSectionLevel">
  161. <xsl:with-param name="outlineLevel" select="@text:level"/>
  162. </xsl:call-template>
  163. </xsl:variable>
  164. <xsl:choose>
  165. <!-- heading with outline level 1 might be an Abstract -->
  166. <xsl:when test="$currentSectionLevel = 1">
  167. <xsl:choose>
  168. <!-- when the content of a level 1 heading is 'Abstract' the <abstract> docbook element is used instead of <section1> -->
  169. <xsl:when test=".='Abstract'">
  170. <abstract>
  171. <xsl:apply-templates select="key('nestedContent', generate-id())"/>
  172. <xsl:apply-templates select="key('nestedHeadings', generate-id())" mode="recreateStructure"/>
  173. </abstract>
  174. </xsl:when>
  175. <xsl:otherwise>
  176. <xsl:call-template name="make-section">
  177. <xsl:with-param name="currentSectionLevel" select="$currentSectionLevel"/>
  178. <xsl:with-param name="previousSectionLevel" select="$currentSectionLevel"/>
  179. </xsl:call-template>
  180. </xsl:otherwise>
  181. </xsl:choose>
  182. </xsl:when>
  183. <xsl:otherwise>
  184. <xsl:variable name="previousHeading" select="preceding::text:h[@text:level &lt; current()/@text:level][1]"/>
  185. <xsl:choose>
  186. <xsl:when test="$previousHeading/@text:level != ''">
  187. <xsl:call-template name="make-section">
  188. <xsl:with-param name="currentSectionLevel" select="$currentSectionLevel"/>
  189. <xsl:with-param name="previousSectionLevel">
  190. <xsl:call-template name="getSectionLevel">
  191. <xsl:with-param name="outlineLevel" select="$previousHeading/@text:level"/>
  192. </xsl:call-template>
  193. </xsl:with-param>
  194. </xsl:call-template>
  195. </xsl:when>
  196. <xsl:otherwise>
  197. <xsl:call-template name="make-section">
  198. <xsl:with-param name="currentSectionLevel" select="$currentSectionLevel"/>
  199. <xsl:with-param name="previousSectionLevel" select="$currentSectionLevel"/>
  200. </xsl:call-template>
  201. </xsl:otherwise>
  202. </xsl:choose>
  203. </xsl:otherwise>
  204. </xsl:choose>
  205. </xsl:template>
  206. <xsl:template match="text:bookmark | text:bookmark-start">
  207. <xsl:element name="anchor">
  208. <xsl:attribute name="id">
  209. <!-- ID have to be an NCName which have to start with a letter or '_'
  210. in case of the frequent starting number a '_' will be added as prefix -->
  211. <xsl:choose>
  212. <xsl:when test="(starts-with(@text:name, '0') or
  213. starts-with(@text:name, '1') or
  214. starts-with(@text:name, '2') or
  215. starts-with(@text:name, '3') or
  216. starts-with(@text:name, '4') or
  217. starts-with(@text:name, '5') or
  218. starts-with(@text:name, '6') or
  219. starts-with(@text:name, '7') or
  220. starts-with(@text:name, '8') or
  221. starts-with(@text:name, '9'))">
  222. <xsl:value-of select="concat('_', @text:name)"/>
  223. </xsl:when>
  224. <xsl:otherwise>
  225. <xsl:value-of select="@text:name"/>
  226. </xsl:otherwise>
  227. </xsl:choose>
  228. </xsl:attribute>
  229. </xsl:element>
  230. </xsl:template>
  231. <xsl:template name="getSectionLevel">
  232. <xsl:param name="outlineLevel"/>
  233. <xsl:choose>
  234. <xsl:when test="$outlineLevel = $section1_OutlineLevel">1</xsl:when>
  235. <xsl:when test="$outlineLevel = $section2_OutlineLevel">2</xsl:when>
  236. <xsl:when test="$outlineLevel = $section3_OutlineLevel">3</xsl:when>
  237. <xsl:otherwise>4</xsl:otherwise>
  238. </xsl:choose>
  239. </xsl:template>
  240. <!-- make-section creates the nested section hierarchy and
  241. in case the difference between the parent section and the new section is higher than one
  242. a section is inserted to keep the output format valid -->
  243. <xsl:template name="make-section">
  244. <xsl:param name="currentSectionLevel"/>
  245. <xsl:param name="previousSectionLevel"/>
  246. <xsl:choose>
  247. <!-- empty title as it is an empty section between two headings with an outline level difference higher than 1 -->
  248. <xsl:when test="$currentSectionLevel &gt; $previousSectionLevel+1">
  249. <xsl:element name="{concat('sect', $previousSectionLevel + 1)}">
  250. <title></title>
  251. <xsl:call-template name="make-section">
  252. <xsl:with-param name="currentSectionLevel" select="$currentSectionLevel"/>
  253. <xsl:with-param name="previousSectionLevel" select="$previousSectionLevel +1"/>
  254. </xsl:call-template>
  255. </xsl:element>
  256. </xsl:when>
  257. <xsl:otherwise>
  258. <xsl:element name="{concat('sect', $currentSectionLevel)}">
  259. <title>
  260. <xsl:apply-templates/>
  261. </title>
  262. <xsl:apply-templates select="key('nestedContent', generate-id())"/>
  263. <xsl:apply-templates select="key('nestedHeadings', generate-id())" mode="recreateStructure"/>
  264. </xsl:element>
  265. </xsl:otherwise>
  266. </xsl:choose>
  267. </xsl:template>
  268. <xsl:template match="office:meta">
  269. <!--<xsl:apply-templates/>--></xsl:template>
  270. <xsl:template match="meta:editing-cycles"></xsl:template>
  271. <xsl:template match="meta:user-defined"></xsl:template>
  272. <xsl:template match="meta:editing-duration"></xsl:template>
  273. <xsl:template match="dc:language"></xsl:template>
  274. <xsl:template match="dc:date">
  275. <!--<pubdate>
  276. <xsl:value-of select="substring-before(.,'T')"/>
  277. </pubdate>--></xsl:template>
  278. <xsl:template match="meta:creation-date"></xsl:template>
  279. <xsl:template match="office:styles">
  280. <xsl:apply-templates/>
  281. </xsl:template>
  282. <xsl:template match="office:script"></xsl:template>
  283. <xsl:template match="office:settings"></xsl:template>
  284. <xsl:template match="office:font-decls"></xsl:template>
  285. <xsl:template match="text:section">
  286. <xsl:choose>
  287. <xsl:when test="@text:name='ArticleInfo'">
  288. <articleinfo>
  289. <title>
  290. <xsl:value-of select="text:p[@text:style-name='Document Title']"/>
  291. </title>
  292. <subtitle>
  293. <xsl:value-of select="text:p[@text:style-name='Document SubTitle']"/>
  294. </subtitle>
  295. <edition>
  296. <xsl:value-of select="text:p/text:variable-set[@text:name='articleinfo.edition']"/>
  297. </edition>
  298. <xsl:for-each select="text:p/text:variable-set[substring-after(@text:name,'articleinfo.releaseinfo')]">
  299. <releaseinfo>
  300. <xsl:value-of select="."/>
  301. </releaseinfo>
  302. </xsl:for-each>
  303. <xsl:call-template name="ArticleInfo">
  304. <xsl:with-param name="level" select="0"/>
  305. </xsl:call-template>
  306. </articleinfo>
  307. </xsl:when>
  308. <xsl:when test="@text:name='Abstract'">
  309. <abstract>
  310. <xsl:apply-templates/>
  311. </abstract>
  312. </xsl:when>
  313. <xsl:when test="@text:name='Appendix'">
  314. <appendix>
  315. <xsl:apply-templates/>
  316. </appendix>
  317. </xsl:when>
  318. <xsl:otherwise>
  319. <xsl:element name="{concat('sect', count(ancestor::text:section) + 1)}">
  320. <xsl:attribute name="id">
  321. <xsl:value-of select="@text:name"/>
  322. </xsl:attribute>
  323. <xsl:apply-templates/>
  324. </xsl:element>
  325. </xsl:otherwise>
  326. </xsl:choose>
  327. </xsl:template>
  328. <xsl:template name="ArticleInfo">
  329. <xsl:param name="level"/>
  330. <xsl:variable name="author">
  331. <xsl:value-of select="concat('articleinfo.author_','', $level)"/>
  332. </xsl:variable>
  333. <xsl:if test="text:p/text:variable-set[contains(@text:name, $author )]">
  334. <xsl:call-template name="Author">
  335. <xsl:with-param name="AuthorLevel" select="0"/>
  336. </xsl:call-template>
  337. <xsl:call-template name="Copyright">
  338. <xsl:with-param name="CopyrightLevel" select="0"/>
  339. </xsl:call-template>
  340. </xsl:if>
  341. </xsl:template>
  342. <xsl:template name="Copyright">
  343. <xsl:param name="CopyrightLevel"/>
  344. <xsl:variable name="Copyright">
  345. <xsl:value-of select="concat('articleinfo.copyright_','', $CopyrightLevel)"/>
  346. </xsl:variable>
  347. <xsl:if test="text:p/text:variable-set[contains(@text:name,$Copyright)]">
  348. <copyright>
  349. <xsl:call-template name="Year">
  350. <xsl:with-param name="CopyrightLevel" select="$CopyrightLevel"/>
  351. <xsl:with-param name="YearlLevel" select="0"/>
  352. </xsl:call-template>
  353. <xsl:call-template name="Holder">
  354. <xsl:with-param name="CopyrightLevel" select="$CopyrightLevel"/>
  355. <xsl:with-param name="HolderlLevel" select="0"/>
  356. </xsl:call-template>
  357. </copyright>
  358. </xsl:if>
  359. </xsl:template>
  360. <xsl:template name="Year">
  361. <xsl:param name="CopyrightLevel"/>
  362. <xsl:param name="YearLevel"/>
  363. <xsl:variable name="Copyright">
  364. <xsl:value-of select="concat('articleinfo.copyright_','', $CopyrightLevel)"/>
  365. </xsl:variable>
  366. <xsl:variable name="Year">
  367. <xsl:value-of select="concat($Copyright,'',concat('.year_','',$YearLevel))"/>
  368. </xsl:variable>
  369. <xsl:if test="text:p/text:variable-set[@text:name=$Year]">
  370. <orgname>
  371. <xsl:value-of select="text:p/text:variable-set[@text:name=$Year]"/>
  372. </orgname>
  373. </xsl:if>
  374. </xsl:template>
  375. <xsl:template name="Holder">
  376. <xsl:param name="CopyrightLevel"/>
  377. <xsl:param name="HolderLevel"/>
  378. <xsl:variable name="Copyright">
  379. <xsl:value-of select="concat('articleinfo.copyright_','', $CopyrightLevel)"/>
  380. </xsl:variable>
  381. <xsl:variable name="Holder">
  382. <xsl:value-of select="concat($Copyright,'',concat('.holder_','',$HolderLevel))"/>
  383. </xsl:variable>
  384. <xsl:if test="text:p/text:variable-set[@text:name=$Holder]">
  385. <orgname>
  386. <xsl:value-of select="text:p/text:variable-set[@text:name=$Holder]"/>
  387. </orgname>
  388. </xsl:if>
  389. </xsl:template>
  390. <xsl:template name="Author">
  391. <xsl:param name="AuthorLevel"/>
  392. <xsl:variable name="Author">
  393. <xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
  394. </xsl:variable>
  395. <xsl:if test="text:p/text:variable-set[contains(@text:name, $Author )]">
  396. <author>
  397. <xsl:call-template name="Surname">
  398. <xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
  399. <xsl:with-param name="SurnameLevel" select="0"/>
  400. </xsl:call-template>
  401. <xsl:call-template name="Firstname">
  402. <xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
  403. <xsl:with-param name="FirstnameLevel" select="0"/>
  404. </xsl:call-template>
  405. <xsl:call-template name="Affiliation">
  406. <xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
  407. <xsl:with-param name="AffilLevel" select="0"/>
  408. </xsl:call-template>
  409. </author>
  410. <xsl:call-template name="Author">
  411. <xsl:with-param name="AuthorLevel" select="$AuthorLevel+1"/>
  412. </xsl:call-template>
  413. </xsl:if>
  414. </xsl:template>
  415. <xsl:template name="Surname">
  416. <xsl:param name="AuthorLevel"/>
  417. <xsl:param name="SurnameLevel"/>
  418. <xsl:variable name="Author">
  419. <xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
  420. </xsl:variable>
  421. <xsl:variable name="Surname">
  422. <xsl:value-of select="concat($Author,'',concat('.surname_','',$SurnameLevel))"/>
  423. </xsl:variable>
  424. <xsl:if test="text:p/text:variable-set[@text:name=$Surname]">
  425. <surname>
  426. <xsl:value-of select="text:p/text:variable-set[@text:name=$Surname]"/>
  427. </surname>
  428. <xsl:call-template name="Surname">
  429. <xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
  430. <xsl:with-param name="SurnameLevel" select="SurnameLevel+1"/>
  431. </xsl:call-template>
  432. </xsl:if>
  433. </xsl:template>
  434. <xsl:template name="Firstname">
  435. <xsl:param name="AuthorLevel"/>
  436. <xsl:param name="FirstnameLevel"/>
  437. <xsl:variable name="Author">
  438. <xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
  439. </xsl:variable>
  440. <xsl:variable name="Firstname">
  441. <xsl:value-of select="concat($Author,'',concat('.firstname_','',$FirstnameLevel))"/>
  442. </xsl:variable>
  443. <xsl:if test="text:p/text:variable-set[@text:name=$Firstname]">
  444. <firstname>
  445. <xsl:value-of select="text:p/text:variable-set[@text:name=$Firstname]"/>
  446. </firstname>
  447. <xsl:call-template name="Surname">
  448. <xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
  449. <xsl:with-param name="FirstnameLevel" select="FirstnameLevel+1"/>
  450. </xsl:call-template>
  451. </xsl:if>
  452. </xsl:template>
  453. <xsl:template name="Affiliation">
  454. <xsl:param name="AuthorLevel"/>
  455. <xsl:param name="AffilLevel"/>
  456. <xsl:variable name="Author">
  457. <xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
  458. </xsl:variable>
  459. <xsl:variable name="Affil">
  460. <xsl:value-of select="concat($Author,'',concat('.affiliation_','',$AffilLevel))"/>
  461. </xsl:variable>
  462. <xsl:if test="text:p/text:variable-set[contains(@text:name,$Affil)]">
  463. <affiliation>
  464. <xsl:call-template name="Orgname">
  465. <xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
  466. <xsl:with-param name="AffilLevel" select="$AffilLevel"/>
  467. <xsl:with-param name="OrgLevel" select="0"/>
  468. </xsl:call-template>
  469. <xsl:call-template name="Address">
  470. <xsl:with-param name="AuthorLevel" select="$AuthorLevel"/>
  471. <xsl:with-param name="AffilLevel" select="$AffilLevel"/>
  472. <xsl:with-param name="AddressLevel" select="0"/>
  473. </xsl:call-template>
  474. </affiliation>
  475. </xsl:if>
  476. </xsl:template>
  477. <xsl:template name="Orgname">
  478. <xsl:param name="AuthorLevel"/>
  479. <xsl:param name="AffilLevel"/>
  480. <xsl:param name="OrgLevel"/>
  481. <xsl:variable name="Author">
  482. <xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
  483. </xsl:variable>
  484. <xsl:variable name="Affil">
  485. <xsl:value-of select="concat($Author,'',concat('.affiliation_','',$AffilLevel))"/>
  486. </xsl:variable>
  487. <xsl:variable name="Org">
  488. <xsl:value-of select="concat($Affil,'',concat('.orgname_','',$OrgLevel))"/>
  489. </xsl:variable>
  490. <xsl:if test="text:p/text:variable-set[@text:name=$Org]">
  491. <orgname>
  492. <xsl:value-of select="text:p/text:variable-set[@text:name=$Org]"/>
  493. </orgname>
  494. </xsl:if>
  495. </xsl:template>
  496. <xsl:template name="Address">
  497. <xsl:param name="AuthorLevel"/>
  498. <xsl:param name="AffilLevel"/>
  499. <xsl:param name="AddressLevel"/>
  500. <xsl:variable name="Author">
  501. <xsl:value-of select="concat('articleinfo.author_','', $AuthorLevel)"/>
  502. </xsl:variable>
  503. <xsl:variable name="Affil">
  504. <xsl:value-of select="concat($Author,'',concat('.affiliation_','',$AffilLevel))"/>
  505. </xsl:variable>
  506. <xsl:variable name="Address">
  507. <xsl:value-of select="concat($Affil,'',concat('.address_','',$AddressLevel))"/>
  508. </xsl:variable>
  509. <xsl:if test="text:p/text:variable-set[@text:name=$Address]">
  510. <address>
  511. <xsl:value-of select="text:p/text:variable-set[@text:name=$Address]"/>
  512. </address>
  513. </xsl:if>
  514. </xsl:template>
  515. <xsl:template match="text:p[@text:style-name='Document Title']"></xsl:template>
  516. <xsl:template match="text:p[@text:style-name='Document SubTitle']"></xsl:template>
  517. <xsl:template match="text:p[@text:style-name='Section Title']">
  518. <xsl:element name="title">
  519. <xsl:apply-templates/>
  520. </xsl:element>
  521. </xsl:template>
  522. <xsl:template match="text:p[@text:style-name='Appendix Title']">
  523. <xsl:element name="title">
  524. <xsl:apply-templates/>
  525. </xsl:element>
  526. </xsl:template>
  527. <!--<xsl:template match="text:p[@text:style-name='VarList Item']">
  528. <xsl:if test="not(preceding-sibling::text:p[@text:style-name='VarList Item'])">
  529. <xsl:text disable-output-escaping="yes">&lt;listitem&gt;</xsl:text>
  530. </xsl:if>
  531. <para>
  532. <xsl:apply-templates/>
  533. </para>
  534. <xsl:if test="not(following-sibling::text:p[@text:style-name='VarList Item'])">
  535. <xsl:text disable-output-escaping="yes">&lt;/listitem&gt;</xsl:text>
  536. </xsl:if>
  537. </xsl:template>-->
  538. <xsl:template match="text:p[@text:style-name='Section1 Title']">
  539. <xsl:element name="title">
  540. <xsl:apply-templates/>
  541. </xsl:element>
  542. </xsl:template>
  543. <xsl:template match="text:p[@text:style-name='Section2 Title']">
  544. <xsl:element name="title">
  545. <xsl:apply-templates/>
  546. </xsl:element>
  547. </xsl:template>
  548. <xsl:template match="text:p[@text:style-name='Section3 Title']">
  549. <xsl:element name="title">
  550. <xsl:apply-templates/>
  551. </xsl:element>
  552. </xsl:template>
  553. <xsl:template match="text:footnote-citation"></xsl:template>
  554. <xsl:template match="text:p[@text:style-name='Mediaobject']">
  555. <mediaobject>
  556. <xsl:apply-templates/>
  557. </mediaobject>
  558. </xsl:template>
  559. <xsl:template match="office:annotation/text:p">
  560. <note>
  561. <remark>
  562. <xsl:apply-templates/>
  563. </remark>
  564. </note>
  565. </xsl:template>
  566. <!--<xsl:template match="meta:initial-creator">
  567. <author>
  568. <xsl:apply-templates />
  569. </author>
  570. </xsl:template>-->
  571. <xsl:template match="table:table">
  572. <xsl:choose>
  573. <xsl:when test="following-sibling::text:p[@text:style-name='Table']">
  574. <table frame="all">
  575. <xsl:attribute name="id">
  576. <xsl:value-of select="@table:name"/>
  577. </xsl:attribute>
  578. <title>
  579. <xsl:value-of select="following-sibling::text:p[@text:style-name='Table']"/>
  580. </title>
  581. <xsl:call-template name="generictable"/>
  582. </table>
  583. </xsl:when>
  584. <xsl:otherwise>
  585. <informaltable frame="all">
  586. <xsl:call-template name="generictable"/>
  587. </informaltable>
  588. </xsl:otherwise>
  589. </xsl:choose>
  590. </xsl:template>
  591. <xsl:template name="generictable">
  592. <xsl:variable name="cells" select="count(descendant::table:table-cell)"></xsl:variable>
  593. <xsl:variable name="rows">
  594. <xsl:value-of select="count(descendant::table:table-row)"/>
  595. </xsl:variable>
  596. <xsl:variable name="cols">
  597. <xsl:value-of select="$cells div $rows"/>
  598. </xsl:variable>
  599. <xsl:variable name="numcols">
  600. <xsl:choose>
  601. <xsl:when test="child::table:table-column/@table:number-columns-repeated">
  602. <xsl:value-of select="number(table:table-column/@table:number-columns-repeated+1)"/>
  603. </xsl:when>
  604. <xsl:otherwise>
  605. <xsl:value-of select="$cols"/>
  606. </xsl:otherwise>
  607. </xsl:choose>
  608. </xsl:variable>
  609. <xsl:element name="tgroup">
  610. <xsl:attribute name="cols">
  611. <xsl:value-of select="$numcols"/>
  612. </xsl:attribute>
  613. <xsl:call-template name="colspec">
  614. <xsl:with-param name="left" select="1"/>
  615. </xsl:call-template>
  616. <xsl:apply-templates/>
  617. </xsl:element>
  618. </xsl:template>
  619. <xsl:template name="colspec">
  620. <xsl:param name="left"/>
  621. <xsl:if test="number($left &lt; ( table:table-column/@table:number-columns-repeated +2) )">
  622. <xsl:element name="colspec">
  623. <xsl:attribute name="colnum">
  624. <xsl:value-of select="$left"/>
  625. </xsl:attribute>
  626. <xsl:attribute name="colname">c<xsl:value-of select="$left"/>
  627. </xsl:attribute>
  628. </xsl:element>
  629. <xsl:call-template name="colspec">
  630. <xsl:with-param name="left" select="$left+1"/>
  631. </xsl:call-template>
  632. </xsl:if>
  633. </xsl:template>
  634. <xsl:template match="table:table-column">
  635. <xsl:apply-templates/>
  636. </xsl:template>
  637. <xsl:template match="table:table-header-rows">
  638. <thead>
  639. <xsl:apply-templates/>
  640. </thead>
  641. </xsl:template>
  642. <xsl:template match="table:table-header-rows/table:table-row">
  643. <row>
  644. <xsl:apply-templates/>
  645. </row>
  646. </xsl:template>
  647. <xsl:template match="table:table/table:table-row">
  648. <xsl:if test="not(preceding-sibling::table:table-row)">
  649. <xsl:text disable-output-escaping="yes">&lt;tbody&gt;</xsl:text>
  650. </xsl:if>
  651. <row>
  652. <xsl:apply-templates/>
  653. </row>
  654. <xsl:if test="not(following-sibling::table:table-row)">
  655. <xsl:text disable-output-escaping="yes">&lt;/tbody&gt;</xsl:text>
  656. </xsl:if>
  657. </xsl:template>
  658. <xsl:template match="table:table-cell">
  659. <xsl:element name="entry">
  660. <xsl:if test="@table:number-columns-spanned >'1'">
  661. <xsl:attribute name="namest">
  662. <xsl:value-of select="concat('c',count(preceding-sibling::table:table-cell[not(@table:number-columns-spanned)]) +sum(preceding-sibling::table:table-cell/@table:number-columns-spanned)+1)"/>
  663. </xsl:attribute>
  664. <xsl:attribute name="nameend">
  665. <xsl:value-of select="concat('c',count(preceding-sibling::table:table-cell[not(@table:number-columns-spanned)]) +sum(preceding-sibling::table:table-cell/@table:number-columns-spanned)+ @table:number-columns-spanned)"/>
  666. </xsl:attribute>
  667. </xsl:if>
  668. <xsl:apply-templates/>
  669. </xsl:element>
  670. </xsl:template>
  671. <xsl:template match="text:p">
  672. <xsl:choose>
  673. <xsl:when test="@text:style-name='Table'"></xsl:when>
  674. <xsl:otherwise>
  675. <para>
  676. <xsl:apply-templates/>
  677. </para>
  678. </xsl:otherwise>
  679. </xsl:choose>
  680. </xsl:template>
  681. <xsl:key match="text:list-style" name="getListStyle" use="@style:name"/>
  682. <xsl:template match="text:ordered-list">
  683. <xsl:param name="outlineLevel" select="1"/>
  684. <xsl:variable name="listStyle" select="key('getListStyle', @text:style-name)/*[@text:level = $outlineLevel]"/>
  685. <!-- if the list is not recognizable as a list (e.g. no indent, number/bullet, etc.) the list will be ignored -->
  686. <xsl:if test="$listStyle/style:properties/@*">
  687. <orderedlist>
  688. <xsl:apply-templates>
  689. <xsl:with-param name="itemType" select="'listitem'"/>
  690. <xsl:with-param name="outlineLevel" select="$outlineLevel + 1"/>
  691. </xsl:apply-templates>
  692. </orderedlist>
  693. </xsl:if>
  694. </xsl:template>
  695. <xsl:template match="text:unordered-list">
  696. <xsl:param name="outlineLevel" select="1"/>
  697. <xsl:variable name="listStyle" select="key('getListStyle', @text:style-name)/*[@text:level = $outlineLevel]"/>
  698. <!-- if the list is not recognizable as a list (e.g. no indent, number/bullet, etc.) the list will be ignored -->
  699. <xsl:if test="$listStyle/style:properties/@*">
  700. <xsl:choose>
  701. <xsl:when test="@text:style-name='Var List'">
  702. <variablelist>
  703. <xsl:apply-templates>
  704. <xsl:with-param name="itemType" select="'varlist'"/>
  705. <xsl:with-param name="outlineLevel" select="$outlineLevel + 1"/>
  706. </xsl:apply-templates>
  707. </variablelist>
  708. </xsl:when>
  709. <xsl:otherwise>
  710. <itemizedlist>
  711. <xsl:apply-templates>
  712. <xsl:with-param name="itemType" select="'listitem'"/>
  713. <xsl:with-param name="outlineLevel" select="$outlineLevel + 1"/>
  714. </xsl:apply-templates>
  715. </itemizedlist>
  716. </xsl:otherwise>
  717. </xsl:choose>
  718. </xsl:if>
  719. </xsl:template>
  720. <xsl:template match="text:list-item | text:list-header">
  721. <xsl:param name="listType"/>
  722. <xsl:param name="outlineLevel"/>
  723. <xsl:choose>
  724. <xsl:when test="$listType='Var List'">
  725. <xsl:element name="varlistentry">
  726. <xsl:apply-templates>
  727. <xsl:with-param name="outlineLevel" select="$outlineLevel"/>
  728. </xsl:apply-templates>
  729. </xsl:element>
  730. </xsl:when>
  731. <xsl:otherwise>
  732. <xsl:element name="listitem">
  733. <xsl:apply-templates>
  734. <xsl:with-param name="outlineLevel" select="$outlineLevel"/>
  735. </xsl:apply-templates>
  736. </xsl:element>
  737. </xsl:otherwise>
  738. </xsl:choose>
  739. </xsl:template>
  740. <xsl:template match="text:p[@text:style-name='VarList Term']">
  741. <xsl:element name="term">
  742. <xsl:apply-templates/>
  743. </xsl:element>
  744. </xsl:template>
  745. <xsl:template match="text:p[@text:style-name='VarList Item']">
  746. <xsl:element name="para">
  747. <xsl:apply-templates/>
  748. </xsl:element>
  749. </xsl:template>
  750. <!-- text headings should only be matched once, when creating a nested docbook section structure, but might be as well become as part of a list a title -->
  751. <xsl:template match="text:h">
  752. <title>
  753. <xsl:apply-templates/>
  754. </title>
  755. </xsl:template>
  756. <xsl:template match="dc:title"></xsl:template>
  757. <xsl:template match="dc:description">
  758. <abstract>
  759. <para>
  760. <xsl:apply-templates/>
  761. </para>
  762. </abstract>
  763. </xsl:template>
  764. <xsl:template match="dc:subject"></xsl:template>
  765. <xsl:template match="meta:generator"></xsl:template>
  766. <xsl:template match="draw:plugin">
  767. <xsl:element name="audioobject">
  768. <xsl:attribute name="fileref">
  769. <xsl:value-of select="@xlink:href"/>
  770. </xsl:attribute>
  771. <xsl:attribute name="width"></xsl:attribute>
  772. </xsl:element>
  773. </xsl:template>
  774. <xsl:template match="text:footnote">
  775. <footnote>
  776. <xsl:apply-templates/>
  777. </footnote>
  778. </xsl:template>
  779. <xsl:template match="text:footnote-body">
  780. <xsl:apply-templates/>
  781. </xsl:template>
  782. <xsl:template match="draw:text-box"></xsl:template>
  783. <xsl:template match="draw:image">
  784. <xsl:choose>
  785. <xsl:when test="parent::text:p[@text:style-name='Mediaobject']">
  786. <xsl:element name="imageobject">
  787. <xsl:element name="imagedata">
  788. <xsl:attribute name="fileref">
  789. <xsl:value-of select="@xlink:href"/>
  790. </xsl:attribute>
  791. </xsl:element>
  792. <xsl:element name="caption">
  793. <xsl:value-of select="."/>
  794. </xsl:element>
  795. </xsl:element>
  796. </xsl:when>
  797. <xsl:otherwise>
  798. <xsl:element name="inlinegraphic">
  799. <xsl:attribute name="fileref">
  800. <xsl:choose>
  801. <xsl:when test="@xlink:href != ''">
  802. <xsl:value-of select="@xlink:href"/>
  803. </xsl:when>
  804. <xsl:otherwise>
  805. <xsl:text>embedded:</xsl:text>
  806. <xsl:value-of select="@draw:name"/>
  807. </xsl:otherwise>
  808. </xsl:choose>
  809. </xsl:attribute>
  810. <xsl:attribute name="width">
  811. <xsl:value-of select="@svg:width"/>
  812. </xsl:attribute>
  813. <xsl:attribute name="depth">
  814. <xsl:value-of select="@svg:height"/>
  815. </xsl:attribute>
  816. </xsl:element>
  817. </xsl:otherwise>
  818. </xsl:choose>
  819. </xsl:template>
  820. <xsl:template match="text:span">
  821. <xsl:choose>
  822. <xsl:when test="./@text:style-name='GuiMenu'">
  823. <xsl:element name="guimenu">
  824. <xsl:value-of select="."/>
  825. </xsl:element>
  826. </xsl:when>
  827. <xsl:when test="./@text:style-name='GuiSubMenu'">
  828. <xsl:element name="guisubmenu">
  829. <xsl:value-of select="."/>
  830. </xsl:element>
  831. </xsl:when>
  832. <xsl:when test="@text:style-name='GuiMenuItem'">
  833. <xsl:element name="guimenuitem">
  834. <xsl:value-of select="."/>
  835. </xsl:element>
  836. </xsl:when>
  837. <xsl:when test="@text:style-name='GuiButton'">
  838. <xsl:element name="guibutton">
  839. <xsl:value-of select="."/>
  840. </xsl:element>
  841. </xsl:when>
  842. <xsl:when test="@text:style-name='GuiButton'">
  843. <xsl:element name="guibutton">
  844. <xsl:value-of select="."/>
  845. </xsl:element>
  846. </xsl:when>
  847. <xsl:when test="@text:style-name='GuiLabel'">
  848. <xsl:element name="guilabel">
  849. <xsl:value-of select="."/>
  850. </xsl:element>
  851. </xsl:when>
  852. <xsl:when test="@text:style-name='Emphasis'">
  853. <xsl:element name="emphasis">
  854. <xsl:value-of select="."/>
  855. </xsl:element>
  856. </xsl:when>
  857. <xsl:when test="@text:style-name='FileName'">
  858. <xsl:element name="filename">
  859. <xsl:value-of select="."/>
  860. </xsl:element>
  861. </xsl:when>
  862. <xsl:when test="@text:style-name='Application'">
  863. <xsl:element name="application">
  864. <xsl:value-of select="."/>
  865. </xsl:element>
  866. </xsl:when>
  867. <xsl:when test="@text:style-name='Command'">
  868. <command>
  869. <xsl:apply-templates/>
  870. </command>
  871. </xsl:when>
  872. <xsl:when test="@text:style-name='SubScript'">
  873. <subscript>
  874. <xsl:apply-templates/>
  875. </subscript>
  876. </xsl:when>
  877. <xsl:when test="@text:style-name='SuperScript'">
  878. <superscript>
  879. <xsl:apply-templates/>
  880. </superscript>
  881. </xsl:when>
  882. <xsl:when test="@text:style-name='SystemItem'">
  883. <systemitem>
  884. <xsl:apply-templates/>
  885. </systemitem>
  886. </xsl:when>
  887. <xsl:when test="@text:style-name='ComputerOutput'">
  888. <computeroutput>
  889. <xsl:apply-templates/>
  890. </computeroutput>
  891. </xsl:when>
  892. <xsl:when test="@text:style-name='Highlight'">
  893. <highlight>
  894. <xsl:apply-templates/>
  895. </highlight>
  896. </xsl:when>
  897. <xsl:when test="@text:style-name='KeyCap'">
  898. <keycap>
  899. <xsl:apply-templates/>
  900. </keycap>
  901. </xsl:when>
  902. <xsl:when test="@text:style-name='KeySym'">
  903. <xsl:element name="keysym">
  904. <xsl:apply-templates/>
  905. </xsl:element>
  906. </xsl:when>
  907. <xsl:when test="@text:style-name='KeyCombo'">
  908. <keycombo>
  909. <xsl:apply-templates/>
  910. </keycombo>
  911. </xsl:when>
  912. <xsl:otherwise>
  913. <xsl:apply-templates/>
  914. </xsl:otherwise>
  915. </xsl:choose>
  916. </xsl:template>
  917. <xsl:template match="text:a">
  918. <xsl:choose>
  919. <xsl:when test="contains(@xlink:href,'://')">
  920. <xsl:element name="ulink">
  921. <xsl:attribute name="url">
  922. <xsl:value-of select="@xlink:href"/>
  923. </xsl:attribute>
  924. <xsl:apply-templates/>
  925. </xsl:element>
  926. </xsl:when>
  927. <xsl:when test="contains(@xlink:href,'mailto:')">
  928. <xsl:element name="ulink">
  929. <xsl:attribute name="url">
  930. <xsl:value-of select="@xlink:href"/>
  931. </xsl:attribute>
  932. <xsl:apply-templates/>
  933. </xsl:element>
  934. </xsl:when>
  935. <xsl:when test="not(contains(@xlink:href,'#'))">
  936. <xsl:element name="olink">
  937. <xsl:attribute name="targetdocent">
  938. <xsl:value-of select="@xlink:href"/>
  939. </xsl:attribute>
  940. <xsl:apply-templates/>
  941. </xsl:element>
  942. </xsl:when>
  943. <xsl:otherwise>
  944. <xsl:variable name="linkvar" select="substring-after(@xlink:href,'#')"/>
  945. <xsl:element name="link">
  946. <xsl:attribute name="linkend">
  947. <xsl:value-of select="substring-before($linkvar,'%')"/>
  948. </xsl:attribute>
  949. <xsl:apply-templates/>
  950. </xsl:element>
  951. </xsl:otherwise>
  952. </xsl:choose>
  953. </xsl:template>
  954. <!--
  955. Change Made By Kevin Fowlks (fowlks@msu.edu) July 2nd, 2003
  956. This allows users to create example code in DocBook.
  957. Note: This type of grouping could also be implemented for
  958. <notes>,<literallayout>, <blockquote> or any other tag that requires text to be treated as blocked.
  959. -->
  960. <xsl:template match="text:p[@text:style-name='Example']">
  961. <xsl:if test="not(preceding-sibling::*[1][self::text:p[@text:style-name='Example']])">
  962. <xsl:element name="example">
  963. <xsl:element name="title"></xsl:element>
  964. <xsl:element name="programlisting">
  965. <xsl:value-of select="."/>
  966. <xsl:text disable-output-escaping="no">&#xD;</xsl:text>
  967. <xsl:apply-templates mode="in-list" select="following-sibling::*[1][self::text:p[@text:style-name='Example']]"/>
  968. </xsl:element>
  969. </xsl:element>
  970. </xsl:if>
  971. </xsl:template>
  972. <xsl:template match="text:p[@text:style-name='Example']" mode="in-list">
  973. <xsl:value-of select="."/>
  974. <xsl:text disable-output-escaping="no">&#xD;</xsl:text>
  975. <xsl:apply-templates mode="in-list" select="following-sibling::*[1][self::text:p[@text:style-name='Example']]"/>
  976. </xsl:template>
  977. <!-- ****************** -->
  978. <!-- *** Whitespace *** -->
  979. <!-- ****************** -->
  980. <xsl:template match="text:s">
  981. <xsl:call-template name="write-breakable-whitespace">
  982. <xsl:with-param name="whitespaces" select="@text:c"/>
  983. </xsl:call-template>
  984. </xsl:template>
  985. <!--write the number of 'whitespaces' -->
  986. <xsl:template name="write-breakable-whitespace">
  987. <xsl:param name="whitespaces"/>
  988. <!--write two space chars as the normal white space character will be stripped
  989. and the other is able to break -->
  990. <xsl:text>&#160;</xsl:text>
  991. <xsl:if test="$whitespaces >= 2">
  992. <xsl:call-template name="write-breakable-whitespace-2">
  993. <xsl:with-param name="whitespaces" select="$whitespaces - 1"/>
  994. </xsl:call-template>
  995. </xsl:if>
  996. </xsl:template>
  997. <!--write the number of 'whitespaces' -->
  998. <xsl:template name="write-breakable-whitespace-2">
  999. <xsl:param name="whitespaces"/>
  1000. <!--write two space chars as the normal white space character will be stripped
  1001. and the other is able to break -->
  1002. <xsl:text> </xsl:text>
  1003. <xsl:if test="$whitespaces >= 2">
  1004. <xsl:call-template name="write-breakable-whitespace">
  1005. <xsl:with-param name="whitespaces" select="$whitespaces - 1"/>
  1006. </xsl:call-template>
  1007. </xsl:if>
  1008. </xsl:template>
  1009. <xsl:template match="text:tab-stop">
  1010. <xsl:call-template name="write-breakable-whitespace">
  1011. <xsl:with-param name="whitespaces" select="8"/>
  1012. </xsl:call-template>
  1013. </xsl:template>
  1014. </xsl:stylesheet>