body.xsl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--***********************************************************
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one
  5. * or more contributor license agreements. See the NOTICE file
  6. * distributed with this work for additional information
  7. * regarding copyright ownership. The ASF licenses this file
  8. * to you under the Apache License, Version 2.0 (the
  9. * "License"); you may not use this file except in compliance
  10. * with the License. You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing,
  15. * software distributed under the License is distributed on an
  16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. * KIND, either express or implied. See the License for the
  18. * specific language governing permissions and limitations
  19. * under the License.
  20. *
  21. ***********************************************************-->
  22. <!--
  23. For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
  24. -->
  25. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://xml.apache.org/xslt/java" xmlns:urlencoder="http://www.jclark.com/xt/java/java.net.URLEncoder" exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xforms xlink xsd xsi java urlencoder">
  26. <xsl:include href="table_of_content.xsl"/>
  27. <!-- ****************** -->
  28. <!-- *** Whitespace *** -->
  29. <!-- ****************** -->
  30. <xsl:template match="text:s">
  31. <xsl:call-template name="write-breakable-whitespace">
  32. <xsl:with-param name="whitespaces" select="@text:c"/>
  33. </xsl:call-template>
  34. </xsl:template>
  35. <!--write the number of 'whitespaces' -->
  36. <xsl:template name="write-breakable-whitespace">
  37. <xsl:param name="whitespaces"/>
  38. <!--write two space chars as the normal white space character will be stripped
  39. and the other is able to break -->
  40. <xsl:text>&#160;</xsl:text>
  41. <xsl:if test="$whitespaces >= 2">
  42. <xsl:call-template name="write-breakable-whitespace-2">
  43. <xsl:with-param name="whitespaces" select="$whitespaces - 1"/>
  44. </xsl:call-template>
  45. </xsl:if>
  46. </xsl:template>
  47. <!--write the number of 'whitespaces' -->
  48. <xsl:template name="write-breakable-whitespace-2">
  49. <xsl:param name="whitespaces"/>
  50. <!--write two space chars as the normal white space character will be stripped
  51. and the other is able to break -->
  52. <xsl:text> </xsl:text>
  53. <xsl:if test="$whitespaces >= 2">
  54. <xsl:call-template name="write-breakable-whitespace">
  55. <xsl:with-param name="whitespaces" select="$whitespaces - 1"/>
  56. </xsl:call-template>
  57. </xsl:if>
  58. </xsl:template>
  59. <!-- currentSolution: 8 non-breakable-spaces instead of a TAB is an approximation.
  60. Sometimes less spaces than 8 might be needed and the output might be more difficult to read-->
  61. <xsl:template match="text:tab">
  62. <xsl:param name="globalData"/>
  63. <xsl:call-template name="write-breakable-whitespace">
  64. <xsl:with-param name="whitespaces" select="8"/>
  65. </xsl:call-template>
  66. </xsl:template>
  67. <!-- *************** -->
  68. <!-- *** Textbox *** -->
  69. <!-- *************** -->
  70. <!-- ID / NAME of text-box -->
  71. <xsl:template match="@draw:name">
  72. <xsl:attribute name="id">
  73. <xsl:choose>
  74. <xsl:when test="number(substring(.,1,1))">
  75. <!-- Heuristic: If the first character is a number a 'a_' will be set
  76. as prefix, as id have to be of type NMTOKEN -->
  77. <xsl:value-of select="concat('a_',translate(., '&#xA;&amp;&lt;&gt;.,;: %()[]/\+', '___________________________'))"/>
  78. </xsl:when>
  79. <xsl:otherwise>
  80. <xsl:value-of select="translate(., '&#xA;&amp;&lt;&gt;.,;: %()[]/\+', '___________________________')"/>
  81. </xsl:otherwise>
  82. </xsl:choose>
  83. </xsl:attribute>
  84. </xsl:template>
  85. <xsl:template match="text:line-break">
  86. <xsl:param name="listIndent"/>
  87. <xsl:element namespace="{$namespace}" name="br"/>
  88. <!-- line breaks in lists need an indent similar to the list label -->
  89. <xsl:if test="$listIndent">
  90. <xsl:element namespace="{$namespace}" name="span">
  91. <xsl:attribute name="style">margin-left:<xsl:value-of select="$listIndent"/>cm</xsl:attribute>
  92. </xsl:element>
  93. </xsl:if>
  94. </xsl:template>
  95. <!-- currently there have to be an explicit call of the style attribute nodes, maybe the attributes nodes have no priority only order relevant-->
  96. <xsl:template name="apply-styles-and-content">
  97. <xsl:param name="globalData"/>
  98. <xsl:param name="footnotePrefix" />
  99. <xsl:apply-templates select="@*">
  100. <xsl:with-param name="globalData" select="$globalData"/>
  101. </xsl:apply-templates>
  102. <!-- the footnote symbol is the prefix for a footnote in the footer -->
  103. <xsl:copy-of select="$footnotePrefix"/>
  104. <xsl:apply-templates select="node()">
  105. <xsl:with-param name="globalData" select="$globalData"/>
  106. </xsl:apply-templates>
  107. </xsl:template>
  108. <!-- ******************* -->
  109. <!-- *** References *** -->
  110. <!-- ******************* -->
  111. <xsl:template match="text:reference-ref | text:sequence-ref">
  112. <xsl:param name="globalData"/>
  113. <xsl:element namespace="{$namespace}" name="a">
  114. <xsl:attribute name="href">
  115. <xsl:text>#</xsl:text>
  116. <xsl:choose>
  117. <xsl:when test="number(substring(@text:ref-name,1,1))">
  118. <!-- Heuristic: If the first character is a number a 'a_' will be set
  119. as prefix, as id have to be of type NMTOKEN -->
  120. <xsl:value-of select="concat('a_',translate(@text:ref-name, '&#xA;&amp;&lt;&gt;.,;: %()[]/\+', '___________________________'))"/>
  121. </xsl:when>
  122. <xsl:otherwise>
  123. <xsl:value-of select="translate(@text:ref-name, '&#xA;&amp;&lt;&gt;.,;: %()[]/\+', '___________________________')"/>
  124. </xsl:otherwise>
  125. </xsl:choose>
  126. </xsl:attribute>
  127. <xsl:apply-templates select="@* | node()">
  128. <xsl:with-param name="globalData" select="$globalData"/>
  129. </xsl:apply-templates>
  130. </xsl:element>
  131. </xsl:template>
  132. <xsl:template match="@text:name">
  133. <xsl:attribute name="id">
  134. <xsl:choose>
  135. <xsl:when test="number(substring(.,1,1))">
  136. <!-- Heuristic: If the first character is a number a 'a_' will be set
  137. as prefix, as id have to be of type NMTOKEN -->
  138. <xsl:value-of select="concat('a_',translate(., '&#xA;&amp;&lt;&gt;.,;: %()[]/\+', '___________________________'))"/>
  139. </xsl:when>
  140. <xsl:otherwise>
  141. <xsl:value-of select="translate(., '&#xA;&amp;&lt;&gt;.,;: %()[]/\+', '___________________________')"/>
  142. </xsl:otherwise>
  143. </xsl:choose>
  144. </xsl:attribute>
  145. </xsl:template>
  146. <xsl:template match="text:sequence">
  147. <xsl:param name="globalData"/>
  148. <xsl:element namespace="{$namespace}" name="a">
  149. <xsl:apply-templates select="@*" />
  150. <xsl:attribute name="id">
  151. <xsl:choose>
  152. <xsl:when test="number(substring(@text:ref-name,1,1))">
  153. <!-- Heuristic: If the first character is a number a 'a_' will be set
  154. as prefix, as id have to be of type NMTOKEN -->
  155. <xsl:value-of select="concat('a_',translate(@text:ref-name, '&#xA;&amp;&lt;&gt;.,;: %()[]/\+', '___________________________'))"/>
  156. </xsl:when>
  157. <xsl:otherwise>
  158. <xsl:value-of select="translate(@text:ref-name, '&#xA;&amp;&lt;&gt;.,;: %()[]/\+', '___________________________')"/>
  159. </xsl:otherwise>
  160. </xsl:choose>
  161. </xsl:attribute>
  162. </xsl:element>
  163. <xsl:apply-templates>
  164. <xsl:with-param name="globalData" select="$globalData"/>
  165. </xsl:apply-templates>
  166. </xsl:template>
  167. <xsl:template match="text:reference-mark">
  168. <xsl:param name="globalData"/>
  169. <xsl:element namespace="{$namespace}" name="a">
  170. <xsl:apply-templates select="@*" />
  171. <xsl:attribute name="id">
  172. <xsl:choose>
  173. <xsl:when test="number(substring(@text:name,1,1))">
  174. <!-- Heuristic: If the first character is a number a 'a_' will be set
  175. as prefix, as id have to be of type NMTOKEN -->
  176. <xsl:value-of select="concat('a_',translate(@text:name, '&#xA;&amp;&lt;&gt;.,;: %()[]/\+', '___________________________'))"/>
  177. </xsl:when>
  178. <xsl:otherwise>
  179. <xsl:value-of select="translate(@text:name, '&#xA;&amp;&lt;&gt;.,;: %()[]/\+', '___________________________')"/>
  180. </xsl:otherwise>
  181. </xsl:choose>
  182. </xsl:attribute>
  183. </xsl:element>
  184. <xsl:apply-templates>
  185. <xsl:with-param name="globalData" select="$globalData"/>
  186. </xsl:apply-templates>
  187. </xsl:template>
  188. <xsl:template match="text:reference-mark-start">
  189. <xsl:param name="globalData"/>
  190. <xsl:element namespace="{$namespace}" name="a">
  191. <xsl:apply-templates select="@*" />
  192. </xsl:element>
  193. </xsl:template>
  194. <xsl:template match="text:bibliography-mark">
  195. <xsl:param name="globalData"/>
  196. <xsl:element namespace="{$namespace}" name="a">
  197. <xsl:apply-templates select="@* | node()">
  198. <xsl:with-param name="globalData" select="$globalData"/>
  199. </xsl:apply-templates>
  200. </xsl:element>
  201. </xsl:template>
  202. <!-- @text:title exist only in text:bibliography-mark -->
  203. <xsl:template match="@text:title">
  204. <xsl:attribute name="title">
  205. <xsl:value-of select="."/>
  206. </xsl:attribute>
  207. </xsl:template>
  208. <!-- @text:url exist only in text:bibliography-mark -->
  209. <xsl:template match="@text:url">
  210. <xsl:attribute name="href">
  211. <xsl:value-of select="."/>
  212. </xsl:attribute>
  213. </xsl:template>
  214. <xsl:template match="text:user-defined">
  215. <xsl:apply-templates/>
  216. </xsl:template>
  217. <xsl:template match="office:annotation">
  218. <xsl:element name="span">
  219. <xsl:attribute name="title">annotation</xsl:attribute>
  220. <xsl:attribute name="class">annotation_style_by_filter</xsl:attribute>
  221. <xsl:apply-templates select="@*" />
  222. <br/>
  223. <xsl:text>[ANNOTATION:</xsl:text>
  224. <br/>
  225. <xsl:apply-templates select="*" mode="annotation"/>
  226. <xsl:text>]</xsl:text>
  227. </xsl:element>
  228. </xsl:template>
  229. <xsl:template match="text:p" mode="annotation">
  230. <br/>
  231. <xsl:element name="span">
  232. <xsl:text>NOTE: '</xsl:text>
  233. <xsl:apply-templates />
  234. <xsl:text>'</xsl:text>
  235. </xsl:element>
  236. </xsl:template>
  237. <xsl:template match="dc:creator" mode="annotation">
  238. <br/>
  239. <xsl:element name="span">
  240. <xsl:attribute name="title">dc:creator</xsl:attribute>
  241. <xsl:text>BY '</xsl:text>
  242. <xsl:apply-templates />
  243. <xsl:text>'</xsl:text>
  244. </xsl:element>
  245. </xsl:template>
  246. <xsl:template match="dc:date" mode="annotation">
  247. <br/>
  248. <xsl:element name="span">
  249. <xsl:attribute name="title">dc:date</xsl:attribute>
  250. <xsl:text>ON '</xsl:text>
  251. <xsl:apply-templates />
  252. <xsl:text>'</xsl:text>
  253. </xsl:element>
  254. </xsl:template>
  255. <xsl:template match="meta:date-string" mode="annotation">
  256. <br/>
  257. <xsl:element name="span">
  258. <xsl:attribute name="title">meta-date-string</xsl:attribute>
  259. <xsl:text>META DATE '</xsl:text>
  260. <xsl:apply-templates />
  261. <xsl:text>'</xsl:text>
  262. </xsl:element>
  263. </xsl:template>
  264. <!-- *************** -->
  265. <!-- *** HELPER *** -->
  266. <!-- *************** -->
  267. <xsl:template name="create-href">
  268. <xsl:param name="href"/>
  269. <xsl:choose>
  270. <!-- internal OOo URL used in content tables -->
  271. <xsl:when test="contains($href, '%7Coutline')">
  272. <!-- the simple workaround for content tables in a single document is to create create an anchor from every heading element
  273. work-around downside: Multiple identical headings won't refer always to the first.
  274. -->
  275. <xsl:text>#</xsl:text>
  276. <xsl:variable name="title">
  277. <xsl:apply-templates mode="concatenate"/>
  278. </xsl:variable>
  279. <xsl:value-of select="concat('a_', translate(normalize-space($title), '.,;: %()[]/\+', '_____________'))"/>
  280. </xsl:when>
  281. <xsl:when test="self::draw:image[office:binary-data]">
  282. <xsl:text>data:image/*;base64,</xsl:text><xsl:value-of select="office:binary-data"/>
  283. </xsl:when>
  284. <xsl:otherwise>
  285. <xsl:choose>
  286. <!-- in case of packed open office document -->
  287. <xsl:when test="starts-with($sourceBaseURL, 'jar:') or $isPackageFormat">
  288. <xsl:choose>
  289. <!-- for images relative to open office document -->
  290. <xsl:when test="starts-with($href, '../')">
  291. <!-- creating an absolute http URL to the packed image file (removing the '.')-->
  292. <xsl:value-of select="concat(substring-after(substring-before($sourceBaseURL, '!'), 'jar:'), '/', $href, $optionalURLSuffix)"/>
  293. </xsl:when>
  294. <!-- for absolute URLs & absolute paths -->
  295. <xsl:when test="contains($href, ':') or starts-with($href, '/')">
  296. <xsl:value-of select="concat($href, $optionalURLSuffix)"/>
  297. </xsl:when>
  298. <!-- for images jared in open office document -->
  299. <xsl:otherwise>
  300. <xsl:value-of select="concat($sourceBaseURL, $href, $optionalURLSuffix)"/>
  301. </xsl:otherwise>
  302. </xsl:choose>
  303. </xsl:when>
  304. <xsl:otherwise>
  305. <xsl:choose>
  306. <!-- for absolute URLs & Paths -->
  307. <xsl:when test="contains($href, ':') or starts-with($href, '/')">
  308. <xsl:value-of select="concat($href, $optionalURLSuffix)"/>
  309. </xsl:when>
  310. <!-- for relative URLs -->
  311. <xsl:otherwise>
  312. <xsl:value-of select="concat($sourceBaseURL, $href, $optionalURLSuffix)"/>
  313. </xsl:otherwise>
  314. </xsl:choose>
  315. </xsl:otherwise>
  316. </xsl:choose>
  317. </xsl:otherwise>
  318. </xsl:choose>
  319. </xsl:template>
  320. <xsl:template match="text()" mode="concatenate">
  321. <xsl:value-of select="."/>
  322. </xsl:template>
  323. <xsl:template match="*" mode="concatenate">
  324. <xsl:apply-templates mode="concatenate"/>
  325. </xsl:template>
  326. <!-- ******************** -->
  327. <!-- *** Common Rules *** -->
  328. <!-- ******************** -->
  329. <!-- ignore / neglect the following elements -->
  330. <xsl:template match="draw:custom-shape | draw:g | office:forms | text:alphabetical-index-mark | text:alphabetical-index-mark-end | text:alphabetical-index-mark-start | text:bibliography-source | text:number | text:reference-mark-end | text:sequence-decls | text:soft-page-break | text:table-of-content-source | text:tracked-changes | text:user-field-decls"/>
  331. <!-- default template used by purpose-->
  332. <xsl:template match="text:bibliography | text:change-end | text:change-start">
  333. <xsl:param name="globalData"/>
  334. <xsl:apply-templates>
  335. <xsl:with-param name="globalData" select="$globalData"/>
  336. </xsl:apply-templates>
  337. </xsl:template>
  338. <!-- default template for not recognized elements -->
  339. <xsl:template match="*">
  340. <xsl:param name="globalData"/>
  341. <xsl:message>Using default element rule for ODF element '<xsl:value-of select="name()"/>'.</xsl:message>
  342. <xsl:apply-templates>
  343. <xsl:with-param name="globalData" select="$globalData"/>
  344. </xsl:apply-templates>
  345. </xsl:template>
  346. <xsl:template match="@*"/>
  347. <!-- allowing all matched text nodes -->
  348. <xsl:template match="text()">
  349. <xsl:value-of select="."/>
  350. </xsl:template>
  351. </xsl:stylesheet>