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

  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.                 version='1.0'>
  4.  
  5. <!-- ********************************************************************
  6.      $Id: math.xsl,v 1.1.2.1 2002/09/04 13:50:42 jdj Exp $
  7.      ********************************************************************
  8.  
  9.      This file is part of the XSL DocBook Stylesheet distribution.
  10.      See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  11.      and other information.
  12.  
  13.      ******************************************************************** -->
  14.  
  15. <xsl:template match="inlineequation">
  16.   <xsl:apply-templates/>
  17. </xsl:template>
  18.  
  19. <xsl:template match="alt">
  20. </xsl:template>
  21.  
  22. <!-- "Support" for MathML -->
  23.  
  24. <xsl:template match="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
  25.   <xsl:copy>
  26.     <xsl:copy-of select="@*"/>
  27.     <xsl:apply-templates/>
  28.   </xsl:copy>
  29. </xsl:template>
  30.  
  31. <!-- Support for TeX math in alt -->
  32.  
  33. <xsl:template match="*" mode="collect.tex.math">
  34.   <xsl:call-template name="write.text.chunk">
  35.     <xsl:with-param name="filename" select="$tex.math.file"/>
  36.     <xsl:with-param name="method" select="'text'"/>
  37.     <xsl:with-param name="content">
  38.       <xsl:choose>
  39.         <xsl:when test="$tex.math.in.alt = 'plain'">
  40.           <xsl:call-template name="tex.math.plain.head"/>
  41.           <xsl:apply-templates select="." mode="collect.tex.math.plain"/>
  42.           <xsl:call-template name="tex.math.plain.tail"/>
  43.         </xsl:when>
  44.         <xsl:when test="$tex.math.in.alt = 'latex'">
  45.           <xsl:call-template name="tex.math.latex.head"/>
  46.           <xsl:apply-templates select="." mode="collect.tex.math.latex"/>
  47.           <xsl:call-template name="tex.math.latex.tail"/>
  48.         </xsl:when>
  49.         <xsl:otherwise>
  50.           <xsl:message>
  51.             Unsupported TeX math notation: 
  52.             <xsl:value-of select="$tex.math.in.alt"/>
  53.           </xsl:message>
  54.         </xsl:otherwise>
  55.       </xsl:choose>
  56.     </xsl:with-param>
  57.     <xsl:with-param name="encoding" select="$chunker.output.encoding"/>
  58.   </xsl:call-template>
  59. </xsl:template>
  60.  
  61. <!-- PlainTeX -->
  62.  
  63. <xsl:template name="tex.math.plain.head">
  64.   <xsl:text>\nopagenumbers  </xsl:text>
  65. </xsl:template>
  66.  
  67. <xsl:template name="tex.math.plain.tail">
  68.   <xsl:text>\bye  </xsl:text>
  69. </xsl:template>
  70.  
  71. <xsl:template match="inlineequation" mode="collect.tex.math.plain">
  72.   <xsl:variable name="filename">
  73.     <xsl:choose>
  74.       <xsl:when test="graphic">
  75.         <xsl:call-template name="mediaobject.filename">
  76.           <xsl:with-param name="object" select="graphic"/>
  77.         </xsl:call-template>
  78.       </xsl:when>
  79.       <xsl:otherwise>
  80.         <xsl:call-template name="select.mediaobject.filename">
  81.           <xsl:with-param name="olist" select="inlinemediaobject/*"/>
  82.         </xsl:call-template>
  83.       </xsl:otherwise>
  84.     </xsl:choose>
  85.   </xsl:variable>
  86.   <xsl:variable name="output.delims">
  87.     <xsl:call-template name="tex.math.output.delims"/>
  88.   </xsl:variable>
  89.   <xsl:variable name="tex" select="alt[@role='tex'] | inlinemediaobject/textobject[@role='tex']"/>
  90.   <xsl:if test="$tex">
  91.     <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
  92.     <xsl:value-of select="$filename"/>
  93.     <xsl:text>}  </xsl:text>
  94.     <xsl:if test="$output.delims != 0">
  95.       <xsl:text>$</xsl:text>
  96.     </xsl:if>
  97.     <xsl:value-of select="$tex"/>
  98.     <xsl:if test="$output.delims != 0">
  99.       <xsl:text>$  </xsl:text>
  100.     </xsl:if>
  101.     <xsl:text>\vfill\eject  </xsl:text>
  102.   </xsl:if>
  103. </xsl:template>
  104.  
  105. <xsl:template match="equation|informalequation" mode="collect.tex.math.plain">
  106.   <xsl:variable name="filename">
  107.     <xsl:choose>
  108.       <xsl:when test="graphic">
  109.         <xsl:call-template name="mediaobject.filename">
  110.           <xsl:with-param name="object" select="graphic"/>
  111.         </xsl:call-template>
  112.       </xsl:when>
  113.       <xsl:otherwise>
  114.         <xsl:call-template name="select.mediaobject.filename">
  115.           <xsl:with-param name="olist" select="mediaobject/*"/>
  116.         </xsl:call-template>
  117.       </xsl:otherwise>
  118.     </xsl:choose>
  119.   </xsl:variable>
  120.   <xsl:variable name="output.delims">
  121.     <xsl:call-template name="tex.math.output.delims"/>
  122.   </xsl:variable>
  123.   <xsl:variable name="tex" select="alt[@role='tex'] | mediaobject/textobject[@role='tex']"/>
  124.   <xsl:if test="$tex">
  125.     <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
  126.     <xsl:value-of select="$filename"/>
  127.     <xsl:text>}  </xsl:text>
  128.     <xsl:if test="$output.delims != 0">
  129.       <xsl:text>$$</xsl:text>
  130.     </xsl:if>
  131.     <xsl:value-of select="$tex"/>
  132.     <xsl:if test="$output.delims != 0">
  133.       <xsl:text>$$  </xsl:text>
  134.     </xsl:if>
  135.     <xsl:text>\vfill\eject  </xsl:text>
  136.   </xsl:if>
  137. </xsl:template>
  138.  
  139. <xsl:template match="text()" mode="collect.tex.math.plain"/>
  140.  
  141. <!-- LaTeX -->
  142.  
  143. <xsl:template name="tex.math.latex.head">
  144.   <xsl:text>\documentclass{article}  </xsl:text>
  145.   <xsl:text>\pagestyle{empty}  </xsl:text>
  146.   <xsl:text>\begin{document}  </xsl:text>
  147. </xsl:template>
  148.  
  149. <xsl:template name="tex.math.latex.tail">
  150.   <xsl:text>\end{document}  </xsl:text>
  151. </xsl:template>
  152.  
  153. <xsl:template match="inlineequation" mode="collect.tex.math.latex">
  154.   <xsl:variable name="filename">
  155.     <xsl:choose>
  156.       <xsl:when test="graphic">
  157.         <xsl:call-template name="mediaobject.filename">
  158.           <xsl:with-param name="object" select="graphic"/>
  159.         </xsl:call-template>
  160.       </xsl:when>
  161.       <xsl:otherwise>
  162.         <xsl:call-template name="select.mediaobject.filename">
  163.           <xsl:with-param name="olist" select="inlinemediaobject/*"/>
  164.         </xsl:call-template>
  165.       </xsl:otherwise>
  166.     </xsl:choose>
  167.   </xsl:variable>
  168.   <xsl:variable name="output.delims">
  169.     <xsl:call-template name="tex.math.output.delims"/>
  170.   </xsl:variable>
  171.   <xsl:variable name="tex" select="alt[@role='tex'] | inlinemediaobject/textobject[@role='tex']"/>
  172.   <xsl:if test="$tex">
  173.     <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
  174.     <xsl:value-of select="$filename"/>
  175.     <xsl:text>}  </xsl:text>
  176.     <xsl:if test="$output.delims != 0">  
  177.       <xsl:text>$</xsl:text>
  178.     </xsl:if>
  179.     <xsl:value-of select="$tex"/>
  180.     <xsl:if test="$output.delims != 0">  
  181.       <xsl:text>$  </xsl:text>
  182.     </xsl:if>
  183.     <xsl:text>\newpage  </xsl:text>
  184.   </xsl:if>
  185. </xsl:template>
  186.  
  187. <xsl:template match="equation|informalequation" mode="collect.tex.math.latex">
  188.   <xsl:variable name="filename">
  189.     <xsl:choose>
  190.       <xsl:when test="graphic">
  191.         <xsl:call-template name="mediaobject.filename">
  192.           <xsl:with-param name="object" select="graphic"/>
  193.         </xsl:call-template>
  194.       </xsl:when>
  195.       <xsl:otherwise>
  196.         <xsl:call-template name="select.mediaobject.filename">
  197.           <xsl:with-param name="olist" select="mediaobject/*"/>
  198.         </xsl:call-template>
  199.       </xsl:otherwise>
  200.     </xsl:choose>
  201.   </xsl:variable>
  202.   <xsl:variable name="output.delims">
  203.     <xsl:call-template name="tex.math.output.delims"/>
  204.   </xsl:variable>
  205.   <xsl:variable name="tex" select="alt[@role='tex'] | mediaobject/textobject[@role='tex']"/>
  206.   <xsl:if test="$tex">
  207.     <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
  208.     <xsl:value-of select="$filename"/>
  209.     <xsl:text>}  </xsl:text>
  210.     <xsl:if test="$output.delims != 0">
  211.       <xsl:text>$$</xsl:text>
  212.     </xsl:if>
  213.     <xsl:value-of select="$tex"/>
  214.     <xsl:if test="$output.delims != 0">
  215.       <xsl:text>$$  </xsl:text>
  216.     </xsl:if>
  217.     <xsl:text>\newpage  </xsl:text>
  218.   </xsl:if>
  219. </xsl:template>
  220.  
  221. <xsl:template match="text()" mode="collect.tex.math.latex"/>
  222.  
  223. <!-- Extracting image filename from mediaobject and graphic elements -->
  224.  
  225. <xsl:template name="select.mediaobject.filename">
  226.   <xsl:param name="olist"
  227.              select="imageobject|imageobjectco
  228.                      |videoobject|audioobject|textobject"/>
  229.   <xsl:param name="count">1</xsl:param>
  230.  
  231.   <xsl:if test="$count <= count($olist)">
  232.     <xsl:variable name="object" select="$olist[position()=$count]"/>
  233.  
  234.     <xsl:variable name="useobject">
  235.       <xsl:choose>
  236.     <!-- The phrase is never used -->
  237.         <xsl:when test="name($object)='textobject' and $object/phrase">
  238.           <xsl:text>0</xsl:text>
  239.         </xsl:when>
  240.     <!-- The first textobject is not a reasonable fallback for equation image -->
  241.         <xsl:when test="name($object)='textobject'">
  242.           <xsl:text>0</xsl:text>
  243.         </xsl:when>
  244.     <!-- If there's only one object, use it -->
  245.     <xsl:when test="$count = 1 and count($olist) = 1">
  246.       <xsl:text>1</xsl:text>
  247.     </xsl:when>
  248.     <!-- Otherwise, see if this one is a useable graphic -->
  249.         <xsl:otherwise>
  250.           <xsl:choose>
  251.             <!-- peek inside imageobjectco to simplify the test -->
  252.             <xsl:when test="local-name($object) = 'imageobjectco'">
  253.               <xsl:call-template name="is.acceptable.mediaobject">
  254.                 <xsl:with-param name="object" select="$object/imageobject"/>
  255.               </xsl:call-template>
  256.             </xsl:when>
  257.             <xsl:otherwise>
  258.               <xsl:call-template name="is.acceptable.mediaobject">
  259.                 <xsl:with-param name="object" select="$object"/>
  260.               </xsl:call-template>
  261.             </xsl:otherwise>
  262.           </xsl:choose>
  263.         </xsl:otherwise>
  264.       </xsl:choose>
  265.     </xsl:variable>
  266.  
  267.     <xsl:choose>
  268.       <xsl:when test="$useobject='1'">
  269.         <xsl:call-template name="mediaobject.filename">
  270.           <xsl:with-param name="object" select="$object"/>
  271.         </xsl:call-template>
  272.       </xsl:when>
  273.       <xsl:otherwise>
  274.         <xsl:call-template name="select.mediaobject">
  275.           <xsl:with-param name="olist" select="$olist"/>
  276.           <xsl:with-param name="count" select="$count + 1"/>
  277.         </xsl:call-template>
  278.       </xsl:otherwise>
  279.     </xsl:choose>
  280.   </xsl:if>
  281. </xsl:template>
  282.  
  283. <xsl:template name="tex.math.output.delims">
  284.   <xsl:variable name="pi.delims">
  285.     <xsl:call-template name="pi-attribute">
  286.       <xsl:with-param name="pis" select=".//processing-instruction('dbtex')"/>
  287.       <xsl:with-param name="attribute" select="'delims'"/>
  288.     </xsl:call-template>
  289.   </xsl:variable>
  290.   <xsl:variable name="result">
  291.     <xsl:choose>
  292.       <xsl:when test="$pi.delims = 'no'">0</xsl:when>
  293.       <xsl:when test="$pi.delims = '' and $tex.math.delims = 0">0</xsl:when>
  294.       <xsl:otherwise>1</xsl:otherwise>
  295.     </xsl:choose>
  296.   </xsl:variable>
  297.   <xsl:value-of select="$result"/>
  298. </xsl:template>
  299.  
  300. </xsl:stylesheet>
  301.