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

  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.                 xmlns:exsl="http://exslt.org/common"
  4.                 exclude-result-prefixes="exsl"
  5.                 version='1.0'>
  6.  
  7. <!-- ********************************************************************
  8.      $Id: footnote.xsl,v 1.1.2.1 2002/09/04 13:50:26 jdj Exp $
  9.      ********************************************************************
  10.  
  11.      This file is part of the XSL DocBook Stylesheet distribution.
  12.      See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  13.      and other information.
  14.  
  15.      ******************************************************************** -->
  16.  
  17. <xsl:template match="footnote">
  18.   <xsl:variable name="name">
  19.     <xsl:call-template name="object.id"/>
  20.   </xsl:variable>
  21.   <xsl:variable name="href">
  22.     <xsl:text>#ftn.</xsl:text>
  23.     <xsl:call-template name="object.id"/>
  24.   </xsl:variable>
  25.  
  26.   <xsl:choose>
  27.     <xsl:when test="ancestor::tgroup">
  28.       <sup>
  29.         <xsl:text>[</xsl:text>
  30.         <a name="{$name}" href="{$href}">
  31.           <xsl:apply-templates select="." mode="footnote.number"/>
  32.         </a>
  33.         <xsl:text>]</xsl:text>
  34.       </sup>
  35.     </xsl:when>
  36.     <xsl:otherwise>
  37.       <sup>
  38.         <xsl:text>[</xsl:text>
  39.         <a name="{$name}" href="{$href}">
  40.           <xsl:apply-templates select="." mode="footnote.number"/>
  41.         </a>
  42.         <xsl:text>]</xsl:text>
  43.       </sup>
  44.     </xsl:otherwise>
  45.   </xsl:choose>
  46. </xsl:template>
  47.  
  48. <xsl:template match="footnoteref">
  49.   <xsl:variable name="targets" select="key('id',@linkend)"/>
  50.   <xsl:variable name="footnote" select="$targets[1]"/>
  51.   <xsl:variable name="href">
  52.     <xsl:text>#ftn.</xsl:text>
  53.     <xsl:call-template name="object.id">
  54.       <xsl:with-param name="object" select="$footnote"/>
  55.     </xsl:call-template>
  56.   </xsl:variable>
  57.   <sup>
  58.     <xsl:text>[</xsl:text>
  59.     <a href="{$href}">
  60.       <xsl:apply-templates select="$footnote" mode="footnote.number"/>
  61.     </a>
  62.     <xsl:text>]</xsl:text>
  63.   </sup>
  64. </xsl:template>
  65.  
  66. <xsl:template match="footnote" mode="footnote.number">
  67.   <xsl:choose>
  68.     <xsl:when test="ancestor::tgroup">
  69.       <xsl:number level="any" from="table|informaltable" format="a"/>
  70.     </xsl:when>
  71.     <xsl:when test="ancestor::refentry">
  72.       <xsl:number level="any" from="refentry" format="1"/>
  73.     </xsl:when>
  74.     <xsl:otherwise>
  75.       <xsl:variable name="pfoot" select="preceding::footnote"/>
  76.       <xsl:variable name="ptfoot" select="preceding::table//footnote
  77.                                           |preceding::informaltable//footnote"/>
  78.       <xsl:number value="count($pfoot) - count($ptfoot) + 1" format="1"/>
  79.     </xsl:otherwise>
  80.   </xsl:choose>
  81. </xsl:template>
  82.  
  83. <!-- ==================================================================== -->
  84.  
  85. <xsl:template match="footnote/para[1]|footnote/simpara[1]" priority="2">
  86.   <!-- this only works if the first thing in a footnote is a para, -->
  87.   <!-- which is ok, because it usually is. -->
  88.   <xsl:variable name="name">
  89.     <xsl:text>ftn.</xsl:text>
  90.     <xsl:call-template name="object.id">
  91.       <xsl:with-param name="object" select="ancestor::footnote"/>
  92.     </xsl:call-template>
  93.   </xsl:variable>
  94.   <xsl:variable name="href">
  95.     <xsl:text>#</xsl:text>
  96.     <xsl:call-template name="object.id">
  97.       <xsl:with-param name="object" select="ancestor::footnote"/>
  98.     </xsl:call-template>
  99.   </xsl:variable>
  100.   <p>
  101.     <sup>
  102.       <xsl:text>[</xsl:text>
  103.       <a name="{$name}" href="{$href}">
  104.         <xsl:apply-templates select="ancestor::footnote"
  105.                              mode="footnote.number"/>
  106.       </a>
  107.       <xsl:text>] </xsl:text>
  108.     </sup>
  109.     <xsl:apply-templates/>
  110.   </p>
  111. </xsl:template>
  112.  
  113. <!-- ==================================================================== -->
  114.  
  115. <xsl:template match="*" mode="footnote.body.number">
  116.   <xsl:variable name="name">
  117.     <xsl:text>ftn.</xsl:text>
  118.     <xsl:call-template name="object.id">
  119.       <xsl:with-param name="object" select="ancestor::footnote"/>
  120.     </xsl:call-template>
  121.   </xsl:variable>
  122.   <xsl:variable name="href">
  123.     <xsl:text>#</xsl:text>
  124.     <xsl:call-template name="object.id">
  125.       <xsl:with-param name="object" select="ancestor::footnote"/>
  126.     </xsl:call-template>
  127.   </xsl:variable>
  128.   <xsl:variable name="footnote.mark">
  129.     <sup>
  130.       <xsl:text>[</xsl:text>
  131.       <a name="{$name}" href="{$href}">
  132.         <xsl:apply-templates select="ancestor::footnote"
  133.                              mode="footnote.number"/>
  134.       </a>
  135.       <xsl:text>] </xsl:text>
  136.     </sup>
  137.   </xsl:variable>
  138.  
  139.   <xsl:variable name="html">
  140.     <xsl:apply-templates select="."/>
  141.   </xsl:variable>
  142.  
  143.   <xsl:choose>
  144.     <xsl:when test="function-available('exsl:node-set')">
  145.       <xsl:variable name="html-nodes" select="exsl:node-set($html)"/>
  146.       <xsl:choose>
  147.         <xsl:when test="$html-nodes//p">
  148.           <xsl:apply-templates select="$html-nodes" mode="insert.html.p">
  149.             <xsl:with-param name="mark" select="$footnote.mark"/>
  150.           </xsl:apply-templates>
  151.         </xsl:when>
  152.         <xsl:otherwise>
  153.           <xsl:apply-templates select="$html-nodes" mode="insert.html.text">
  154.             <xsl:with-param name="mark" select="$footnote.mark"/>
  155.           </xsl:apply-templates>
  156.         </xsl:otherwise>
  157.       </xsl:choose>
  158.     </xsl:when>
  159.     <xsl:otherwise>
  160.       <xsl:copy-of select="$html"/>
  161.     </xsl:otherwise>
  162.   </xsl:choose>
  163. </xsl:template>
  164.  
  165. <!-- ==================================================================== -->
  166.  
  167. <!--
  168. <xsl:template name="count-element-from">
  169.   <xsl:param name="from" select=".."/>
  170.   <xsl:param name="to" select="."/>
  171.   <xsl:param name="count" select="0"/>
  172.   <xsl:param name="list" select="$from/following::*[name(.)=name($to)]
  173.                                  |$from/descendant-or-self::*[name(.)=name($to)]"/>
  174.  
  175.   <xsl:choose>
  176.     <xsl:when test="not($list)">
  177.       <xsl:text>-1</xsl:text>
  178.     </xsl:when>
  179.     <xsl:when test="$list[1] = $to">
  180.       <xsl:value-of select="$count + 1"/>
  181.     </xsl:when>
  182.     <xsl:otherwise>
  183.     </xsl:otherwise>
  184.   </xsl:choose>
  185. </xsl:template>
  186. -->
  187.  
  188. <!-- ==================================================================== -->
  189.  
  190. <xsl:template name="process.footnotes">
  191.   <xsl:variable name="footnotes" select=".//footnote"/>
  192.   <xsl:variable name="table.footnotes"
  193.                 select=".//tgroup//footnote"/>
  194.  
  195.   <!-- Only bother to do this if there's at least one non-table footnote -->
  196.   <xsl:if test="count($footnotes)>count($table.footnotes)">
  197.     <div class="footnotes">
  198.       <br/>
  199.       <hr width="100" align="left"/>
  200.       <xsl:apply-templates select="$footnotes" mode="process.footnote.mode"/>
  201.     </div>
  202.   </xsl:if>
  203. </xsl:template>
  204.  
  205. <xsl:template name="process.chunk.footnotes">
  206.   <!-- nop -->
  207. </xsl:template>
  208.  
  209. <xsl:template match="footnote" name="process.footnote" mode="process.footnote.mode">
  210.   <xsl:choose>
  211.     <xsl:when test="local-name(*[1]) = 'para' or local-name(*[1]) = 'simpara'">
  212.       <div class="{name(.)}">
  213.         <xsl:apply-templates/>
  214.       </div>
  215.     </xsl:when>
  216.  
  217.     <xsl:when test="$html.cleanup != 0 and function-available('exsl:node-set')">
  218.       <div class="{name(.)}">
  219.         <xsl:apply-templates select="*[1]" mode="footnote.body.number"/>
  220.         <xsl:apply-templates select="*[position() > 1]"/>
  221.       </div>
  222.     </xsl:when>
  223.  
  224.     <xsl:otherwise>
  225.       <xsl:message>
  226.         <xsl:text>Warning: footnote number may not be generated </xsl:text>
  227.         <xsl:text>correctly; </xsl:text>
  228.         <xsl:value-of select="local-name(*[1])"/>
  229.         <xsl:text> unexpected as first child of footnote.</xsl:text>
  230.       </xsl:message>
  231.       <div class="{name(.)}">
  232.         <xsl:apply-templates/>
  233.       </div>
  234.     </xsl:otherwise>
  235.   </xsl:choose>
  236. </xsl:template>
  237.  
  238. <xsl:template match="tgroup//footnote"
  239.               mode="process.footnote.mode">
  240. </xsl:template>
  241.  
  242. <xsl:template match="footnote" mode="table.footnote.mode">
  243.   <xsl:call-template name="process.footnote"/>
  244. </xsl:template>
  245.  
  246. </xsl:stylesheet>
  247.