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

  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
  4.                 xmlns:xlink="http://www.w3.org/1999/xlink"
  5.                 xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
  6.                 xmlns:xtext="com.nwalsh.xalan.Text"
  7.                 xmlns:lxslt="http://xml.apache.org/xslt"
  8.                 exclude-result-prefixes="xlink stext xtext lxslt"
  9.                 extension-element-prefixes="stext xtext"
  10.                 version='1.0'>
  11.  
  12. <!-- ********************************************************************
  13.      $Id: graphics.xsl,v 1.1.2.1 2002/09/04 14:25:15 jdj Exp $
  14.      ********************************************************************
  15.  
  16.      This file is part of the XSL DocBook Stylesheet distribution.
  17.      See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  18.      and other information.
  19.  
  20.      Contributors:
  21.      Colin Paul Adams, <colin@colina.demon.co.uk>
  22.      Paul Grosso, <pgrosso@arbortext.com>
  23.  
  24.      ******************************************************************** -->
  25.  
  26. <!-- ==================================================================== -->
  27. <!-- Graphic format tests for the FO backend -->
  28.  
  29. <xsl:param name="graphic.notations">
  30.   <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
  31.   <xsl:choose>
  32.     <xsl:when test="$passivetex.extensions != 0">
  33.       <xsl:text> PNG PDF JPG JPEG linespecific </xsl:text>
  34.     </xsl:when>
  35.     <xsl:when test="$fop.extensions != 0">
  36.       <xsl:text> SVG PNG PDF JPG JPEG linespecific </xsl:text>
  37.     </xsl:when>
  38.     <xsl:when test="$arbortext.extensions != 0">
  39.       <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
  40.     </xsl:when>
  41.     <xsl:when test="$xep.extensions != 0">
  42.       <xsl:text> SVG PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
  43.     </xsl:when>
  44.     <xsl:otherwise>
  45.       <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
  46.     </xsl:otherwise>
  47.   </xsl:choose>
  48. </xsl:param>
  49.  
  50. <xsl:template name="is.graphic.format">
  51.   <xsl:param name="format"/>
  52.   <xsl:if test="contains($graphic.notations, concat(' ',$format,' '))">1</xsl:if>
  53. </xsl:template>
  54.  
  55. <xsl:param name="graphic.extensions">
  56.   <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
  57.   <xsl:choose>
  58.     <xsl:when test="$passivetex.extensions != 0">
  59.       <xsl:text> png pdf jpg jpeg </xsl:text>
  60.     </xsl:when>
  61.     <xsl:when test="$fop.extensions != 0">
  62.       <xsl:text> svg png pdf jpg jpeg </xsl:text>
  63.     </xsl:when>
  64.     <xsl:when test="$arbortext.extensions != 0">
  65.       <xsl:text> png pdf jpg jpeg gif tif tiff bmp </xsl:text>
  66.     </xsl:when>
  67.     <xsl:when test="$xep.extensions != 0">
  68.       <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp </xsl:text>
  69.     </xsl:when>
  70.     <xsl:otherwise>
  71.       <xsl:text> png pdf jpg jpeg gif tif tiff bmp </xsl:text>
  72.     </xsl:otherwise>
  73.   </xsl:choose>
  74. </xsl:param>
  75.  
  76. <xsl:template name="is.graphic.extension">
  77.   <xsl:param name="ext"/>
  78.   <xsl:if test="contains($graphic.extensions, concat(' ', $ext, ' '))">1</xsl:if>
  79. </xsl:template>
  80.  
  81. <!-- ==================================================================== -->
  82.  
  83. <xsl:template match="screenshot">
  84.   <fo:block>
  85.     <xsl:apply-templates/>
  86.   </fo:block>
  87. </xsl:template>
  88.  
  89. <xsl:template match="screeninfo">
  90. </xsl:template>
  91.  
  92. <!-- ==================================================================== -->
  93. <!-- Override these templates for FO -->
  94. <!-- ==================================================================== -->
  95.  
  96. <xsl:template name="process.image">
  97.   <!-- When this template is called, the current node should be  -->
  98.   <!-- a graphic, inlinegraphic, imagedata, or videodata. All    -->
  99.   <!-- those elements have the same set of attributes, so we can -->
  100.   <!-- handle them all in one place.                             -->
  101.  
  102.   <xsl:variable name="scalefit">
  103.     <xsl:choose>
  104.       <xsl:when test="@contentwidth or @contentdepth">0</xsl:when>
  105.       <xsl:when test="@scale">0</xsl:when>
  106.       <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
  107.       <xsl:when test="@width or @depth">1</xsl:when>
  108.       <xsl:otherwise>0</xsl:otherwise>
  109.     </xsl:choose>
  110.   </xsl:variable>
  111.  
  112.   <xsl:variable name="scale">
  113.     <xsl:choose>
  114.       <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
  115.       <xsl:when test="@scale">
  116.         <xsl:value-of select="@scale div 100.0"/>
  117.       </xsl:when>
  118.       <xsl:otherwise>1.0</xsl:otherwise>
  119.     </xsl:choose>
  120.   </xsl:variable>
  121.  
  122.   <xsl:variable name="filename">
  123.     <xsl:choose>
  124.       <xsl:when test="local-name(.) = 'graphic'
  125.                       or local-name(.) = 'inlinegraphic'">
  126.         <!-- handle legacy graphic and inlinegraphic by new template --> 
  127.         <xsl:call-template name="mediaobject.filename">
  128.           <xsl:with-param name="object" select="."/>
  129.         </xsl:call-template>
  130.       </xsl:when>
  131.       <xsl:otherwise>
  132.         <!-- imagedata, videodata, audiodata -->
  133.         <xsl:call-template name="mediaobject.filename">
  134.           <xsl:with-param name="object" select=".."/>
  135.         </xsl:call-template>
  136.       </xsl:otherwise>
  137.     </xsl:choose>
  138.   </xsl:variable>
  139.  
  140.   <xsl:variable name="bgcolor">
  141.     <xsl:call-template name="dbfo-attribute">
  142.       <xsl:with-param name="pis"
  143.                       select="../processing-instruction('dbfo')"/>
  144.       <xsl:with-param name="attribute" select="'background-color'"/>
  145.     </xsl:call-template>
  146.   </xsl:variable>
  147.  
  148.   <fo:external-graphic>
  149.     <xsl:attribute name="src">
  150.       <xsl:call-template name="fo-external-image">
  151.         <xsl:with-param name="filename" select="$filename"/>
  152.       </xsl:call-template>
  153.     </xsl:attribute>
  154.  
  155.     <xsl:attribute name="width">
  156.       <xsl:choose>
  157.         <xsl:when test="contains(@width,'%')">
  158.           <xsl:value-of select="@width"/>
  159.         </xsl:when>
  160.         <xsl:when test="@width">
  161.           <xsl:call-template name="length-spec">
  162.             <xsl:with-param name="length" select="@width"/>
  163.             <xsl:with-param name="default.units" select="'px'"/>
  164.           </xsl:call-template>
  165.         </xsl:when>
  166.         <xsl:otherwise>auto</xsl:otherwise>
  167.       </xsl:choose>
  168.     </xsl:attribute>
  169.  
  170.     <xsl:attribute name="height">
  171.       <xsl:choose>
  172.         <xsl:when test="contains(@depth,'%')">
  173.           <xsl:value-of select="@depth"/>
  174.         </xsl:when>
  175.         <xsl:when test="@depth">
  176.           <xsl:call-template name="length-spec">
  177.             <xsl:with-param name="length" select="@depth"/>
  178.             <xsl:with-param name="default.units" select="'px'"/>
  179.           </xsl:call-template>
  180.         </xsl:when>
  181.         <xsl:otherwise>auto</xsl:otherwise>
  182.       </xsl:choose>
  183.     </xsl:attribute>
  184.  
  185.     <xsl:attribute name="content-width">
  186.       <xsl:choose>
  187.         <xsl:when test="contains(@contentwidth,'%')">
  188.           <xsl:value-of select="@contentwidth"/>
  189.         </xsl:when>
  190.         <xsl:when test="@contentwidth">
  191.           <xsl:call-template name="length-spec">
  192.             <xsl:with-param name="length" select="@contentwidth"/>
  193.             <xsl:with-param name="default.units" select="'px'"/>
  194.           </xsl:call-template>
  195.         </xsl:when>
  196.         <xsl:when test="number($scale) != 1.0">
  197.           <xsl:value-of select="$scale * 100"/>
  198.           <xsl:text>%</xsl:text>
  199.         </xsl:when>
  200.         <xsl:otherwise>auto</xsl:otherwise>
  201.       </xsl:choose>
  202.     </xsl:attribute>
  203.  
  204.     <xsl:attribute name="content-height">
  205.       <xsl:choose>
  206.         <xsl:when test="contains(@contentdepth,'%')">
  207.           <xsl:value-of select="@contentdepth"/>
  208.         </xsl:when>
  209.         <xsl:when test="@contentdepth">
  210.           <xsl:call-template name="length-spec">
  211.             <xsl:with-param name="length" select="@contentdepth"/>
  212.             <xsl:with-param name="default.units" select="'px'"/>
  213.           </xsl:call-template>
  214.         </xsl:when>
  215.         <xsl:when test="number($scale) != 1.0">
  216.           <xsl:value-of select="$scale * 100"/>
  217.           <xsl:text>%</xsl:text>
  218.         </xsl:when>
  219.         <xsl:otherwise>auto</xsl:otherwise>
  220.       </xsl:choose>
  221.     </xsl:attribute>
  222.  
  223.     <xsl:if test="$bgcolor != ''">
  224.       <xsl:attribute name="background-color">
  225.         <xsl:value-of select="$bgcolor"/>
  226.       </xsl:attribute>
  227.     </xsl:if>
  228.  
  229.     <xsl:if test="@align">
  230.       <xsl:attribute name="text-align">
  231.         <xsl:value-of select="@align"/>
  232.       </xsl:attribute>
  233.     </xsl:if>
  234.  
  235.     <xsl:if test="@valign">
  236.       <xsl:attribute name="display-align">
  237.         <xsl:choose>
  238.           <xsl:when test="@valign = 'top'">before</xsl:when>
  239.           <xsl:when test="@valign = 'middle'">center</xsl:when>
  240.           <xsl:when test="@valign = 'bottom'">after</xsl:when>
  241.           <xsl:otherwise>auto</xsl:otherwise>
  242.         </xsl:choose>
  243.       </xsl:attribute>
  244.     </xsl:if>
  245.   </fo:external-graphic>
  246. </xsl:template>
  247.  
  248. <!-- ==================================================================== -->
  249.  
  250. <xsl:template match="graphic">
  251.   <xsl:choose>
  252.     <xsl:when test="../inlineequation">
  253.       <xsl:call-template name="process.image"/>
  254.     </xsl:when>
  255.     <xsl:otherwise>
  256.       <fo:block>
  257.         <xsl:call-template name="process.image"/>
  258.       </fo:block>
  259.     </xsl:otherwise>
  260.   </xsl:choose>
  261. </xsl:template>
  262.  
  263. <xsl:template match="inlinegraphic">
  264.   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  265.   <xsl:variable name="filename">
  266.     <xsl:choose>
  267.       <xsl:when test="@entityref">
  268.         <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  269.       </xsl:when>
  270.       <xsl:otherwise>
  271.         <xsl:value-of select="@fileref"/>
  272.       </xsl:otherwise>
  273.     </xsl:choose>
  274.   </xsl:variable>
  275.  
  276.   <xsl:choose>
  277.     <xsl:when test="@format='linespecific'">
  278.       <xsl:choose>
  279.         <xsl:when test="$use.extensions != '0'
  280.                         and $textinsert.extension != '0'">
  281.           <xsl:choose>
  282.             <xsl:when test="contains($vendor, 'SAXON')">
  283.               <stext:insertfile href="{$filename}"/>
  284.             </xsl:when>
  285.             <xsl:when test="contains($vendor, 'Apache Software Foundation')">
  286.               <xtext:insertfile href="{$filename}"/>
  287.             </xsl:when>
  288.             <xsl:otherwise>
  289.               <xsl:message terminate="yes">
  290.                 <xsl:text>Don't know how to insert files with </xsl:text>
  291.                 <xsl:value-of select="$vendor"/>
  292.               </xsl:message>
  293.             </xsl:otherwise>
  294.           </xsl:choose>
  295.         </xsl:when>
  296.         <xsl:otherwise>
  297.           <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
  298.              href="{$filename}"/>
  299.         </xsl:otherwise>
  300.       </xsl:choose>
  301.     </xsl:when>
  302.     <xsl:otherwise>
  303.       <xsl:call-template name="process.image"/>
  304.     </xsl:otherwise>
  305.   </xsl:choose>
  306. </xsl:template>
  307.  
  308. <!-- ==================================================================== -->
  309.  
  310. <xsl:template match="mediaobject|mediaobjectco">
  311.   <fo:block>
  312.     <xsl:call-template name="select.mediaobject"/>
  313.     <xsl:apply-templates select="caption"/>
  314.   </fo:block>
  315. </xsl:template>
  316.  
  317. <xsl:template match="inlinemediaobject">
  318.   <xsl:call-template name="select.mediaobject"/>
  319. </xsl:template>
  320.  
  321. <!-- ==================================================================== -->
  322.  
  323. <xsl:template match="imageobjectco">
  324.   <xsl:apply-templates select="imageobject"/>
  325.   <xsl:apply-templates select="calloutlist"/>
  326. </xsl:template>
  327.  
  328. <xsl:template match="imageobject">
  329.   <xsl:choose>
  330.     <xsl:when test="imagedata">
  331.       <xsl:apply-templates select="imagedata"/>
  332.     </xsl:when>
  333.     <xsl:otherwise>
  334.       <fo:instream-foreign-object>
  335.         <xsl:apply-templates mode="copy-all"/>
  336.       </fo:instream-foreign-object>
  337.     </xsl:otherwise>
  338.   </xsl:choose>
  339. </xsl:template>
  340.  
  341. <!-- ==================================================================== -->
  342.  
  343. <xsl:template match="*" mode="copy-all">
  344.   <xsl:copy>
  345.     <xsl:for-each select="@*">
  346.       <xsl:copy/>
  347.     </xsl:for-each>
  348.     <xsl:apply-templates mode="copy-all"/>
  349.   </xsl:copy>
  350. </xsl:template>
  351.  
  352. <xsl:template match="text()|comment()|processing-instruction()" mode="copy-all">
  353.   <xsl:copy/>
  354. </xsl:template>
  355.  
  356. <!-- ==================================================================== -->
  357.  
  358. <xsl:template match="imagedata">
  359.   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  360.   <xsl:variable name="filename">
  361.     <xsl:call-template name="mediaobject.filename">
  362.       <xsl:with-param name="object" select=".."/>
  363.     </xsl:call-template>
  364.   </xsl:variable>
  365.  
  366.   <xsl:choose>
  367.     <xsl:when test="@format='linespecific'">
  368.       <xsl:choose>
  369.         <xsl:when test="$use.extensions != '0'
  370.                         and $textinsert.extension != '0'">
  371.           <xsl:choose>
  372.             <xsl:when test="contains($vendor, 'SAXON')">
  373.               <stext:insertfile href="{$filename}"/>
  374.             </xsl:when>
  375.             <xsl:when test="contains($vendor, 'Apache Software Foundation')">
  376.               <xtext:insertfile href="{$filename}"/>
  377.             </xsl:when>
  378.             <xsl:otherwise>
  379.               <xsl:message terminate="yes">
  380.                 <xsl:text>Don't know how to insert files with </xsl:text>
  381.                 <xsl:value-of select="$vendor"/>
  382.               </xsl:message>
  383.             </xsl:otherwise>
  384.           </xsl:choose>
  385.         </xsl:when>
  386.         <xsl:otherwise>
  387.           <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
  388.              href="{$filename}"/>
  389.         </xsl:otherwise>
  390.       </xsl:choose>
  391.     </xsl:when>
  392.     <xsl:otherwise>
  393.       <xsl:call-template name="process.image"/>
  394.     </xsl:otherwise>
  395.   </xsl:choose>
  396. </xsl:template>
  397.  
  398. <!-- ==================================================================== -->
  399.  
  400. <xsl:template match="videoobject">
  401.   <xsl:apply-templates select="videodata"/>
  402. </xsl:template>
  403.  
  404. <xsl:template match="videodata">
  405.   <xsl:call-template name="process.image"/>
  406. </xsl:template>
  407.  
  408. <!-- ==================================================================== -->
  409.  
  410. <xsl:template match="audioobject">
  411.   <xsl:apply-templates select="audiodata"/>
  412. </xsl:template>
  413.  
  414. <xsl:template match="audiodata">
  415.   <xsl:call-template name="process.image"/>
  416. </xsl:template>
  417.  
  418. <!-- ==================================================================== -->
  419.  
  420. <xsl:template match="textobject">
  421.   <xsl:apply-templates/>
  422. </xsl:template>
  423.  
  424. <xsl:template match="textdata">
  425.   <xsl:variable name="filename">
  426.     <xsl:choose>
  427.       <xsl:when test="@entityref">
  428.         <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  429.       </xsl:when>
  430.       <xsl:otherwise>
  431.         <xsl:value-of select="@fileref"/>
  432.       </xsl:otherwise>
  433.     </xsl:choose>
  434.   </xsl:variable>
  435.  
  436.   <xsl:choose>
  437.     <xsl:when test="$use.extensions != '0'
  438.                     and $textinsert.extension != '0'">
  439.       <xsl:choose>
  440.         <xsl:when test="element-available('stext:insertfile')">
  441.           <stext:insertfile href="{$filename}"/>
  442.         </xsl:when>
  443.         <xsl:when test="element-available('xtext:insertfile')">
  444.           <xtext:insertfile href="{$filename}"/>
  445.         </xsl:when>
  446.         <xsl:otherwise>
  447.           <xsl:message terminate="yes">
  448.             <xsl:text>No insertfile extension available.</xsl:text>
  449.           </xsl:message>
  450.         </xsl:otherwise>
  451.       </xsl:choose>
  452.     </xsl:when>
  453.     <xsl:otherwise>
  454.       <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
  455.          href="{$filename}"/>
  456.     </xsl:otherwise>
  457.   </xsl:choose>
  458. </xsl:template>
  459.  
  460. <!-- ==================================================================== -->
  461.  
  462. <xsl:template match="caption">
  463.   <fo:block>
  464.     <xsl:apply-templates/>
  465.   </fo:block>
  466. </xsl:template>
  467.  
  468. <!-- ==================================================================== -->
  469.  
  470. <xsl:template name="fo-external-image">
  471.   <xsl:param name="filename"/>
  472.  
  473.   <xsl:choose>
  474.     <xsl:when test="$passivetex.extensions != 0
  475.                     or $fop.extensions != 0
  476.                     or $arbortext.extensions != 0">
  477.       <xsl:value-of select="$filename"/>
  478.     </xsl:when>
  479.     <xsl:otherwise>
  480.       <xsl:value-of select="concat('url(', $filename, ')')"/>
  481.     </xsl:otherwise>
  482.   </xsl:choose>
  483. </xsl:template>
  484.  
  485. </xsl:stylesheet>
  486.