graphics.xsl 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. <?xml version='1.0'?>
  2. <!DOCTYPE xsl:stylesheet [
  3. <!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
  4. <!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
  5. ]>
  6. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  8. xmlns:xlink="http://www.w3.org/1999/xlink"
  9. xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
  10. xmlns:xtext="com.nwalsh.xalan.Text"
  11. xmlns:lxslt="http://xml.apache.org/xslt"
  12. exclude-result-prefixes="xlink stext xtext lxslt"
  13. extension-element-prefixes="stext xtext"
  14. version='1.0'>
  15. <!-- ********************************************************************
  16. $Id: graphics.xsl 9647 2012-10-26 17:42:03Z bobstayton $
  17. ********************************************************************
  18. This file is part of the XSL DocBook Stylesheet distribution.
  19. See ../README or http://docbook.sf.net/release/xsl/current/ for
  20. copyright and other information.
  21. Contributors:
  22. Colin Paul Adams, <colin@colina.demon.co.uk>
  23. Paul Grosso, <pgrosso@arbortext.com>
  24. ******************************************************************** -->
  25. <!-- ==================================================================== -->
  26. <!-- Graphic format tests for the FO backend -->
  27. <xsl:param name="graphic.notations">
  28. <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
  29. <xsl:choose>
  30. <xsl:when test="$fop1.extensions != 0">
  31. <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
  32. </xsl:when>
  33. <xsl:when test="$fop.extensions != 0">
  34. <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
  35. </xsl:when>
  36. <xsl:when test="$arbortext.extensions != 0">
  37. <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
  38. </xsl:when>
  39. <xsl:when test="$xep.extensions != 0">
  40. <xsl:text> SVG PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
  41. </xsl:when>
  42. <xsl:otherwise>
  43. <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
  44. </xsl:otherwise>
  45. </xsl:choose>
  46. </xsl:param>
  47. <xsl:template name="is.graphic.format">
  48. <xsl:param name="format"/>
  49. <xsl:if test="contains($graphic.notations, concat(' ',$format,' '))">1</xsl:if>
  50. </xsl:template>
  51. <xsl:param name="graphic.extensions">
  52. <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
  53. <xsl:choose>
  54. <xsl:when test="$fop1.extensions != 0">
  55. <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
  56. </xsl:when>
  57. <xsl:when test="$fop.extensions != 0">
  58. <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
  59. </xsl:when>
  60. <xsl:when test="$arbortext.extensions != 0">
  61. <xsl:text> png pdf jpg jpeg gif tif tiff bmp </xsl:text>
  62. </xsl:when>
  63. <xsl:when test="$xep.extensions != 0">
  64. <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
  65. </xsl:when>
  66. <xsl:otherwise>
  67. <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
  68. </xsl:otherwise>
  69. </xsl:choose>
  70. </xsl:param>
  71. <xsl:template name="is.graphic.extension">
  72. <xsl:param name="ext"/>
  73. <xsl:variable name="lcext" select="translate($ext,
  74. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  75. 'abcdefghijklmnopqrstuvwxyz')"/>
  76. <xsl:if test="contains($graphic.extensions,
  77. concat(' ', $lcext, ' '))">1</xsl:if>
  78. </xsl:template>
  79. <!-- ==================================================================== -->
  80. <xsl:template match="screenshot">
  81. <fo:block>
  82. <xsl:call-template name="anchor"/>
  83. <xsl:apply-templates/>
  84. </fo:block>
  85. </xsl:template>
  86. <xsl:template match="screenshot/title">
  87. <xsl:call-template name="formal.object.heading">
  88. <xsl:with-param name="object" select=".."/>
  89. </xsl:call-template>
  90. </xsl:template>
  91. <xsl:template match="screeninfo">
  92. </xsl:template>
  93. <!-- ==================================================================== -->
  94. <!-- Override these templates for FO -->
  95. <!-- ==================================================================== -->
  96. <xsl:template name="image.scalefit">
  97. <xsl:choose>
  98. <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
  99. <xsl:when test="@contentwidth">0</xsl:when>
  100. <xsl:when test="@contentdepth and
  101. @contentdepth != '100%'">0</xsl:when>
  102. <xsl:when test="@scale">0</xsl:when>
  103. <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
  104. <xsl:when test="@width or @depth">1</xsl:when>
  105. <xsl:when test="$default.image.width != ''">1</xsl:when>
  106. <xsl:otherwise>0</xsl:otherwise>
  107. </xsl:choose>
  108. </xsl:template>
  109. <xsl:template name="image.scale">
  110. <xsl:choose>
  111. <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
  112. <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
  113. <xsl:when test="@scale">
  114. <xsl:value-of select="@scale div 100.0"/>
  115. </xsl:when>
  116. <xsl:otherwise>1.0</xsl:otherwise>
  117. </xsl:choose>
  118. </xsl:template>
  119. <xsl:template name="image.filename">
  120. <xsl:choose>
  121. <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
  122. <!-- no filename for inline SVG content -->
  123. </xsl:when>
  124. <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
  125. <!-- no filename for inline MathML content -->
  126. </xsl:when>
  127. <xsl:when test="local-name(.) = 'graphic'
  128. or local-name(.) = 'inlinegraphic'">
  129. <!-- handle legacy graphic and inlinegraphic by new template -->
  130. <xsl:call-template name="mediaobject.filename">
  131. <xsl:with-param name="object" select="."/>
  132. </xsl:call-template>
  133. </xsl:when>
  134. <xsl:otherwise>
  135. <!-- imagedata, videodata, audiodata -->
  136. <xsl:call-template name="mediaobject.filename">
  137. <xsl:with-param name="object" select=".."/>
  138. </xsl:call-template>
  139. </xsl:otherwise>
  140. </xsl:choose>
  141. </xsl:template>
  142. <xsl:template name="image.src">
  143. <xsl:param name="filename"/>
  144. <xsl:choose>
  145. <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
  146. <!-- no src attribute for inline SVG content -->
  147. </xsl:when>
  148. <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
  149. <!-- no src attribute for inline MathML content -->
  150. </xsl:when>
  151. <xsl:otherwise>
  152. <xsl:call-template name="fo-external-image">
  153. <xsl:with-param name="filename">
  154. <xsl:if test="$img.src.path != '' and
  155. not(starts-with($filename, '/')) and
  156. not(contains($filename, '://'))">
  157. <xsl:value-of select="$img.src.path"/>
  158. </xsl:if>
  159. <xsl:value-of select="$filename"/>
  160. </xsl:with-param>
  161. </xsl:call-template>
  162. </xsl:otherwise>
  163. </xsl:choose>
  164. </xsl:template>
  165. <xsl:template name="image.content.type">
  166. <xsl:if test="@format">
  167. <xsl:call-template name="graphic.format.content-type">
  168. <xsl:with-param name="format" select="@format"/>
  169. </xsl:call-template>
  170. </xsl:if>
  171. </xsl:template>
  172. <xsl:template name="image.bgcolor">
  173. <xsl:call-template name="pi.dbfo_background-color">
  174. <xsl:with-param name="node" select=".."/>
  175. </xsl:call-template>
  176. </xsl:template>
  177. <xsl:template name="image.width">
  178. <xsl:choose>
  179. <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
  180. <xsl:when test="contains(@width,'%')">
  181. <xsl:value-of select="@width"/>
  182. </xsl:when>
  183. <xsl:when test="@width and not(@width = '')">
  184. <xsl:call-template name="length-spec">
  185. <xsl:with-param name="length" select="@width"/>
  186. <xsl:with-param name="default.units" select="'px'"/>
  187. </xsl:call-template>
  188. </xsl:when>
  189. <xsl:when test="not(@depth) and $default.image.width != ''">
  190. <xsl:call-template name="length-spec">
  191. <xsl:with-param name="length" select="$default.image.width"/>
  192. <xsl:with-param name="default.units" select="'px'"/>
  193. </xsl:call-template>
  194. </xsl:when>
  195. <xsl:otherwise>auto</xsl:otherwise>
  196. </xsl:choose>
  197. </xsl:template>
  198. <xsl:template name="image.height">
  199. <xsl:choose>
  200. <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
  201. <xsl:when test="contains(@depth,'%')">
  202. <xsl:value-of select="@depth"/>
  203. </xsl:when>
  204. <xsl:when test="@depth">
  205. <xsl:call-template name="length-spec">
  206. <xsl:with-param name="length" select="@depth"/>
  207. <xsl:with-param name="default.units" select="'px'"/>
  208. </xsl:call-template>
  209. </xsl:when>
  210. <xsl:otherwise>auto</xsl:otherwise>
  211. </xsl:choose>
  212. </xsl:template>
  213. <xsl:template name="image.content.width">
  214. <xsl:param name="scalefit" select="0"/>
  215. <xsl:param name="scale" select="'1.0'"/>
  216. <xsl:choose>
  217. <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
  218. <xsl:when test="contains(@contentwidth,'%')">
  219. <xsl:value-of select="@contentwidth"/>
  220. </xsl:when>
  221. <xsl:when test="@contentwidth">
  222. <xsl:call-template name="length-spec">
  223. <xsl:with-param name="length" select="@contentwidth"/>
  224. <xsl:with-param name="default.units" select="'px'"/>
  225. </xsl:call-template>
  226. </xsl:when>
  227. <xsl:when test="number($scale) != 1.0">
  228. <xsl:value-of select="$scale * 100"/>
  229. <xsl:text>%</xsl:text>
  230. </xsl:when>
  231. <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
  232. <xsl:otherwise>auto</xsl:otherwise>
  233. </xsl:choose>
  234. </xsl:template>
  235. <xsl:template name="image.content.height">
  236. <xsl:param name="scalefit" select="0"/>
  237. <xsl:param name="scale" select="0"/>
  238. <xsl:choose>
  239. <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
  240. <xsl:when test="contains(@contentdepth,'%')">
  241. <xsl:value-of select="@contentdepth"/>
  242. </xsl:when>
  243. <xsl:when test="@contentdepth">
  244. <xsl:call-template name="length-spec">
  245. <xsl:with-param name="length" select="@contentdepth"/>
  246. <xsl:with-param name="default.units" select="'px'"/>
  247. </xsl:call-template>
  248. </xsl:when>
  249. <xsl:when test="number($scale) != 1.0">
  250. <xsl:value-of select="$scale * 100"/>
  251. <xsl:text>%</xsl:text>
  252. </xsl:when>
  253. <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
  254. <xsl:otherwise>auto</xsl:otherwise>
  255. </xsl:choose>
  256. </xsl:template>
  257. <xsl:template name="image.align">
  258. <xsl:value-of select="@align"/>
  259. </xsl:template>
  260. <xsl:template name="image.valign">
  261. <xsl:if test="@valign">
  262. <xsl:choose>
  263. <xsl:when test="ancestor::inlinemediaobject or ancestor-or-self::inlinegraphic">
  264. <xsl:choose>
  265. <xsl:when test="@valign = 'top'">baseline</xsl:when>
  266. <xsl:when test="@valign = 'middle'">central</xsl:when>
  267. <xsl:when test="@valign = 'bottom'">text-before-edge</xsl:when>
  268. </xsl:choose>
  269. </xsl:when>
  270. <xsl:otherwise>
  271. <xsl:choose>
  272. <xsl:when test="@valign = 'top'">before</xsl:when>
  273. <xsl:when test="@valign = 'middle'">center</xsl:when>
  274. <xsl:when test="@valign = 'bottom'">after</xsl:when>
  275. </xsl:choose>
  276. </xsl:otherwise>
  277. </xsl:choose>
  278. </xsl:if>
  279. </xsl:template>
  280. <xsl:template name="process.image">
  281. <!-- When this template is called, the current node should be -->
  282. <!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
  283. <!-- those elements have the same set of attributes, so we can -->
  284. <!-- handle them all in one place. -->
  285. <!-- Compute each attribute value with its own customizable template call -->
  286. <xsl:variable name="scalefit">
  287. <xsl:call-template name="image.scalefit"/>
  288. </xsl:variable>
  289. <xsl:variable name="scale">
  290. <xsl:call-template name="image.scale"/>
  291. </xsl:variable>
  292. <xsl:variable name="filename">
  293. <xsl:call-template name="image.filename"/>
  294. </xsl:variable>
  295. <xsl:variable name="src">
  296. <xsl:call-template name="image.src">
  297. <xsl:with-param name="filename" select="$filename"/>
  298. </xsl:call-template>
  299. </xsl:variable>
  300. <xsl:variable name="content.type">
  301. <xsl:call-template name="image.content.type"/>
  302. </xsl:variable>
  303. <xsl:variable name="bgcolor">
  304. <xsl:call-template name="image.bgcolor"/>
  305. </xsl:variable>
  306. <xsl:variable name="width">
  307. <xsl:call-template name="image.width"/>
  308. </xsl:variable>
  309. <xsl:variable name="height">
  310. <xsl:call-template name="image.height"/>
  311. </xsl:variable>
  312. <xsl:variable name="content.width">
  313. <xsl:call-template name="image.content.width">
  314. <xsl:with-param name="scalefit" select="$scalefit"/>
  315. <xsl:with-param name="scale" select="$scale"/>
  316. </xsl:call-template>
  317. </xsl:variable>
  318. <xsl:variable name="content.height">
  319. <xsl:call-template name="image.content.height">
  320. <xsl:with-param name="scalefit" select="$scalefit"/>
  321. <xsl:with-param name="scale" select="$scale"/>
  322. </xsl:call-template>
  323. </xsl:variable>
  324. <xsl:variable name="align">
  325. <xsl:call-template name="image.align"/>
  326. </xsl:variable>
  327. <xsl:variable name="valign">
  328. <xsl:call-template name="image.valign"/>
  329. </xsl:variable>
  330. <xsl:variable name="element.name">
  331. <xsl:choose>
  332. <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
  333. <xsl:text>fo:instream-foreign-object</xsl:text>
  334. </xsl:when>
  335. <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
  336. <xsl:text>fo:instream-foreign-object</xsl:text>
  337. </xsl:when>
  338. <xsl:otherwise>
  339. <xsl:text>fo:external-graphic</xsl:text>
  340. </xsl:otherwise>
  341. </xsl:choose>
  342. </xsl:variable>
  343. <xsl:element name="{$element.name}">
  344. <xsl:if test="$src != ''">
  345. <xsl:attribute name="src">
  346. <xsl:value-of select="$src"/>
  347. </xsl:attribute>
  348. </xsl:if>
  349. <xsl:if test="$width != ''">
  350. <xsl:attribute name="width">
  351. <xsl:value-of select="$width"/>
  352. </xsl:attribute>
  353. </xsl:if>
  354. <xsl:if test="$height != ''">
  355. <xsl:attribute name="height">
  356. <xsl:value-of select="$height"/>
  357. </xsl:attribute>
  358. </xsl:if>
  359. <xsl:if test="$content.width != ''">
  360. <xsl:attribute name="content-width">
  361. <xsl:value-of select="$content.width"/>
  362. </xsl:attribute>
  363. </xsl:if>
  364. <xsl:if test="$content.height != ''">
  365. <xsl:attribute name="content-height">
  366. <xsl:value-of select="$content.height"/>
  367. </xsl:attribute>
  368. </xsl:if>
  369. <xsl:if test="$content.type != ''">
  370. <xsl:attribute name="content-type">
  371. <xsl:value-of select="concat('content-type:',$content.type)"/>
  372. </xsl:attribute>
  373. </xsl:if>
  374. <xsl:if test="$bgcolor != ''">
  375. <xsl:attribute name="background-color">
  376. <xsl:value-of select="$bgcolor"/>
  377. </xsl:attribute>
  378. </xsl:if>
  379. <xsl:if test="$align != ''">
  380. <xsl:attribute name="text-align">
  381. <xsl:value-of select="$align"/>
  382. </xsl:attribute>
  383. </xsl:if>
  384. <xsl:if test="$valign != ''">
  385. <xsl:variable name="att.name">
  386. <xsl:choose>
  387. <xsl:when test="ancestor::inlinemediaobject or ancestor-or-self::inlinegraphic">
  388. <xsl:text>alignment-baseline</xsl:text>
  389. </xsl:when>
  390. <xsl:otherwise>
  391. <xsl:text>display-align</xsl:text>
  392. </xsl:otherwise>
  393. </xsl:choose>
  394. </xsl:variable>
  395. <xsl:attribute name="{$att.name}">
  396. <xsl:value-of select="$valign"/>
  397. </xsl:attribute>
  398. </xsl:if>
  399. <!-- copy literal SVG elements to output -->
  400. <xsl:if test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
  401. <xsl:call-template name="process.svg"/>
  402. </xsl:if>
  403. <xsl:if test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
  404. <xsl:call-template name="process.mml"/>
  405. </xsl:if>
  406. </xsl:element>
  407. </xsl:template>
  408. <!-- ==================================================================== -->
  409. <xsl:template match="graphic">
  410. <xsl:choose>
  411. <xsl:when test="parent::inlineequation">
  412. <xsl:call-template name="process.image"/>
  413. </xsl:when>
  414. <xsl:otherwise>
  415. <fo:block>
  416. <xsl:call-template name="anchor"/>
  417. <xsl:if test="@align">
  418. <xsl:attribute name="text-align">
  419. <xsl:value-of select="@align"/>
  420. </xsl:attribute>
  421. </xsl:if>
  422. <xsl:call-template name="process.image"/>
  423. </fo:block>
  424. </xsl:otherwise>
  425. </xsl:choose>
  426. </xsl:template>
  427. <xsl:template match="inlinegraphic">
  428. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  429. <xsl:variable name="filename">
  430. <xsl:choose>
  431. <xsl:when test="@entityref">
  432. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  433. </xsl:when>
  434. <xsl:otherwise>
  435. <xsl:apply-templates select="@fileref"/>
  436. </xsl:otherwise>
  437. </xsl:choose>
  438. </xsl:variable>
  439. <xsl:choose>
  440. <xsl:when test="@format='linespecific'">
  441. <xsl:choose>
  442. <xsl:when test="$use.extensions != '0'
  443. and $textinsert.extension != '0'">
  444. <xsl:choose>
  445. <xsl:when test="contains($vendor, 'SAXON')">
  446. <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
  447. </xsl:when>
  448. <xsl:when test="contains($vendor, 'Apache Software Foundation')">
  449. <xtext:insertfile href="{$filename}"/>
  450. </xsl:when>
  451. <xsl:otherwise>
  452. <xsl:message terminate="yes">
  453. <xsl:text>Don't know how to insert files with </xsl:text>
  454. <xsl:value-of select="$vendor"/>
  455. </xsl:message>
  456. </xsl:otherwise>
  457. </xsl:choose>
  458. </xsl:when>
  459. <xsl:otherwise>
  460. <xsl:message terminate="yes">
  461. <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
  462. <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
  463. </xsl:message>
  464. </xsl:otherwise>
  465. </xsl:choose>
  466. </xsl:when>
  467. <xsl:otherwise>
  468. <xsl:call-template name="process.image"/>
  469. </xsl:otherwise>
  470. </xsl:choose>
  471. </xsl:template>
  472. <!-- ==================================================================== -->
  473. <xsl:template match="mediaobject|mediaobjectco">
  474. <xsl:variable name="olist" select="imageobject|imageobjectco
  475. |videoobject|audioobject
  476. |textobject"/>
  477. <xsl:variable name="object.index">
  478. <xsl:call-template name="select.mediaobject.index">
  479. <xsl:with-param name="olist" select="$olist"/>
  480. <xsl:with-param name="count" select="1"/>
  481. </xsl:call-template>
  482. </xsl:variable>
  483. <xsl:variable name="object" select="$olist[position() = $object.index]"/>
  484. <xsl:variable name="align">
  485. <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
  486. </xsl:variable>
  487. <xsl:variable name="id">
  488. <xsl:call-template name="object.id"/>
  489. </xsl:variable>
  490. <fo:block id="{$id}">
  491. <xsl:if test="$align != '' ">
  492. <xsl:attribute name="text-align">
  493. <xsl:value-of select="$align"/>
  494. </xsl:attribute>
  495. </xsl:if>
  496. <xsl:apply-templates select="$object"/>
  497. <xsl:apply-templates select="caption"/>
  498. </fo:block>
  499. </xsl:template>
  500. <xsl:template match="inlinemediaobject">
  501. <xsl:call-template name="select.mediaobject"/>
  502. </xsl:template>
  503. <!-- ==================================================================== -->
  504. <xsl:template match="imageobjectco">
  505. <xsl:choose>
  506. <!-- select one imageobject? -->
  507. <xsl:when test="$use.role.for.mediaobject != 0 and
  508. count(imageobject) &gt; 1 and
  509. imageobject[@role]">
  510. <xsl:variable name="olist" select="imageobject"/>
  511. <xsl:variable name="object.index">
  512. <xsl:call-template name="select.mediaobject.index">
  513. <xsl:with-param name="olist" select="$olist"/>
  514. <xsl:with-param name="count" select="1"/>
  515. </xsl:call-template>
  516. </xsl:variable>
  517. <xsl:variable name="object" select="$olist[position() = $object.index]"/>
  518. <xsl:apply-templates select="$object"/>
  519. </xsl:when>
  520. <xsl:otherwise>
  521. <!-- otherwise process them all -->
  522. <xsl:apply-templates select="imageobject"/>
  523. </xsl:otherwise>
  524. </xsl:choose>
  525. <xsl:apply-templates select="calloutlist"/>
  526. </xsl:template>
  527. <xsl:template match="imageobject">
  528. <xsl:choose>
  529. <xsl:when test="imagedata">
  530. <xsl:apply-templates select="imagedata"/>
  531. </xsl:when>
  532. <xsl:otherwise>
  533. <fo:instream-foreign-object>
  534. <xsl:apply-templates mode="copy-all"/>
  535. </fo:instream-foreign-object>
  536. </xsl:otherwise>
  537. </xsl:choose>
  538. </xsl:template>
  539. <!-- ==================================================================== -->
  540. <xsl:template match="*" mode="copy-all">
  541. <xsl:copy>
  542. <xsl:for-each select="@*">
  543. <xsl:copy/>
  544. </xsl:for-each>
  545. <xsl:apply-templates mode="copy-all"/>
  546. </xsl:copy>
  547. </xsl:template>
  548. <xsl:template match="text()|comment()|processing-instruction()" mode="copy-all">
  549. <xsl:copy/>
  550. </xsl:template>
  551. <xsl:template name="process.mml">
  552. <xsl:apply-templates mode="copy-all" select="*"/>
  553. </xsl:template>
  554. <xsl:template name="process.svg">
  555. <xsl:apply-templates mode="copy-all" select="*"/>
  556. </xsl:template>
  557. <!-- ==================================================================== -->
  558. <xsl:template match="imagedata">
  559. <xsl:choose>
  560. <xsl:when test="@format='linespecific'">
  561. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  562. <xsl:variable name="filename">
  563. <xsl:call-template name="mediaobject.filename">
  564. <xsl:with-param name="object" select=".."/>
  565. </xsl:call-template>
  566. </xsl:variable>
  567. <xsl:choose>
  568. <xsl:when test="$use.extensions != '0'
  569. and $textinsert.extension != '0'">
  570. <xsl:choose>
  571. <xsl:when test="contains($vendor, 'SAXON')">
  572. <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
  573. </xsl:when>
  574. <xsl:when test="contains($vendor, 'Apache Software Foundation')">
  575. <xtext:insertfile href="{$filename}"/>
  576. </xsl:when>
  577. <xsl:otherwise>
  578. <xsl:message terminate="yes">
  579. <xsl:text>Don't know how to insert files with </xsl:text>
  580. <xsl:value-of select="$vendor"/>
  581. </xsl:message>
  582. </xsl:otherwise>
  583. </xsl:choose>
  584. </xsl:when>
  585. <xsl:otherwise>
  586. <xsl:message terminate="yes">
  587. <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
  588. <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
  589. </xsl:message>
  590. </xsl:otherwise>
  591. </xsl:choose>
  592. </xsl:when>
  593. <xsl:otherwise>
  594. <xsl:call-template name="process.image"/>
  595. </xsl:otherwise>
  596. </xsl:choose>
  597. </xsl:template>
  598. <!-- ==================================================================== -->
  599. <xsl:template match="videoobject">
  600. <xsl:apply-templates select="videodata"/>
  601. </xsl:template>
  602. <xsl:template match="videodata">
  603. <xsl:call-template name="process.image"/>
  604. </xsl:template>
  605. <!-- ==================================================================== -->
  606. <xsl:template match="audioobject">
  607. <xsl:apply-templates select="audiodata"/>
  608. </xsl:template>
  609. <xsl:template match="audiodata">
  610. <xsl:call-template name="process.image"/>
  611. </xsl:template>
  612. <!-- ==================================================================== -->
  613. <xsl:template match="textobject">
  614. <xsl:apply-templates/>
  615. </xsl:template>
  616. <xsl:template match="textdata">
  617. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  618. <xsl:variable name="filename">
  619. <xsl:choose>
  620. <xsl:when test="@entityref">
  621. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  622. </xsl:when>
  623. <xsl:otherwise>
  624. <xsl:apply-templates select="@fileref"/>
  625. </xsl:otherwise>
  626. </xsl:choose>
  627. </xsl:variable>
  628. <xsl:variable name="encoding">
  629. <xsl:choose>
  630. <xsl:when test="@encoding">
  631. <xsl:value-of select="@encoding"/>
  632. </xsl:when>
  633. <xsl:otherwise>
  634. <xsl:value-of select="$textdata.default.encoding"/>
  635. </xsl:otherwise>
  636. </xsl:choose>
  637. </xsl:variable>
  638. <xsl:choose>
  639. <xsl:when test="$use.extensions != '0'
  640. and $textinsert.extension != '0'">
  641. <xsl:choose>
  642. <xsl:when test="element-available('stext:insertfile')">
  643. <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
  644. </xsl:when>
  645. <xsl:when test="element-available('xtext:insertfile')">
  646. <xtext:insertfile href="{$filename}"/>
  647. </xsl:when>
  648. <xsl:otherwise>
  649. <xsl:message terminate="yes">
  650. <xsl:text>Don't know how to insert files with </xsl:text>
  651. <xsl:value-of select="$vendor"/>
  652. </xsl:message>
  653. </xsl:otherwise>
  654. </xsl:choose>
  655. </xsl:when>
  656. <xsl:otherwise>
  657. <xsl:message terminate="yes">
  658. <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
  659. <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
  660. </xsl:message>
  661. </xsl:otherwise>
  662. </xsl:choose>
  663. </xsl:template>
  664. <!-- ==================================================================== -->
  665. <xsl:template match="mediaobject/caption|figure/caption">
  666. <fo:block>
  667. <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
  668. <xsl:attribute name="text-align"><xsl:value-of
  669. select="@align"/></xsl:attribute>
  670. </xsl:if>
  671. <xsl:apply-templates/>
  672. </fo:block>
  673. </xsl:template>
  674. <!-- ==================================================================== -->
  675. <xsl:template name="fo-external-image">
  676. <xsl:param name="filename"/>
  677. <xsl:choose>
  678. <xsl:when test="$fop.extensions != 0">
  679. <xsl:value-of select="$filename"/>
  680. </xsl:when>
  681. <xsl:otherwise>
  682. <xsl:value-of select="concat('url(', $filename, ')')"/>
  683. </xsl:otherwise>
  684. </xsl:choose>
  685. </xsl:template>
  686. <!-- Resolve xml:base attributes -->
  687. <xsl:template match="@fileref">
  688. <!-- need a check for absolute urls -->
  689. <xsl:choose>
  690. <xsl:when test="contains(., ':') or starts-with(.,'/')">
  691. <!-- it has a uri scheme or starts with '/', so it is an absolute uri -->
  692. <xsl:value-of select="."/>
  693. </xsl:when>
  694. <xsl:when test="$keep.relative.image.uris != 0">
  695. <!-- leave it alone -->
  696. <xsl:value-of select="."/>
  697. </xsl:when>
  698. <xsl:otherwise>
  699. <!-- its a relative uri -->
  700. <xsl:call-template name="relative-uri">
  701. </xsl:call-template>
  702. </xsl:otherwise>
  703. </xsl:choose>
  704. </xsl:template>
  705. </xsl:stylesheet>