graphics.xsl 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  1. <?xml version="1.0" encoding="ASCII"?>
  2. <!--This file was created automatically by html2xhtml-->
  3. <!--from the HTML stylesheets.-->
  4. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory" xmlns:simg="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.ImageIntrinsics" xmlns:ximg="xalan://com.nwalsh.xalan.ImageIntrinsics" xmlns:xtext="xalan://com.nwalsh.xalan.Text" xmlns:lxslt="http://xml.apache.org/xslt" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xlink stext xtext lxslt simg ximg" extension-element-prefixes="stext xtext" version="1.0">
  5. <!-- ********************************************************************
  6. $Id$
  7. ********************************************************************
  8. This file is part of the XSL DocBook Stylesheet distribution.
  9. See ../README or http://docbook.sf.net/release/xsl/current/ for
  10. copyright and other information.
  11. Contributors:
  12. Colin Paul Adams, <colin@colina.demon.co.uk>
  13. ******************************************************************** -->
  14. <lxslt:component prefix="xtext" elements="insertfile"/>
  15. <lxslt:component prefix="ximg" functions="new getWidth getDepth"/>
  16. <!-- ==================================================================== -->
  17. <!-- Graphic format tests for the HTML backend -->
  18. <xsl:template name="is.graphic.format">
  19. <xsl:param name="format"/>
  20. <xsl:if test="$format = 'SVG' or $format = 'PNG' or $format = 'JPG' or $format = 'JPEG' or $format = 'linespecific' or $format = 'GIF' or $format = 'GIF87a' or $format = 'GIF89a' or $format = 'BMP'">1</xsl:if>
  21. </xsl:template>
  22. <xsl:template name="is.graphic.extension">
  23. <xsl:param name="ext"/>
  24. <xsl:variable name="lcext" select="translate($ext, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
  25. <xsl:if test="$lcext = 'svg' or $lcext = 'png' or $lcext = 'jpeg' or $lcext = 'jpg' or $lcext = 'avi' or $lcext = 'mpg' or $lcext = 'mpeg' or $lcext = 'qt' or $lcext = 'gif' or $lcext = 'bmp'">1</xsl:if>
  26. </xsl:template>
  27. <!-- ==================================================================== -->
  28. <xsl:template match="screenshot">
  29. <div>
  30. <xsl:apply-templates select="." mode="class.attribute"/>
  31. <xsl:apply-templates/>
  32. </div>
  33. </xsl:template>
  34. <xsl:template match="screeninfo">
  35. </xsl:template>
  36. <!-- ==================================================================== -->
  37. <xsl:template name="process.image">
  38. <!-- When this template is called, the current node should be -->
  39. <!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
  40. <!-- those elements have the same set of attributes, so we can -->
  41. <!-- handle them all in one place. -->
  42. <xsl:param name="tag" select="'img'"/>
  43. <xsl:param name="alt"/>
  44. <xsl:param name="longdesc"/>
  45. <!-- The HTML img element only supports the notion of content-area
  46. scaling; it doesn't support the distinction between a
  47. content-area and a viewport-area, so we have to make some
  48. compromises.
  49. 1. If only the content-area is specified, everything is fine.
  50. (If you ask for a three inch image, that's what you'll get.)
  51. 2. If only the viewport-area is provided:
  52. - If scalefit=1, treat it as both the content-area and
  53. the viewport-area. (If you ask for an image in a five inch
  54. area, we'll make the image five inches to fill that area.)
  55. - If scalefit=0, ignore the viewport-area specification.
  56. Note: this is not quite the right semantic and has the additional
  57. problem that it can result in anamorphic scaling, which scalefit
  58. should never cause.
  59. 3. If both the content-area and the viewport-area is specified
  60. on a graphic element, ignore the viewport-area.
  61. (If you ask for a three inch image in a five inch area, we'll assume
  62. it's better to give you a three inch image in an unspecified area
  63. than a five inch image in a five inch area.
  64. Relative units also cause problems. As a general rule, the stylesheets
  65. are operating too early and too loosely coupled with the rendering engine
  66. to know things like the current font size or the actual dimensions of
  67. an image. Therefore:
  68. 1. We use a fixed size for pixels, $pixels.per.inch
  69. 2. We use a fixed size for "em"s, $points.per.em
  70. Percentages are problematic. In the following discussion, we speak
  71. of width and contentwidth, but the same issues apply to depth and
  72. contentdepth
  73. 1. A width of 50% means "half of the available space for the image."
  74. That's fine. But note that in HTML, this is a dynamic property and
  75. the image size will vary if the browser window is resized.
  76. 2. A contentwidth of 50% means "half of the actual image width". But
  77. the stylesheets have no way to assess the image's actual size. Treating
  78. this as a width of 50% is one possibility, but it produces behavior
  79. (dynamic scaling) that seems entirely out of character with the
  80. meaning.
  81. Instead, the stylesheets define a $nominal.image.width
  82. and convert percentages to actual values based on that nominal size.
  83. Scale can be problematic. Scale applies to the contentwidth, so
  84. a scale of 50 when a contentwidth is not specified is analogous to a
  85. width of 50%. (If a contentwidth is specified, the scaling factor can
  86. be applied to that value and no problem exists.)
  87. If scale is specified but contentwidth is not supplied, the
  88. nominal.image.width is used to calculate a base size
  89. for scaling.
  90. Warning: as a consequence of these decisions, unless the aspect ratio
  91. of your image happens to be exactly the same as (nominal width / nominal height),
  92. specifying contentwidth="50%" and contentdepth="50%" is NOT going to
  93. scale the way you expect (or really, the way it should).
  94. Don't do that. In fact, a percentage value is not recommended for content
  95. size at all. Use scale instead.
  96. Finally, align and valign are troublesome. Horizontal alignment is now
  97. supported by wrapping the image in a <div align="{@align}"> (in block
  98. contexts!). I can't think of anything (practical) to do about vertical
  99. alignment.
  100. -->
  101. <xsl:variable name="width-units">
  102. <xsl:choose>
  103. <xsl:when test="$ignore.image.scaling != 0"/>
  104. <xsl:when test="@width">
  105. <xsl:call-template name="length-units">
  106. <xsl:with-param name="length" select="@width"/>
  107. </xsl:call-template>
  108. </xsl:when>
  109. <xsl:when test="not(@depth) and $default.image.width != ''">
  110. <xsl:call-template name="length-units">
  111. <xsl:with-param name="length" select="$default.image.width"/>
  112. </xsl:call-template>
  113. </xsl:when>
  114. </xsl:choose>
  115. </xsl:variable>
  116. <xsl:variable name="width">
  117. <xsl:choose>
  118. <xsl:when test="$ignore.image.scaling != 0"/>
  119. <xsl:when test="@width">
  120. <xsl:choose>
  121. <xsl:when test="$width-units = '%'">
  122. <xsl:value-of select="@width"/>
  123. </xsl:when>
  124. <xsl:otherwise>
  125. <xsl:call-template name="length-spec">
  126. <xsl:with-param name="length" select="@width"/>
  127. </xsl:call-template>
  128. </xsl:otherwise>
  129. </xsl:choose>
  130. </xsl:when>
  131. <xsl:when test="not(@depth) and $default.image.width != ''">
  132. <xsl:value-of select="$default.image.width"/>
  133. </xsl:when>
  134. </xsl:choose>
  135. </xsl:variable>
  136. <xsl:variable name="scalefit">
  137. <xsl:choose>
  138. <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
  139. <xsl:when test="@contentwidth or @contentdepth">0</xsl:when>
  140. <xsl:when test="@scale">0</xsl:when>
  141. <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
  142. <xsl:when test="$width != '' or @depth">1</xsl:when>
  143. <xsl:otherwise>0</xsl:otherwise>
  144. </xsl:choose>
  145. </xsl:variable>
  146. <xsl:variable name="scale">
  147. <xsl:choose>
  148. <xsl:when test="$ignore.image.scaling != 0">1.0</xsl:when>
  149. <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
  150. <xsl:when test="@scale">
  151. <xsl:value-of select="@scale div 100.0"/>
  152. </xsl:when>
  153. <xsl:otherwise>1.0</xsl:otherwise>
  154. </xsl:choose>
  155. </xsl:variable>
  156. <xsl:variable name="filename">
  157. <xsl:choose>
  158. <xsl:when test="local-name(.) = 'graphic' or local-name(.) = 'inlinegraphic'">
  159. <!-- handle legacy graphic and inlinegraphic by new template -->
  160. <xsl:call-template name="mediaobject.filename">
  161. <xsl:with-param name="object" select="."/>
  162. </xsl:call-template>
  163. </xsl:when>
  164. <xsl:otherwise>
  165. <!-- imagedata, videodata, audiodata -->
  166. <xsl:call-template name="mediaobject.filename">
  167. <xsl:with-param name="object" select=".."/>
  168. </xsl:call-template>
  169. </xsl:otherwise>
  170. </xsl:choose>
  171. </xsl:variable>
  172. <xsl:variable name="output_filename">
  173. <xsl:choose>
  174. <xsl:when test="@entityref">
  175. <xsl:value-of select="$filename"/>
  176. </xsl:when>
  177. <!--
  178. Moved test for $keep.relative.image.uris to template below:
  179. <xsl:template match="@fileref">
  180. -->
  181. <xsl:otherwise>
  182. <xsl:value-of select="$filename"/>
  183. </xsl:otherwise>
  184. </xsl:choose>
  185. </xsl:variable>
  186. <xsl:variable name="img.src.path.pi">
  187. <xsl:call-template name="pi.dbhtml_img.src.path">
  188. <xsl:with-param name="node" select=".."/>
  189. </xsl:call-template>
  190. </xsl:variable>
  191. <xsl:variable name="filename.for.graphicsize">
  192. <xsl:choose>
  193. <xsl:when test="$img.src.path.pi != ''">
  194. <xsl:value-of select="concat($img.src.path.pi, $filename)"/>
  195. </xsl:when>
  196. <xsl:when test="$img.src.path != '' and $graphicsize.use.img.src.path != 0 and $tag = 'img' and not(starts-with($filename, '/')) and not(contains($filename, '://'))">
  197. <xsl:value-of select="concat($img.src.path, $filename)"/>
  198. </xsl:when>
  199. <xsl:otherwise>
  200. <xsl:value-of select="$filename"/>
  201. </xsl:otherwise>
  202. </xsl:choose>
  203. </xsl:variable>
  204. <xsl:variable name="realintrinsicwidth">
  205. <!-- This funny compound test works around a bug in XSLTC -->
  206. <xsl:choose>
  207. <xsl:when test="$use.extensions != 0 and $graphicsize.extension != 0">
  208. <xsl:choose>
  209. <xsl:when test="function-available('simg:getWidth')">
  210. <xsl:value-of select="simg:getWidth(simg:new($filename.for.graphicsize), $nominal.image.width)"/>
  211. </xsl:when>
  212. <xsl:when test="function-available('ximg:getWidth')">
  213. <xsl:value-of select="ximg:getWidth(ximg:new($filename.for.graphicsize), $nominal.image.width)"/>
  214. </xsl:when>
  215. <xsl:otherwise>
  216. <xsl:value-of select="0"/>
  217. </xsl:otherwise>
  218. </xsl:choose>
  219. </xsl:when>
  220. <xsl:otherwise>
  221. <xsl:value-of select="0"/>
  222. </xsl:otherwise>
  223. </xsl:choose>
  224. </xsl:variable>
  225. <xsl:variable name="intrinsicwidth">
  226. <xsl:choose>
  227. <xsl:when test="$realintrinsicwidth = 0">
  228. <xsl:value-of select="$nominal.image.width"/>
  229. </xsl:when>
  230. <xsl:otherwise>
  231. <xsl:value-of select="$realintrinsicwidth"/>
  232. </xsl:otherwise>
  233. </xsl:choose>
  234. </xsl:variable>
  235. <xsl:variable name="intrinsicdepth">
  236. <!-- This funny compound test works around a bug in XSLTC -->
  237. <xsl:choose>
  238. <xsl:when test="$use.extensions != 0 and $graphicsize.extension != 0">
  239. <xsl:choose>
  240. <xsl:when test="function-available('simg:getDepth')">
  241. <xsl:value-of select="simg:getDepth(simg:new($filename.for.graphicsize), $nominal.image.depth)"/>
  242. </xsl:when>
  243. <xsl:when test="function-available('ximg:getDepth')">
  244. <xsl:value-of select="ximg:getDepth(ximg:new($filename.for.graphicsize), $nominal.image.depth)"/>
  245. </xsl:when>
  246. <xsl:otherwise>
  247. <xsl:value-of select="$nominal.image.depth"/>
  248. </xsl:otherwise>
  249. </xsl:choose>
  250. </xsl:when>
  251. <xsl:otherwise>
  252. <xsl:value-of select="$nominal.image.depth"/>
  253. </xsl:otherwise>
  254. </xsl:choose>
  255. </xsl:variable>
  256. <xsl:variable name="contentwidth">
  257. <xsl:choose>
  258. <xsl:when test="$ignore.image.scaling != 0"/>
  259. <xsl:when test="@contentwidth">
  260. <xsl:variable name="units">
  261. <xsl:call-template name="length-units">
  262. <xsl:with-param name="length" select="@contentwidth"/>
  263. </xsl:call-template>
  264. </xsl:variable>
  265. <xsl:choose>
  266. <xsl:when test="$units = '%'">
  267. <xsl:variable name="cmagnitude">
  268. <xsl:call-template name="length-magnitude">
  269. <xsl:with-param name="length" select="@contentwidth"/>
  270. </xsl:call-template>
  271. </xsl:variable>
  272. <xsl:value-of select="$intrinsicwidth * $cmagnitude div 100.0"/>
  273. <xsl:text>px</xsl:text>
  274. </xsl:when>
  275. <xsl:otherwise>
  276. <xsl:call-template name="length-spec">
  277. <xsl:with-param name="length" select="@contentwidth"/>
  278. </xsl:call-template>
  279. </xsl:otherwise>
  280. </xsl:choose>
  281. </xsl:when>
  282. <xsl:otherwise>
  283. <xsl:value-of select="$intrinsicwidth"/>
  284. <xsl:text>px</xsl:text>
  285. </xsl:otherwise>
  286. </xsl:choose>
  287. </xsl:variable>
  288. <xsl:variable name="scaled.contentwidth">
  289. <xsl:if test="$contentwidth != ''">
  290. <xsl:variable name="cwidth.in.points">
  291. <xsl:call-template name="length-in-points">
  292. <xsl:with-param name="length" select="$contentwidth"/>
  293. <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
  294. <xsl:with-param name="em.size" select="$points.per.em"/>
  295. </xsl:call-template>
  296. </xsl:variable>
  297. <xsl:value-of select="$cwidth.in.points div 72.0 * $pixels.per.inch * $scale"/>
  298. </xsl:if>
  299. </xsl:variable>
  300. <xsl:variable name="html.width">
  301. <xsl:choose>
  302. <xsl:when test="$ignore.image.scaling != 0"/>
  303. <xsl:when test="$width-units = '%'">
  304. <xsl:value-of select="$width"/>
  305. </xsl:when>
  306. <xsl:when test="$width != ''">
  307. <xsl:variable name="width.in.points">
  308. <xsl:call-template name="length-in-points">
  309. <xsl:with-param name="length" select="$width"/>
  310. <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
  311. <xsl:with-param name="em.size" select="$points.per.em"/>
  312. </xsl:call-template>
  313. </xsl:variable>
  314. <xsl:value-of select="round($width.in.points div 72.0 * $pixels.per.inch)"/>
  315. </xsl:when>
  316. <xsl:otherwise/>
  317. </xsl:choose>
  318. </xsl:variable>
  319. <xsl:variable name="contentdepth">
  320. <xsl:choose>
  321. <xsl:when test="$ignore.image.scaling != 0"/>
  322. <xsl:when test="@contentdepth">
  323. <xsl:variable name="units">
  324. <xsl:call-template name="length-units">
  325. <xsl:with-param name="length" select="@contentdepth"/>
  326. </xsl:call-template>
  327. </xsl:variable>
  328. <xsl:choose>
  329. <xsl:when test="$units = '%'">
  330. <xsl:variable name="cmagnitude">
  331. <xsl:call-template name="length-magnitude">
  332. <xsl:with-param name="length" select="@contentdepth"/>
  333. </xsl:call-template>
  334. </xsl:variable>
  335. <xsl:value-of select="$intrinsicdepth * $cmagnitude div 100.0"/>
  336. <xsl:text>px</xsl:text>
  337. </xsl:when>
  338. <xsl:otherwise>
  339. <xsl:call-template name="length-spec">
  340. <xsl:with-param name="length" select="@contentdepth"/>
  341. </xsl:call-template>
  342. </xsl:otherwise>
  343. </xsl:choose>
  344. </xsl:when>
  345. <xsl:otherwise>
  346. <xsl:value-of select="$intrinsicdepth"/>
  347. <xsl:text>px</xsl:text>
  348. </xsl:otherwise>
  349. </xsl:choose>
  350. </xsl:variable>
  351. <xsl:variable name="scaled.contentdepth">
  352. <xsl:if test="$contentdepth != ''">
  353. <xsl:variable name="cdepth.in.points">
  354. <xsl:call-template name="length-in-points">
  355. <xsl:with-param name="length" select="$contentdepth"/>
  356. <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
  357. <xsl:with-param name="em.size" select="$points.per.em"/>
  358. </xsl:call-template>
  359. </xsl:variable>
  360. <xsl:value-of select="$cdepth.in.points div 72.0 * $pixels.per.inch * $scale"/>
  361. </xsl:if>
  362. </xsl:variable>
  363. <xsl:variable name="depth-units">
  364. <xsl:if test="@depth">
  365. <xsl:call-template name="length-units">
  366. <xsl:with-param name="length" select="@depth"/>
  367. </xsl:call-template>
  368. </xsl:if>
  369. </xsl:variable>
  370. <xsl:variable name="depth">
  371. <xsl:if test="@depth">
  372. <xsl:choose>
  373. <xsl:when test="$depth-units = '%'">
  374. <xsl:value-of select="@depth"/>
  375. </xsl:when>
  376. <xsl:otherwise>
  377. <xsl:call-template name="length-spec">
  378. <xsl:with-param name="length" select="@depth"/>
  379. </xsl:call-template>
  380. </xsl:otherwise>
  381. </xsl:choose>
  382. </xsl:if>
  383. </xsl:variable>
  384. <xsl:variable name="html.depth">
  385. <xsl:choose>
  386. <xsl:when test="$ignore.image.scaling != 0"/>
  387. <xsl:when test="$depth-units = '%'">
  388. <xsl:value-of select="$depth"/>
  389. </xsl:when>
  390. <xsl:when test="@depth and @depth != ''">
  391. <xsl:variable name="depth.in.points">
  392. <xsl:call-template name="length-in-points">
  393. <xsl:with-param name="length" select="$depth"/>
  394. <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
  395. <xsl:with-param name="em.size" select="$points.per.em"/>
  396. </xsl:call-template>
  397. </xsl:variable>
  398. <xsl:value-of select="round($depth.in.points div 72.0 * $pixels.per.inch)"/>
  399. </xsl:when>
  400. <xsl:otherwise/>
  401. </xsl:choose>
  402. </xsl:variable>
  403. <xsl:variable name="viewport">
  404. <xsl:choose>
  405. <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
  406. <xsl:when test="local-name(.) = 'inlinegraphic' or ancestor::inlinemediaobject or ancestor::inlineequation">0</xsl:when>
  407. <xsl:otherwise>
  408. <xsl:value-of select="$make.graphic.viewport"/>
  409. </xsl:otherwise>
  410. </xsl:choose>
  411. </xsl:variable>
  412. <!--
  413. <xsl:message>=====================================
  414. scale: <xsl:value-of select="$scale"/>, <xsl:value-of select="$scalefit"/>
  415. @contentwidth <xsl:value-of select="@contentwidth"/>
  416. $contentwidth <xsl:value-of select="$contentwidth"/>
  417. scaled.contentwidth: <xsl:value-of select="$scaled.contentwidth"/>
  418. @width: <xsl:value-of select="@width"/>
  419. width: <xsl:value-of select="$width"/>
  420. html.width: <xsl:value-of select="$html.width"/>
  421. @contentdepth <xsl:value-of select="@contentdepth"/>
  422. $contentdepth <xsl:value-of select="$contentdepth"/>
  423. scaled.contentdepth: <xsl:value-of select="$scaled.contentdepth"/>
  424. @depth: <xsl:value-of select="@depth"/>
  425. depth: <xsl:value-of select="$depth"/>
  426. html.depth: <xsl:value-of select="$html.depth"/>
  427. align: <xsl:value-of select="@align"/>
  428. valign: <xsl:value-of select="@valign"/></xsl:message>
  429. -->
  430. <xsl:variable name="scaled" select="@width|@depth|@contentwidth|@contentdepth |@scale|@scalefit"/>
  431. <xsl:variable name="img">
  432. <xsl:choose>
  433. <xsl:when test="@format = 'SVG'">
  434. <object data="{$output_filename}" type="image/svg+xml">
  435. <xsl:call-template name="process.image.attributes">
  436. <!--xsl:with-param name="alt" select="$alt"/ there's no alt here-->
  437. <xsl:with-param name="html.depth" select="$html.depth"/>
  438. <xsl:with-param name="html.width" select="$html.width"/>
  439. <xsl:with-param name="longdesc" select="$longdesc"/>
  440. <xsl:with-param name="scale" select="$scale"/>
  441. <xsl:with-param name="scalefit" select="$scalefit"/>
  442. <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
  443. <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
  444. <xsl:with-param name="viewport" select="$viewport"/>
  445. </xsl:call-template>
  446. <xsl:if test="@align">
  447. <xsl:attribute name="align">
  448. <xsl:choose>
  449. <xsl:when test="@align = 'center'">middle</xsl:when>
  450. <xsl:otherwise>
  451. <xsl:value-of select="@align"/>
  452. </xsl:otherwise>
  453. </xsl:choose>
  454. </xsl:attribute>
  455. </xsl:if>
  456. <xsl:if test="$use.embed.for.svg != 0">
  457. <embed src="{$output_filename}" type="image/svg+xml">
  458. <xsl:call-template name="process.image.attributes">
  459. <!--xsl:with-param name="alt" select="$alt"/ there's no alt here -->
  460. <xsl:with-param name="html.depth" select="$html.depth"/>
  461. <xsl:with-param name="html.width" select="$html.width"/>
  462. <xsl:with-param name="longdesc" select="$longdesc"/>
  463. <xsl:with-param name="scale" select="$scale"/>
  464. <xsl:with-param name="scalefit" select="$scalefit"/>
  465. <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
  466. <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
  467. <xsl:with-param name="viewport" select="$viewport"/>
  468. </xsl:call-template>
  469. </embed>
  470. </xsl:if>
  471. </object>
  472. </xsl:when>
  473. <xsl:otherwise>
  474. <xsl:element name="{$tag}" namespace="http://www.w3.org/1999/xhtml">
  475. <xsl:if test="$tag = 'img' and ../../self::imageobjectco">
  476. <xsl:variable name="mapname">
  477. <xsl:call-template name="object.id">
  478. <xsl:with-param name="object" select="../../areaspec"/>
  479. </xsl:call-template>
  480. </xsl:variable>
  481. <xsl:choose>
  482. <xsl:when test="$scaled">
  483. <!-- It might be possible to handle some scaling; needs -->
  484. <!-- more investigation -->
  485. <xsl:message>
  486. <xsl:text>Warning: imagemaps not supported </xsl:text>
  487. <xsl:text>on scaled images</xsl:text>
  488. </xsl:message>
  489. </xsl:when>
  490. <xsl:otherwise>
  491. <xsl:attribute name="border">0</xsl:attribute>
  492. <xsl:attribute name="usemap">
  493. <xsl:value-of select="concat('#', $mapname)"/>
  494. </xsl:attribute>
  495. </xsl:otherwise>
  496. </xsl:choose>
  497. </xsl:if>
  498. <xsl:attribute name="src">
  499. <xsl:choose>
  500. <xsl:when test="$img.src.path != '' and $tag = 'img' and not(starts-with($output_filename, '/')) and not(contains($output_filename, '://'))">
  501. <xsl:value-of select="$img.src.path"/>
  502. </xsl:when>
  503. </xsl:choose>
  504. <xsl:value-of select="$output_filename"/>
  505. </xsl:attribute>
  506. <xsl:if test="@align">
  507. <xsl:attribute name="align">
  508. <xsl:choose>
  509. <xsl:when test="@align = 'center'">middle</xsl:when>
  510. <xsl:otherwise>
  511. <xsl:value-of select="@align"/>
  512. </xsl:otherwise>
  513. </xsl:choose>
  514. </xsl:attribute>
  515. </xsl:if>
  516. <xsl:call-template name="process.image.attributes">
  517. <xsl:with-param name="alt">
  518. <xsl:choose>
  519. <xsl:when test="$alt != ''">
  520. <xsl:copy-of select="$alt"/>
  521. </xsl:when>
  522. <xsl:when test="ancestor::figure">
  523. <xsl:value-of select="normalize-space(ancestor::figure/title)"/>
  524. </xsl:when>
  525. </xsl:choose>
  526. </xsl:with-param>
  527. <xsl:with-param name="html.depth" select="$html.depth"/>
  528. <xsl:with-param name="html.width" select="$html.width"/>
  529. <xsl:with-param name="longdesc" select="$longdesc"/>
  530. <xsl:with-param name="scale" select="$scale"/>
  531. <xsl:with-param name="scalefit" select="$scalefit"/>
  532. <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
  533. <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
  534. <xsl:with-param name="viewport" select="$viewport"/>
  535. </xsl:call-template>
  536. </xsl:element>
  537. </xsl:otherwise>
  538. </xsl:choose>
  539. </xsl:variable>
  540. <xsl:variable name="bgcolor">
  541. <xsl:call-template name="pi.dbhtml_background-color">
  542. <xsl:with-param name="node" select=".."/>
  543. </xsl:call-template>
  544. </xsl:variable>
  545. <xsl:variable name="use.viewport" select="$viewport != 0 and ($html.width != '' or ($html.depth != '' and $depth-units != '%') or $bgcolor != '' or @valign)"/>
  546. <xsl:choose>
  547. <xsl:when test="$use.viewport">
  548. <table border="0" summary="manufactured viewport for HTML img" cellspacing="0" cellpadding="0">
  549. <xsl:if test="$html.width != ''">
  550. <xsl:attribute name="width">
  551. <xsl:value-of select="$html.width"/>
  552. </xsl:attribute>
  553. </xsl:if>
  554. <tr>
  555. <xsl:if test="$html.depth != '' and $depth-units != '%'">
  556. <!-- don't do this for percentages because browsers get confused -->
  557. <xsl:choose>
  558. <xsl:when test="$css.decoration != 0">
  559. <xsl:attribute name="style">
  560. <xsl:text>height: </xsl:text>
  561. <xsl:value-of select="$html.depth"/>
  562. <xsl:text>px</xsl:text>
  563. </xsl:attribute>
  564. </xsl:when>
  565. <xsl:otherwise>
  566. <xsl:attribute name="height">
  567. <xsl:value-of select="$html.depth"/>
  568. </xsl:attribute>
  569. </xsl:otherwise>
  570. </xsl:choose>
  571. </xsl:if>
  572. <td>
  573. <xsl:if test="$bgcolor != ''">
  574. <xsl:choose>
  575. <xsl:when test="$css.decoration != 0">
  576. <xsl:attribute name="style">
  577. <xsl:text>background-color: </xsl:text>
  578. <xsl:value-of select="$bgcolor"/>
  579. </xsl:attribute>
  580. </xsl:when>
  581. <xsl:otherwise>
  582. <xsl:attribute name="bgcolor">
  583. <xsl:value-of select="$bgcolor"/>
  584. </xsl:attribute>
  585. </xsl:otherwise>
  586. </xsl:choose>
  587. </xsl:if>
  588. <xsl:if test="@align">
  589. <xsl:attribute name="align">
  590. <xsl:value-of select="@align"/>
  591. </xsl:attribute>
  592. </xsl:if>
  593. <xsl:if test="@valign">
  594. <xsl:attribute name="valign">
  595. <xsl:value-of select="@valign"/>
  596. </xsl:attribute>
  597. </xsl:if>
  598. <xsl:copy-of select="$img"/>
  599. </td>
  600. </tr>
  601. </table>
  602. </xsl:when>
  603. <xsl:otherwise>
  604. <xsl:copy-of select="$img"/>
  605. </xsl:otherwise>
  606. </xsl:choose>
  607. <xsl:if test="$tag = 'img' and ../../self::imageobjectco and not($scaled)">
  608. <xsl:variable name="mapname">
  609. <xsl:call-template name="object.id">
  610. <xsl:with-param name="object" select="../../areaspec"/>
  611. </xsl:call-template>
  612. </xsl:variable>
  613. <map name="{$mapname}">
  614. <xsl:for-each select="../../areaspec//area">
  615. <xsl:variable name="units">
  616. <xsl:choose>
  617. <xsl:when test="@units = 'other' and @otherunits">
  618. <xsl:value-of select="@otherunits"/>
  619. </xsl:when>
  620. <xsl:when test="@units">
  621. <xsl:value-of select="@units"/>
  622. </xsl:when>
  623. <!-- areaspec|areaset/area -->
  624. <xsl:when test="../@units = 'other' and ../@otherunits">
  625. <xsl:value-of select="../@otherunits"/>
  626. </xsl:when>
  627. <xsl:when test="../@units">
  628. <xsl:value-of select="../@units"/>
  629. </xsl:when>
  630. <!-- areaspec/areaset/area -->
  631. <xsl:when test="../../@units = 'other' and ../../@otherunits">
  632. <xsl:value-of select="../@otherunits"/>
  633. </xsl:when>
  634. <xsl:when test="../../@units">
  635. <xsl:value-of select="../../@units"/>
  636. </xsl:when>
  637. <xsl:otherwise>calspair</xsl:otherwise>
  638. </xsl:choose>
  639. </xsl:variable>
  640. <xsl:choose>
  641. <xsl:when test="$units = 'calspair' or $units = 'imagemap'">
  642. <xsl:variable name="coords" select="normalize-space(@coords)"/>
  643. <area shape="rect">
  644. <xsl:variable name="linkends">
  645. <xsl:choose>
  646. <xsl:when test="@linkends">
  647. <xsl:value-of select="normalize-space(@linkends)"/>
  648. </xsl:when>
  649. <xsl:otherwise>
  650. <xsl:value-of select="normalize-space(../@linkends)"/>
  651. </xsl:otherwise>
  652. </xsl:choose>
  653. </xsl:variable>
  654. <xsl:variable name="href">
  655. <xsl:choose>
  656. <xsl:when test="@xlink:href">
  657. <xsl:value-of select="@xlink:href"/>
  658. </xsl:when>
  659. <xsl:otherwise>
  660. <xsl:value-of select="../@xlink:href"/>
  661. </xsl:otherwise>
  662. </xsl:choose>
  663. </xsl:variable>
  664. <xsl:choose>
  665. <xsl:when test="$linkends != ''">
  666. <xsl:variable name="linkend">
  667. <xsl:choose>
  668. <xsl:when test="contains($linkends, ' ')">
  669. <xsl:value-of select="substring-before($linkends, ' ')"/>
  670. </xsl:when>
  671. <xsl:otherwise>
  672. <xsl:value-of select="$linkends"/>
  673. </xsl:otherwise>
  674. </xsl:choose>
  675. </xsl:variable>
  676. <xsl:variable name="target" select="key('id', $linkend)[1]"/>
  677. <xsl:if test="$target">
  678. <xsl:attribute name="href">
  679. <xsl:call-template name="href.target">
  680. <xsl:with-param name="object" select="$target"/>
  681. </xsl:call-template>
  682. </xsl:attribute>
  683. </xsl:if>
  684. </xsl:when>
  685. <xsl:when test="$href != ''">
  686. <xsl:attribute name="href">
  687. <xsl:value-of select="$href"/>
  688. </xsl:attribute>
  689. </xsl:when>
  690. </xsl:choose>
  691. <xsl:if test="alt">
  692. <xsl:attribute name="alt">
  693. <xsl:value-of select="alt[1]"/>
  694. </xsl:attribute>
  695. </xsl:if>
  696. <xsl:attribute name="coords">
  697. <xsl:choose>
  698. <xsl:when test="$units = 'calspair'">
  699. <xsl:variable name="p1" select="substring-before($coords, ' ')"/>
  700. <xsl:variable name="p2" select="substring-after($coords, ' ')"/>
  701. <xsl:variable name="x1" select="substring-before($p1,',')"/>
  702. <xsl:variable name="y1" select="substring-after($p1,',')"/>
  703. <xsl:variable name="x2" select="substring-before($p2,',')"/>
  704. <xsl:variable name="y2" select="substring-after($p2,',')"/>
  705. <xsl:variable name="x1p" select="$x1 div 100.0"/>
  706. <xsl:variable name="y1p" select="$y1 div 100.0"/>
  707. <xsl:variable name="x2p" select="$x2 div 100.0"/>
  708. <xsl:variable name="y2p" select="$y2 div 100.0"/>
  709. <!--
  710. <xsl:message>
  711. <xsl:text>units: </xsl:text>
  712. <xsl:value-of select="$units"/>
  713. <xsl:text> </xsl:text>
  714. <xsl:value-of select="$x1p"/><xsl:text>, </xsl:text>
  715. <xsl:value-of select="$y1p"/><xsl:text>, </xsl:text>
  716. <xsl:value-of select="$x2p"/><xsl:text>, </xsl:text>
  717. <xsl:value-of select="$y2p"/><xsl:text>, </xsl:text>
  718. </xsl:message>
  719. <xsl:message>
  720. <xsl:text> </xsl:text>
  721. <xsl:value-of select="$intrinsicwidth"/>
  722. <xsl:text>, </xsl:text>
  723. <xsl:value-of select="$intrinsicdepth"/>
  724. </xsl:message>
  725. <xsl:message>
  726. <xsl:text> </xsl:text>
  727. <xsl:value-of select="$units"/>
  728. <xsl:text> </xsl:text>
  729. <xsl:value-of
  730. select="round($x1p * $intrinsicwidth div 100.0)"/>
  731. <xsl:text>,</xsl:text>
  732. <xsl:value-of select="round($intrinsicdepth
  733. - ($y2p * $intrinsicdepth div 100.0))"/>
  734. <xsl:text>,</xsl:text>
  735. <xsl:value-of select="round($x2p *
  736. $intrinsicwidth div 100.0)"/>
  737. <xsl:text>,</xsl:text>
  738. <xsl:value-of select="round($intrinsicdepth
  739. - ($y1p * $intrinsicdepth div 100.0))"/>
  740. </xsl:message>
  741. -->
  742. <xsl:value-of select="round($x1p * $intrinsicwidth div 100.0)"/>
  743. <xsl:text>,</xsl:text>
  744. <xsl:value-of select="round($intrinsicdepth - ($y2p * $intrinsicdepth div 100.0))"/>
  745. <xsl:text>,</xsl:text>
  746. <xsl:value-of select="round($x2p * $intrinsicwidth div 100.0)"/>
  747. <xsl:text>,</xsl:text>
  748. <xsl:value-of select="round($intrinsicdepth - ($y1p * $intrinsicdepth div 100.0))"/>
  749. </xsl:when>
  750. <xsl:otherwise>
  751. <xsl:copy-of select="$coords"/>
  752. </xsl:otherwise>
  753. </xsl:choose>
  754. </xsl:attribute>
  755. </area>
  756. </xsl:when>
  757. <xsl:otherwise>
  758. <xsl:message>
  759. <xsl:text>Warning: only calspair or </xsl:text>
  760. <xsl:text>otherunits='imagemap' supported </xsl:text>
  761. <xsl:text>in imageobjectco</xsl:text>
  762. </xsl:message>
  763. </xsl:otherwise>
  764. </xsl:choose>
  765. </xsl:for-each>
  766. </map>
  767. </xsl:if>
  768. </xsl:template>
  769. <xsl:template name="process.image.attributes">
  770. <xsl:param name="alt"/>
  771. <xsl:param name="html.width"/>
  772. <xsl:param name="html.depth"/>
  773. <xsl:param name="longdesc"/>
  774. <xsl:param name="scale"/>
  775. <xsl:param name="scalefit"/>
  776. <xsl:param name="scaled.contentdepth"/>
  777. <xsl:param name="scaled.contentwidth"/>
  778. <xsl:param name="viewport"/>
  779. <xsl:choose>
  780. <xsl:when test="@contentwidth or @contentdepth">
  781. <!-- ignore @width/@depth, @scale, and @scalefit if specified -->
  782. <xsl:if test="@contentwidth and $scaled.contentwidth != ''">
  783. <xsl:attribute name="width">
  784. <xsl:value-of select="$scaled.contentwidth"/>
  785. </xsl:attribute>
  786. </xsl:if>
  787. <xsl:if test="@contentdepth and $scaled.contentdepth != ''">
  788. <xsl:attribute name="height">
  789. <xsl:value-of select="$scaled.contentdepth"/>
  790. </xsl:attribute>
  791. </xsl:if>
  792. </xsl:when>
  793. <xsl:when test="number($scale) != 1.0">
  794. <!-- scaling is always uniform, so we only have to specify one dimension -->
  795. <!-- ignore @scalefit if specified -->
  796. <xsl:attribute name="width">
  797. <xsl:value-of select="$scaled.contentwidth"/>
  798. </xsl:attribute>
  799. </xsl:when>
  800. <xsl:when test="$scalefit != 0">
  801. <xsl:choose>
  802. <xsl:when test="contains($html.width, '%')">
  803. <xsl:choose>
  804. <xsl:when test="$viewport != 0">
  805. <!-- The *viewport* will be scaled, so use 100% here! -->
  806. <xsl:attribute name="width">
  807. <xsl:value-of select="'100%'"/>
  808. </xsl:attribute>
  809. </xsl:when>
  810. <xsl:otherwise>
  811. <xsl:attribute name="width">
  812. <xsl:value-of select="$html.width"/>
  813. </xsl:attribute>
  814. </xsl:otherwise>
  815. </xsl:choose>
  816. </xsl:when>
  817. <xsl:when test="contains($html.depth, '%')">
  818. <!-- HTML doesn't deal with this case very well...do nothing -->
  819. </xsl:when>
  820. <xsl:when test="$scaled.contentwidth != '' and $html.width != '' and $scaled.contentdepth != '' and $html.depth != ''">
  821. <!-- scalefit should not be anamorphic; figure out which direction -->
  822. <!-- has the limiting scale factor and scale in that direction -->
  823. <xsl:choose>
  824. <xsl:when test="$html.width div $scaled.contentwidth &gt; $html.depth div $scaled.contentdepth">
  825. <xsl:attribute name="height">
  826. <xsl:value-of select="$html.depth"/>
  827. </xsl:attribute>
  828. </xsl:when>
  829. <xsl:otherwise>
  830. <xsl:attribute name="width">
  831. <xsl:value-of select="$html.width"/>
  832. </xsl:attribute>
  833. </xsl:otherwise>
  834. </xsl:choose>
  835. </xsl:when>
  836. <xsl:when test="$scaled.contentwidth != '' and $html.width != ''">
  837. <xsl:attribute name="width">
  838. <xsl:value-of select="$html.width"/>
  839. </xsl:attribute>
  840. </xsl:when>
  841. <xsl:when test="$scaled.contentdepth != '' and $html.depth != ''">
  842. <xsl:attribute name="height">
  843. <xsl:value-of select="$html.depth"/>
  844. </xsl:attribute>
  845. </xsl:when>
  846. </xsl:choose>
  847. </xsl:when>
  848. </xsl:choose>
  849. <xsl:if test="$alt != ''">
  850. <xsl:attribute name="alt">
  851. <xsl:value-of select="normalize-space($alt)"/>
  852. </xsl:attribute>
  853. </xsl:if>
  854. <xsl:if test="$longdesc != ''">
  855. <xsl:attribute name="longdesc">
  856. <xsl:value-of select="$longdesc"/>
  857. </xsl:attribute>
  858. </xsl:if>
  859. <xsl:if test="@align and $viewport = 0">
  860. <xsl:attribute name="align">
  861. <xsl:choose>
  862. <xsl:when test="@align = 'center'">middle</xsl:when>
  863. <xsl:otherwise>
  864. <xsl:value-of select="@align"/>
  865. </xsl:otherwise>
  866. </xsl:choose>
  867. </xsl:attribute>
  868. </xsl:if>
  869. </xsl:template>
  870. <!-- ==================================================================== -->
  871. <xsl:template match="graphic">
  872. <xsl:choose>
  873. <xsl:when test="parent::inlineequation">
  874. <xsl:call-template name="anchor"/>
  875. <xsl:call-template name="process.image"/>
  876. </xsl:when>
  877. <xsl:otherwise>
  878. <div>
  879. <xsl:if test="@align">
  880. <xsl:attribute name="align">
  881. <xsl:value-of select="@align"/>
  882. </xsl:attribute>
  883. </xsl:if>
  884. <xsl:call-template name="anchor"/>
  885. <xsl:call-template name="process.image"/>
  886. </div>
  887. </xsl:otherwise>
  888. </xsl:choose>
  889. </xsl:template>
  890. <xsl:template match="inlinegraphic">
  891. <xsl:variable name="filename">
  892. <xsl:choose>
  893. <xsl:when test="@entityref">
  894. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  895. </xsl:when>
  896. <xsl:otherwise>
  897. <xsl:apply-templates select="@fileref"/>
  898. </xsl:otherwise>
  899. </xsl:choose>
  900. </xsl:variable>
  901. <xsl:call-template name="anchor"/>
  902. <xsl:choose>
  903. <xsl:when test="@format='linespecific'">
  904. <xsl:choose>
  905. <xsl:when test="$use.extensions != '0' and $textinsert.extension != '0'">
  906. <xsl:choose>
  907. <xsl:when test="element-available('stext:insertfile')">
  908. <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
  909. </xsl:when>
  910. <xsl:when test="element-available('xtext:insertfile')">
  911. <xtext:insertfile href="{$filename}"/>
  912. </xsl:when>
  913. <xsl:otherwise>
  914. <xsl:message terminate="yes">
  915. <xsl:text>No insertfile extension available.</xsl:text>
  916. </xsl:message>
  917. </xsl:otherwise>
  918. </xsl:choose>
  919. </xsl:when>
  920. <xsl:otherwise>
  921. <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" href="{$filename}"/>
  922. </xsl:otherwise>
  923. </xsl:choose>
  924. </xsl:when>
  925. <xsl:otherwise>
  926. <xsl:call-template name="process.image"/>
  927. </xsl:otherwise>
  928. </xsl:choose>
  929. </xsl:template>
  930. <!-- ==================================================================== -->
  931. <xsl:template match="mediaobject|mediaobjectco">
  932. <xsl:variable name="olist" select="imageobject|imageobjectco |videoobject|audioobject |textobject"/>
  933. <xsl:variable name="object.index">
  934. <xsl:call-template name="select.mediaobject.index">
  935. <xsl:with-param name="olist" select="$olist"/>
  936. <xsl:with-param name="count" select="1"/>
  937. </xsl:call-template>
  938. </xsl:variable>
  939. <xsl:variable name="object" select="$olist[position() = $object.index]"/>
  940. <xsl:variable name="align">
  941. <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
  942. </xsl:variable>
  943. <div>
  944. <xsl:apply-templates select="." mode="class.attribute"/>
  945. <xsl:if test="$align != '' ">
  946. <xsl:attribute name="align">
  947. <xsl:value-of select="$align"/>
  948. </xsl:attribute>
  949. </xsl:if>
  950. <xsl:call-template name="anchor"/>
  951. <xsl:apply-templates select="$object"/>
  952. <xsl:apply-templates select="caption"/>
  953. </div>
  954. </xsl:template>
  955. <xsl:template match="inlinemediaobject">
  956. <span>
  957. <xsl:apply-templates select="." mode="class.attribute"/>
  958. <xsl:call-template name="anchor"/>
  959. <xsl:call-template name="select.mediaobject"/>
  960. </span>
  961. </xsl:template>
  962. <xsl:template match="programlisting/inlinemediaobject |screen/inlinemediaobject" priority="2">
  963. <!-- the additional span causes problems in some cases -->
  964. <xsl:call-template name="select.mediaobject"/>
  965. </xsl:template>
  966. <!-- ==================================================================== -->
  967. <xsl:template match="imageobjectco">
  968. <xsl:call-template name="anchor"/>
  969. <xsl:apply-templates select="imageobject"/>
  970. <xsl:apply-templates select="calloutlist"/>
  971. </xsl:template>
  972. <xsl:template match="imageobject">
  973. <xsl:apply-templates select="imagedata"/>
  974. </xsl:template>
  975. <xsl:template match="imagedata">
  976. <xsl:variable name="filename">
  977. <xsl:call-template name="mediaobject.filename">
  978. <xsl:with-param name="object" select=".."/>
  979. </xsl:call-template>
  980. </xsl:variable>
  981. <xsl:choose>
  982. <!-- Handle MathML and SVG markup in imagedata -->
  983. <xsl:when xmlns:mml="http://www.w3.org/1998/Math/MathML" test="mml:*">
  984. <xsl:apply-templates/>
  985. </xsl:when>
  986. <xsl:when xmlns:svg="http://www.w3.org/2000/svg" test="svg:*">
  987. <xsl:apply-templates/>
  988. </xsl:when>
  989. <xsl:when test="@format='linespecific'">
  990. <xsl:choose>
  991. <xsl:when test="$use.extensions != '0' and $textinsert.extension != '0'">
  992. <xsl:choose>
  993. <xsl:when test="element-available('stext:insertfile')">
  994. <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
  995. </xsl:when>
  996. <xsl:when test="element-available('xtext:insertfile')">
  997. <xtext:insertfile href="{$filename}"/>
  998. </xsl:when>
  999. <xsl:otherwise>
  1000. <xsl:message terminate="yes">
  1001. <xsl:text>No insertfile extension available.</xsl:text>
  1002. </xsl:message>
  1003. </xsl:otherwise>
  1004. </xsl:choose>
  1005. </xsl:when>
  1006. <xsl:otherwise>
  1007. <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" href="{$filename}"/>
  1008. </xsl:otherwise>
  1009. </xsl:choose>
  1010. </xsl:when>
  1011. <xsl:otherwise>
  1012. <xsl:variable name="longdesc.uri">
  1013. <xsl:call-template name="longdesc.uri">
  1014. <xsl:with-param name="mediaobject" select="ancestor::imageobject/parent::*"/>
  1015. </xsl:call-template>
  1016. </xsl:variable>
  1017. <xsl:variable name="phrases" select="ancestor::mediaobject/textobject[phrase] |ancestor::inlinemediaobject/textobject[phrase] |ancestor::mediaobjectco/textobject[phrase]"/>
  1018. <xsl:call-template name="process.image">
  1019. <xsl:with-param name="alt">
  1020. <xsl:apply-templates select="$phrases[not(@role) or @role!='tex'][1]"/>
  1021. </xsl:with-param>
  1022. <xsl:with-param name="longdesc">
  1023. <xsl:call-template name="write.longdesc">
  1024. <xsl:with-param name="mediaobject" select="ancestor::imageobject/parent::*"/>
  1025. </xsl:call-template>
  1026. </xsl:with-param>
  1027. </xsl:call-template>
  1028. <xsl:if test="$html.longdesc != 0 and $html.longdesc.link != 0 and ancestor::imageobject/parent::*/textobject[not(phrase)]">
  1029. <xsl:call-template name="longdesc.link">
  1030. <xsl:with-param name="longdesc.uri" select="$longdesc.uri"/>
  1031. </xsl:call-template>
  1032. </xsl:if>
  1033. </xsl:otherwise>
  1034. </xsl:choose>
  1035. </xsl:template>
  1036. <!-- ==================================================================== -->
  1037. <xsl:template name="longdesc.uri">
  1038. <xsl:param name="mediaobject" select="."/>
  1039. <xsl:if test="$html.longdesc">
  1040. <xsl:if test="$mediaobject/textobject[not(phrase)]">
  1041. <xsl:variable name="dbhtml.dir">
  1042. <xsl:call-template name="dbhtml-dir"/>
  1043. </xsl:variable>
  1044. <xsl:variable name="filename">
  1045. <xsl:call-template name="make-relative-filename">
  1046. <xsl:with-param name="base.dir">
  1047. <xsl:choose>
  1048. <xsl:when test="$dbhtml.dir != ''">
  1049. <xsl:value-of select="$dbhtml.dir"/>
  1050. </xsl:when>
  1051. <xsl:otherwise>
  1052. <xsl:value-of select="$base.dir"/>
  1053. </xsl:otherwise>
  1054. </xsl:choose>
  1055. </xsl:with-param>
  1056. <xsl:with-param name="base.name">
  1057. <xsl:choose>
  1058. <xsl:when test=" $mediaobject/@*[local-name() = 'id'] and not($use.id.as.filename = 0)">
  1059. <!-- * if this mediaobject has an ID, then we use the -->
  1060. <!-- * value of that ID as basename for the "longdesc" -->
  1061. <!-- * file (that is, without prepending an "ld-" too it) -->
  1062. <xsl:value-of select="$mediaobject/@*[local-name() = 'id']"/>
  1063. <xsl:value-of select="$html.ext"/>
  1064. </xsl:when>
  1065. <xsl:otherwise>
  1066. <!-- * otherwise, if this mediaobject does not have an -->
  1067. <!-- * ID, then we generate an ID... -->
  1068. <xsl:variable name="image-id">
  1069. <xsl:call-template name="object.id">
  1070. <xsl:with-param name="object" select="$mediaobject"/>
  1071. </xsl:call-template>
  1072. </xsl:variable>
  1073. <!-- * ...and then we take that generated ID, prepend an -->
  1074. <!-- * "ld-" to it, and use that as the basename for the file -->
  1075. <xsl:value-of select="concat('ld-',$image-id,$html.ext)"/>
  1076. </xsl:otherwise>
  1077. </xsl:choose>
  1078. </xsl:with-param>
  1079. </xsl:call-template>
  1080. </xsl:variable>
  1081. <xsl:value-of select="$filename"/>
  1082. </xsl:if>
  1083. </xsl:if>
  1084. </xsl:template>
  1085. <xsl:template name="write.longdesc">
  1086. <xsl:param name="mediaobject" select="."/>
  1087. <xsl:if test="$html.longdesc != 0 and $mediaobject/textobject[not(phrase)]">
  1088. <xsl:variable name="filename">
  1089. <xsl:call-template name="longdesc.uri">
  1090. <xsl:with-param name="mediaobject" select="$mediaobject"/>
  1091. </xsl:call-template>
  1092. </xsl:variable>
  1093. <xsl:value-of select="$filename"/>
  1094. <xsl:call-template name="write.chunk">
  1095. <xsl:with-param name="filename" select="$filename"/>
  1096. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  1097. <xsl:with-param name="content">
  1098. <xsl:call-template name="user.preroot"/>
  1099. <html>
  1100. <head>
  1101. <xsl:call-template name="system.head.content"/>
  1102. <xsl:call-template name="head.content">
  1103. <xsl:with-param name="title" select="'Long Description'"/>
  1104. </xsl:call-template>
  1105. <xsl:call-template name="user.head.content"/>
  1106. </head>
  1107. <body>
  1108. <xsl:call-template name="body.attributes"/>
  1109. <xsl:for-each select="$mediaobject/textobject[not(phrase)]">
  1110. <xsl:apply-templates select="./*"/>
  1111. </xsl:for-each>
  1112. </body>
  1113. </html>
  1114. <xsl:value-of select="$chunk.append"/>
  1115. </xsl:with-param>
  1116. </xsl:call-template>
  1117. </xsl:if>
  1118. </xsl:template>
  1119. <xsl:template name="longdesc.link">
  1120. <xsl:param name="longdesc.uri" select="''"/>
  1121. <xsl:variable name="this.uri">
  1122. <xsl:call-template name="make-relative-filename">
  1123. <xsl:with-param name="base.dir" select="$base.dir"/>
  1124. <xsl:with-param name="base.name">
  1125. <xsl:call-template name="href.target.uri"/>
  1126. </xsl:with-param>
  1127. </xsl:call-template>
  1128. </xsl:variable>
  1129. <xsl:variable name="href.to">
  1130. <xsl:call-template name="trim.common.uri.paths">
  1131. <xsl:with-param name="uriA" select="$longdesc.uri"/>
  1132. <xsl:with-param name="uriB" select="$this.uri"/>
  1133. <xsl:with-param name="return" select="'A'"/>
  1134. </xsl:call-template>
  1135. </xsl:variable>
  1136. <div class="longdesc-link" align="right">
  1137. <br clear="all"/>
  1138. <span class="longdesc-link">
  1139. <xsl:text>[</xsl:text>
  1140. <a href="{$href.to}" target="longdesc">D</a>
  1141. <xsl:text>]</xsl:text>
  1142. </span>
  1143. </div>
  1144. </xsl:template>
  1145. <!-- ==================================================================== -->
  1146. <xsl:template match="videoobject">
  1147. <xsl:apply-templates select="videodata"/>
  1148. </xsl:template>
  1149. <xsl:template match="videodata">
  1150. <xsl:call-template name="process.image">
  1151. <xsl:with-param name="tag" select="'embed'"/>
  1152. <xsl:with-param name="alt">
  1153. <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
  1154. </xsl:with-param>
  1155. </xsl:call-template>
  1156. </xsl:template>
  1157. <!-- ==================================================================== -->
  1158. <xsl:template match="audioobject">
  1159. <xsl:apply-templates select="audiodata"/>
  1160. </xsl:template>
  1161. <xsl:template match="audiodata">
  1162. <xsl:call-template name="process.image">
  1163. <xsl:with-param name="tag" select="'embed'"/>
  1164. <xsl:with-param name="alt">
  1165. <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
  1166. </xsl:with-param>
  1167. </xsl:call-template>
  1168. </xsl:template>
  1169. <!-- ==================================================================== -->
  1170. <xsl:template match="textobject">
  1171. <xsl:apply-templates/>
  1172. </xsl:template>
  1173. <xsl:template match="textdata">
  1174. <xsl:variable name="filename">
  1175. <xsl:choose>
  1176. <xsl:when test="@entityref">
  1177. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  1178. </xsl:when>
  1179. <xsl:otherwise>
  1180. <xsl:apply-templates select="@fileref"/>
  1181. </xsl:otherwise>
  1182. </xsl:choose>
  1183. </xsl:variable>
  1184. <xsl:variable name="encoding">
  1185. <xsl:choose>
  1186. <xsl:when test="@encoding">
  1187. <xsl:value-of select="@encoding"/>
  1188. </xsl:when>
  1189. <xsl:otherwise>
  1190. <xsl:value-of select="$textdata.default.encoding"/>
  1191. </xsl:otherwise>
  1192. </xsl:choose>
  1193. </xsl:variable>
  1194. <xsl:choose>
  1195. <xsl:when test="$use.extensions != '0' and $textinsert.extension != '0'">
  1196. <xsl:choose>
  1197. <xsl:when test="element-available('stext:insertfile')">
  1198. <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
  1199. </xsl:when>
  1200. <xsl:when test="element-available('xtext:insertfile')">
  1201. <xtext:insertfile href="{$filename}"/>
  1202. </xsl:when>
  1203. <xsl:otherwise>
  1204. <xsl:message terminate="yes">
  1205. <xsl:text>No insertfile extension available.</xsl:text>
  1206. </xsl:message>
  1207. </xsl:otherwise>
  1208. </xsl:choose>
  1209. </xsl:when>
  1210. <xsl:otherwise>
  1211. <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" href="{$filename}"/>
  1212. </xsl:otherwise>
  1213. </xsl:choose>
  1214. </xsl:template>
  1215. <!-- ==================================================================== -->
  1216. <xsl:template match="caption">
  1217. <div>
  1218. <xsl:apply-templates select="." mode="class.attribute"/>
  1219. <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
  1220. <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
  1221. </xsl:if>
  1222. <xsl:apply-templates/>
  1223. </div>
  1224. </xsl:template>
  1225. <!-- ==================================================================== -->
  1226. <!-- "Support" for SVG -->
  1227. <xsl:template xmlns:svg="http://www.w3.org/2000/svg" match="svg:*">
  1228. <xsl:copy>
  1229. <xsl:copy-of select="@*"/>
  1230. <xsl:apply-templates/>
  1231. </xsl:copy>
  1232. </xsl:template>
  1233. <!-- The following works sometimes, but needs to take into account
  1234. 1. When there is no /*/@xml:base
  1235. 2. When the chunks are going somewhere else
  1236. <xsl:variable name="relpath">
  1237. <xsl:call-template name="relative-uri">
  1238. <xsl:with-param name="filename" select="@fileref"/>
  1239. </xsl:call-template>
  1240. </xsl:variable>
  1241. <xsl:choose>
  1242. <xsl:when test="/*/@xml:base
  1243. and starts-with($relpath,/*/@xml:base)">
  1244. <xsl:value-of select="substring-after($relpath,/*/@xml:base)"/>
  1245. </xsl:when>
  1246. <xsl:otherwise>
  1247. <xsl:value-of select="@fileref"/>
  1248. </xsl:otherwise>
  1249. </xsl:choose>
  1250. <xsl:value-of select="@fileref"/>
  1251. </xsl:when>
  1252. -->
  1253. <!-- Resolve xml:base attributes -->
  1254. <xsl:template match="@fileref">
  1255. <!-- need a check for absolute urls -->
  1256. <xsl:choose>
  1257. <xsl:when test="contains(., ':')">
  1258. <!-- it has a uri scheme so it is an absolute uri -->
  1259. <xsl:value-of select="."/>
  1260. </xsl:when>
  1261. <xsl:when test="$keep.relative.image.uris != 0">
  1262. <!-- leave it alone -->
  1263. <xsl:value-of select="."/>
  1264. </xsl:when>
  1265. <xsl:otherwise>
  1266. <!-- its a relative uri that needs xml:base processing -->
  1267. <xsl:call-template name="relative-uri">
  1268. </xsl:call-template>
  1269. </xsl:otherwise>
  1270. </xsl:choose>
  1271. </xsl:template>
  1272. </xsl:stylesheet>