graphics.xsl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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$
  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="$passivetex.extensions != 0">
  31. <xsl:text> PNG PDF JPG JPEG linespecific </xsl:text>
  32. </xsl:when>
  33. <xsl:when test="$fop1.extensions != 0">
  34. <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
  35. </xsl:when>
  36. <xsl:when test="$fop.extensions != 0">
  37. <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
  38. </xsl:when>
  39. <xsl:when test="$arbortext.extensions != 0">
  40. <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
  41. </xsl:when>
  42. <xsl:when test="$xep.extensions != 0">
  43. <xsl:text> SVG PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
  44. </xsl:when>
  45. <xsl:otherwise>
  46. <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
  47. </xsl:otherwise>
  48. </xsl:choose>
  49. </xsl:param>
  50. <xsl:template name="is.graphic.format">
  51. <xsl:param name="format"/>
  52. <xsl:if test="contains($graphic.notations, concat(' ',$format,' '))">1</xsl:if>
  53. </xsl:template>
  54. <xsl:param name="graphic.extensions">
  55. <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
  56. <xsl:choose>
  57. <xsl:when test="$passivetex.extensions != 0">
  58. <xsl:text> png pdf jpg jpeg </xsl:text>
  59. </xsl:when>
  60. <xsl:when test="$fop1.extensions != 0">
  61. <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
  62. </xsl:when>
  63. <xsl:when test="$fop.extensions != 0">
  64. <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
  65. </xsl:when>
  66. <xsl:when test="$arbortext.extensions != 0">
  67. <xsl:text> png pdf jpg jpeg gif tif tiff bmp </xsl:text>
  68. </xsl:when>
  69. <xsl:when test="$xep.extensions != 0">
  70. <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
  71. </xsl:when>
  72. <xsl:otherwise>
  73. <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
  74. </xsl:otherwise>
  75. </xsl:choose>
  76. </xsl:param>
  77. <xsl:template name="is.graphic.extension">
  78. <xsl:param name="ext"/>
  79. <xsl:variable name="lcext" select="translate($ext,
  80. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  81. 'abcdefghijklmnopqrstuvwxyz')"/>
  82. <xsl:if test="contains($graphic.extensions,
  83. concat(' ', $lcext, ' '))">1</xsl:if>
  84. </xsl:template>
  85. <xsl:template name="graphic.format.content-type">
  86. <xsl:param name="format"/>
  87. <xsl:variable name="is.graphic.format">
  88. <xsl:call-template name="is.graphic.format">
  89. <xsl:with-param name="format" select="$format"/>
  90. </xsl:call-template>
  91. </xsl:variable>
  92. <xsl:if test="$is.graphic.format">
  93. <xsl:choose>
  94. <xsl:when test="$format = ''"></xsl:when>
  95. <xsl:when test="$format = 'linespecific'"></xsl:when>
  96. <xsl:when test="$format = 'PS'">application/postscript</xsl:when>
  97. <xsl:when test="$format = 'PDF'">application/pdf</xsl:when>
  98. <xsl:when test="$format = 'PNG'">image/png</xsl:when>
  99. <xsl:when test="$format = 'SVG'">image/svg+xml</xsl:when>
  100. <xsl:when test="$format = 'JPG'">image/jpeg</xsl:when>
  101. <xsl:when test="$format = 'GIF87a'">image/gif</xsl:when>
  102. <xsl:when test="$format = 'GIF89a'">image/gif</xsl:when>
  103. <xsl:otherwise>
  104. <xsl:value-of select="concat('image/',
  105. translate($format, &uppercase;, &lowercase;))"/>
  106. </xsl:otherwise>
  107. </xsl:choose>
  108. </xsl:if>
  109. </xsl:template>
  110. <!-- ==================================================================== -->
  111. <xsl:template match="screenshot">
  112. <fo:block>
  113. <xsl:apply-templates/>
  114. </fo:block>
  115. </xsl:template>
  116. <xsl:template match="screeninfo">
  117. </xsl:template>
  118. <!-- ==================================================================== -->
  119. <!-- Override these templates for FO -->
  120. <!-- ==================================================================== -->
  121. <xsl:template name="process.image">
  122. <!-- When this template is called, the current node should be -->
  123. <!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
  124. <!-- those elements have the same set of attributes, so we can -->
  125. <!-- handle them all in one place. -->
  126. <xsl:variable name="scalefit">
  127. <xsl:choose>
  128. <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
  129. <xsl:when test="@contentwidth">0</xsl:when>
  130. <xsl:when test="@contentdepth and
  131. @contentdepth != '100%'">0</xsl:when>
  132. <xsl:when test="@scale">0</xsl:when>
  133. <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
  134. <xsl:when test="@width or @depth">1</xsl:when>
  135. <xsl:otherwise>0</xsl:otherwise>
  136. </xsl:choose>
  137. </xsl:variable>
  138. <xsl:variable name="scale">
  139. <xsl:choose>
  140. <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
  141. <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
  142. <xsl:when test="@scale">
  143. <xsl:value-of select="@scale div 100.0"/>
  144. </xsl:when>
  145. <xsl:otherwise>1.0</xsl:otherwise>
  146. </xsl:choose>
  147. </xsl:variable>
  148. <xsl:variable name="filename">
  149. <xsl:choose>
  150. <xsl:when test="local-name(.) = 'graphic'
  151. or local-name(.) = 'inlinegraphic'">
  152. <!-- handle legacy graphic and inlinegraphic by new template -->
  153. <xsl:call-template name="mediaobject.filename">
  154. <xsl:with-param name="object" select="."/>
  155. </xsl:call-template>
  156. </xsl:when>
  157. <xsl:otherwise>
  158. <!-- imagedata, videodata, audiodata -->
  159. <xsl:call-template name="mediaobject.filename">
  160. <xsl:with-param name="object" select=".."/>
  161. </xsl:call-template>
  162. </xsl:otherwise>
  163. </xsl:choose>
  164. </xsl:variable>
  165. <xsl:variable name="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:variable>
  172. <xsl:variable name="bgcolor">
  173. <xsl:call-template name="pi.dbfo_background-color">
  174. <xsl:with-param name="node" select=".."/>
  175. </xsl:call-template>
  176. </xsl:variable>
  177. <fo:external-graphic>
  178. <xsl:attribute name="src">
  179. <xsl:call-template name="fo-external-image">
  180. <xsl:with-param name="filename">
  181. <xsl:if test="$img.src.path != '' and
  182. not(starts-with($filename, '/')) and
  183. not(contains($filename, '://'))">
  184. <xsl:value-of select="$img.src.path"/>
  185. </xsl:if>
  186. <xsl:value-of select="$filename"/>
  187. </xsl:with-param>
  188. </xsl:call-template>
  189. </xsl:attribute>
  190. <xsl:attribute name="width">
  191. <xsl:choose>
  192. <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
  193. <xsl:when test="contains(@width,'%')">
  194. <xsl:value-of select="@width"/>
  195. </xsl:when>
  196. <xsl:when test="@width and not(@width = '')">
  197. <xsl:call-template name="length-spec">
  198. <xsl:with-param name="length" select="@width"/>
  199. <xsl:with-param name="default.units" select="'px'"/>
  200. </xsl:call-template>
  201. </xsl:when>
  202. <xsl:when test="not(@depth) and $default.image.width != ''">
  203. <xsl:call-template name="length-spec">
  204. <xsl:with-param name="length" select="$default.image.width"/>
  205. <xsl:with-param name="default.units" select="'px'"/>
  206. </xsl:call-template>
  207. </xsl:when>
  208. <xsl:otherwise>auto</xsl:otherwise>
  209. </xsl:choose>
  210. </xsl:attribute>
  211. <xsl:attribute name="height">
  212. <xsl:choose>
  213. <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
  214. <xsl:when test="contains(@depth,'%')">
  215. <xsl:value-of select="@depth"/>
  216. </xsl:when>
  217. <xsl:when test="@depth">
  218. <xsl:call-template name="length-spec">
  219. <xsl:with-param name="length" select="@depth"/>
  220. <xsl:with-param name="default.units" select="'px'"/>
  221. </xsl:call-template>
  222. </xsl:when>
  223. <xsl:otherwise>auto</xsl:otherwise>
  224. </xsl:choose>
  225. </xsl:attribute>
  226. <xsl:attribute name="content-width">
  227. <xsl:choose>
  228. <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
  229. <xsl:when test="contains(@contentwidth,'%')">
  230. <xsl:value-of select="@contentwidth"/>
  231. </xsl:when>
  232. <xsl:when test="@contentwidth">
  233. <xsl:call-template name="length-spec">
  234. <xsl:with-param name="length" select="@contentwidth"/>
  235. <xsl:with-param name="default.units" select="'px'"/>
  236. </xsl:call-template>
  237. </xsl:when>
  238. <xsl:when test="number($scale) != 1.0">
  239. <xsl:value-of select="$scale * 100"/>
  240. <xsl:text>%</xsl:text>
  241. </xsl:when>
  242. <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
  243. <xsl:otherwise>auto</xsl:otherwise>
  244. </xsl:choose>
  245. </xsl:attribute>
  246. <xsl:attribute name="content-height">
  247. <xsl:choose>
  248. <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
  249. <xsl:when test="contains(@contentdepth,'%')">
  250. <xsl:value-of select="@contentdepth"/>
  251. </xsl:when>
  252. <xsl:when test="@contentdepth">
  253. <xsl:call-template name="length-spec">
  254. <xsl:with-param name="length" select="@contentdepth"/>
  255. <xsl:with-param name="default.units" select="'px'"/>
  256. </xsl:call-template>
  257. </xsl:when>
  258. <xsl:when test="number($scale) != 1.0">
  259. <xsl:value-of select="$scale * 100"/>
  260. <xsl:text>%</xsl:text>
  261. </xsl:when>
  262. <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
  263. <xsl:otherwise>auto</xsl:otherwise>
  264. </xsl:choose>
  265. </xsl:attribute>
  266. <xsl:if test="$content-type != ''">
  267. <xsl:attribute name="content-type">
  268. <xsl:value-of select="concat('content-type:',$content-type)"/>
  269. </xsl:attribute>
  270. </xsl:if>
  271. <xsl:if test="$bgcolor != ''">
  272. <xsl:attribute name="background-color">
  273. <xsl:value-of select="$bgcolor"/>
  274. </xsl:attribute>
  275. </xsl:if>
  276. <xsl:if test="@align">
  277. <xsl:attribute name="text-align">
  278. <xsl:value-of select="@align"/>
  279. </xsl:attribute>
  280. </xsl:if>
  281. <xsl:if test="@valign">
  282. <xsl:attribute name="display-align">
  283. <xsl:choose>
  284. <xsl:when test="@valign = 'top'">before</xsl:when>
  285. <xsl:when test="@valign = 'middle'">center</xsl:when>
  286. <xsl:when test="@valign = 'bottom'">after</xsl:when>
  287. <xsl:otherwise>auto</xsl:otherwise>
  288. </xsl:choose>
  289. </xsl:attribute>
  290. </xsl:if>
  291. </fo:external-graphic>
  292. </xsl:template>
  293. <!-- ==================================================================== -->
  294. <xsl:template match="graphic">
  295. <xsl:choose>
  296. <xsl:when test="parent::inlineequation">
  297. <xsl:call-template name="process.image"/>
  298. </xsl:when>
  299. <xsl:otherwise>
  300. <fo:block>
  301. <xsl:if test="@align">
  302. <xsl:attribute name="text-align">
  303. <xsl:value-of select="@align"/>
  304. </xsl:attribute>
  305. </xsl:if>
  306. <xsl:call-template name="process.image"/>
  307. </fo:block>
  308. </xsl:otherwise>
  309. </xsl:choose>
  310. </xsl:template>
  311. <xsl:template match="inlinegraphic">
  312. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  313. <xsl:variable name="filename">
  314. <xsl:choose>
  315. <xsl:when test="@entityref">
  316. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  317. </xsl:when>
  318. <xsl:otherwise>
  319. <xsl:apply-templates select="@fileref"/>
  320. </xsl:otherwise>
  321. </xsl:choose>
  322. </xsl:variable>
  323. <xsl:choose>
  324. <xsl:when test="@format='linespecific'">
  325. <xsl:choose>
  326. <xsl:when test="$use.extensions != '0'
  327. and $textinsert.extension != '0'">
  328. <xsl:choose>
  329. <xsl:when test="contains($vendor, 'SAXON')">
  330. <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
  331. </xsl:when>
  332. <xsl:when test="contains($vendor, 'Apache Software Foundation')">
  333. <xtext:insertfile href="{$filename}"/>
  334. </xsl:when>
  335. <xsl:otherwise>
  336. <xsl:message terminate="yes">
  337. <xsl:text>Don't know how to insert files with </xsl:text>
  338. <xsl:value-of select="$vendor"/>
  339. </xsl:message>
  340. </xsl:otherwise>
  341. </xsl:choose>
  342. </xsl:when>
  343. <xsl:otherwise>
  344. <xsl:message terminate="yes">
  345. <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
  346. <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
  347. </xsl:message>
  348. </xsl:otherwise>
  349. </xsl:choose>
  350. </xsl:when>
  351. <xsl:otherwise>
  352. <xsl:call-template name="process.image"/>
  353. </xsl:otherwise>
  354. </xsl:choose>
  355. </xsl:template>
  356. <!-- ==================================================================== -->
  357. <xsl:template match="mediaobject|mediaobjectco">
  358. <xsl:variable name="olist" select="imageobject|imageobjectco
  359. |videoobject|audioobject
  360. |textobject"/>
  361. <xsl:variable name="object.index">
  362. <xsl:call-template name="select.mediaobject.index">
  363. <xsl:with-param name="olist" select="$olist"/>
  364. <xsl:with-param name="count" select="1"/>
  365. </xsl:call-template>
  366. </xsl:variable>
  367. <xsl:variable name="object" select="$olist[position() = $object.index]"/>
  368. <xsl:variable name="align">
  369. <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
  370. </xsl:variable>
  371. <xsl:variable name="id">
  372. <xsl:call-template name="object.id"/>
  373. </xsl:variable>
  374. <fo:block id="{$id}">
  375. <xsl:if test="$align != '' ">
  376. <xsl:attribute name="text-align">
  377. <xsl:value-of select="$align"/>
  378. </xsl:attribute>
  379. </xsl:if>
  380. <xsl:apply-templates select="$object"/>
  381. <xsl:apply-templates select="caption"/>
  382. </fo:block>
  383. </xsl:template>
  384. <xsl:template match="inlinemediaobject">
  385. <xsl:call-template name="select.mediaobject"/>
  386. </xsl:template>
  387. <!-- ==================================================================== -->
  388. <xsl:template match="imageobjectco">
  389. <xsl:apply-templates select="imageobject"/>
  390. <xsl:apply-templates select="calloutlist"/>
  391. </xsl:template>
  392. <xsl:template match="imageobject">
  393. <xsl:choose>
  394. <xsl:when test="imagedata">
  395. <xsl:apply-templates select="imagedata"/>
  396. </xsl:when>
  397. <xsl:otherwise>
  398. <fo:instream-foreign-object>
  399. <xsl:apply-templates mode="copy-all"/>
  400. </fo:instream-foreign-object>
  401. </xsl:otherwise>
  402. </xsl:choose>
  403. </xsl:template>
  404. <!-- ==================================================================== -->
  405. <xsl:template match="*" mode="copy-all">
  406. <xsl:copy>
  407. <xsl:for-each select="@*">
  408. <xsl:copy/>
  409. </xsl:for-each>
  410. <xsl:apply-templates mode="copy-all"/>
  411. </xsl:copy>
  412. </xsl:template>
  413. <xsl:template match="text()|comment()|processing-instruction()" mode="copy-all">
  414. <xsl:copy/>
  415. </xsl:template>
  416. <!-- ==================================================================== -->
  417. <xsl:template match="imagedata">
  418. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  419. <xsl:variable name="filename">
  420. <xsl:call-template name="mediaobject.filename">
  421. <xsl:with-param name="object" select=".."/>
  422. </xsl:call-template>
  423. </xsl:variable>
  424. <xsl:choose>
  425. <xsl:when test="@format='linespecific'">
  426. <xsl:choose>
  427. <xsl:when test="$use.extensions != '0'
  428. and $textinsert.extension != '0'">
  429. <xsl:choose>
  430. <xsl:when test="contains($vendor, 'SAXON')">
  431. <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
  432. </xsl:when>
  433. <xsl:when test="contains($vendor, 'Apache Software Foundation')">
  434. <xtext:insertfile href="{$filename}"/>
  435. </xsl:when>
  436. <xsl:otherwise>
  437. <xsl:message terminate="yes">
  438. <xsl:text>Don't know how to insert files with </xsl:text>
  439. <xsl:value-of select="$vendor"/>
  440. </xsl:message>
  441. </xsl:otherwise>
  442. </xsl:choose>
  443. </xsl:when>
  444. <xsl:otherwise>
  445. <xsl:message terminate="yes">
  446. <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
  447. <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
  448. </xsl:message>
  449. </xsl:otherwise>
  450. </xsl:choose>
  451. </xsl:when>
  452. <xsl:otherwise>
  453. <xsl:call-template name="process.image"/>
  454. </xsl:otherwise>
  455. </xsl:choose>
  456. </xsl:template>
  457. <!-- ==================================================================== -->
  458. <xsl:template match="videoobject">
  459. <xsl:apply-templates select="videodata"/>
  460. </xsl:template>
  461. <xsl:template match="videodata">
  462. <xsl:call-template name="process.image"/>
  463. </xsl:template>
  464. <!-- ==================================================================== -->
  465. <xsl:template match="audioobject">
  466. <xsl:apply-templates select="audiodata"/>
  467. </xsl:template>
  468. <xsl:template match="audiodata">
  469. <xsl:call-template name="process.image"/>
  470. </xsl:template>
  471. <!-- ==================================================================== -->
  472. <xsl:template match="textobject">
  473. <xsl:apply-templates/>
  474. </xsl:template>
  475. <xsl:template match="textdata">
  476. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  477. <xsl:variable name="filename">
  478. <xsl:choose>
  479. <xsl:when test="@entityref">
  480. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  481. </xsl:when>
  482. <xsl:otherwise>
  483. <xsl:apply-templates select="@fileref"/>
  484. </xsl:otherwise>
  485. </xsl:choose>
  486. </xsl:variable>
  487. <xsl:variable name="encoding">
  488. <xsl:choose>
  489. <xsl:when test="@encoding">
  490. <xsl:value-of select="@encoding"/>
  491. </xsl:when>
  492. <xsl:otherwise>
  493. <xsl:value-of select="$textdata.default.encoding"/>
  494. </xsl:otherwise>
  495. </xsl:choose>
  496. </xsl:variable>
  497. <xsl:choose>
  498. <xsl:when test="$use.extensions != '0'
  499. and $textinsert.extension != '0'">
  500. <xsl:choose>
  501. <xsl:when test="element-available('stext:insertfile')">
  502. <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
  503. </xsl:when>
  504. <xsl:when test="element-available('xtext:insertfile')">
  505. <xtext:insertfile href="{$filename}"/>
  506. </xsl:when>
  507. <xsl:otherwise>
  508. <xsl:message terminate="yes">
  509. <xsl:text>Don't know how to insert files with </xsl:text>
  510. <xsl:value-of select="$vendor"/>
  511. </xsl:message>
  512. </xsl:otherwise>
  513. </xsl:choose>
  514. </xsl:when>
  515. <xsl:otherwise>
  516. <xsl:message terminate="yes">
  517. <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
  518. <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
  519. </xsl:message>
  520. </xsl:otherwise>
  521. </xsl:choose>
  522. </xsl:template>
  523. <!-- ==================================================================== -->
  524. <xsl:template match="caption">
  525. <fo:block>
  526. <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
  527. <xsl:attribute name="text-align"><xsl:value-of
  528. select="@align"/></xsl:attribute>
  529. </xsl:if>
  530. <xsl:apply-templates/>
  531. </fo:block>
  532. </xsl:template>
  533. <!-- ==================================================================== -->
  534. <xsl:template name="fo-external-image">
  535. <xsl:param name="filename"/>
  536. <xsl:choose>
  537. <xsl:when test="$passivetex.extensions != 0
  538. or $fop.extensions != 0">
  539. <xsl:value-of select="$filename"/>
  540. </xsl:when>
  541. <xsl:otherwise>
  542. <xsl:value-of select="concat('url(', $filename, ')')"/>
  543. </xsl:otherwise>
  544. </xsl:choose>
  545. </xsl:template>
  546. <!-- Resolve xml:base attributes -->
  547. <xsl:template match="@fileref">
  548. <!-- need a check for absolute urls -->
  549. <xsl:choose>
  550. <xsl:when test="contains(., ':') or starts-with(.,'/')">
  551. <!-- it has a uri scheme or starts with '/', so it is an absolute uri -->
  552. <xsl:value-of select="."/>
  553. </xsl:when>
  554. <xsl:when test="$keep.relative.image.uris != 0">
  555. <!-- leave it alone -->
  556. <xsl:value-of select="."/>
  557. </xsl:when>
  558. <xsl:otherwise>
  559. <!-- its a relative uri -->
  560. <xsl:call-template name="relative-uri">
  561. </xsl:call-template>
  562. </xsl:otherwise>
  563. </xsl:choose>
  564. </xsl:template>
  565. </xsl:stylesheet>