home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 October / INTERNET108.ISO / pc / software / windows / building / xmlspy / xmlspyentcomplete5.exe / Data1.cab / _10B0B5B223C14B59A5FC6CA3E66470B3 < prev    next >
Encoding:
Extensible Markup Language  |  2002-09-04  |  37.6 KB  |  1,043 lines

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