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

  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2.                 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  3.         version="1.0"
  4.                 exclude-result-prefixes="doc">
  5.  
  6. <xsl:import href="docbook.xsl"/>
  7. <xsl:import href="chunk-common.xsl"/>
  8.  
  9. <xsl:template name="chunk">
  10.   <xsl:param name="node" select="."/>
  11.   <!-- returns 1 if $node is a chunk -->
  12.  
  13.   <xsl:variable name="id">
  14.     <xsl:call-template name="object.id">
  15.       <xsl:with-param name="object" select="$node"/>
  16.     </xsl:call-template>
  17.   </xsl:variable>
  18.  
  19.   <xsl:variable name="chunks" select="document($chunk.toc,$node)"/>
  20.  
  21.   <xsl:choose>
  22.     <xsl:when test="$chunks//tocentry[@linkend=$id]">1</xsl:when>
  23.     <xsl:otherwise>0</xsl:otherwise>
  24.   </xsl:choose>
  25. </xsl:template>
  26.  
  27. <!-- ==================================================================== -->
  28.  
  29. <xsl:template match="*" mode="chunk-filename">
  30.   <!-- returns the filename of a chunk -->
  31.  
  32.   <xsl:variable name="id">
  33.     <xsl:call-template name="object.id"/>
  34.   </xsl:variable>
  35.  
  36.   <xsl:variable name="chunks" select="document($chunk.toc,.)"/>
  37.  
  38.   <xsl:variable name="chunk" select="$chunks//tocentry[@linkend=$id]"/>
  39.   <xsl:variable name="filename">
  40.     <xsl:call-template name="dbhtml-filename">
  41.       <xsl:with-param name="pis" select="$chunk/processing-instruction('dbhtml')"/>
  42.     </xsl:call-template>
  43.   </xsl:variable>
  44.  
  45.   <xsl:choose>
  46.     <xsl:when test="$chunk">
  47.       <xsl:value-of select="$filename"/>
  48.     </xsl:when>
  49.     <xsl:otherwise>
  50.       <xsl:apply-templates select="parent::*" mode="chunk-filename"/>
  51.     </xsl:otherwise>
  52.   </xsl:choose>
  53. </xsl:template>
  54.  
  55. <!-- ==================================================================== -->
  56.  
  57. <xsl:template name="process-chunk">
  58.   <xsl:variable name="id">
  59.     <xsl:call-template name="object.id"/>
  60.   </xsl:variable>
  61.  
  62.   <xsl:variable name="chunks" select="document($chunk.toc,.)"/>
  63.  
  64.   <xsl:variable name="chunk" select="$chunks//tocentry[@linkend=$id]"/>
  65.   <xsl:variable name="prev-id"
  66.                 select="($chunk/preceding::tocentry
  67.                          |$chunk/ancestor::tocentry)[last()]/@linkend"/>
  68.   <xsl:variable name="next-id"
  69.                 select="($chunk/following::tocentry
  70.                          |$chunk/child::tocentry)[1]/@linkend"/>
  71.  
  72.   <xsl:variable name="prev" select="key('id',$prev-id)"/>
  73.   <xsl:variable name="next" select="key('id',$next-id)"/>
  74.  
  75.   <xsl:variable name="ischunk">
  76.     <xsl:call-template name="chunk"/>
  77.   </xsl:variable>
  78.  
  79.   <xsl:variable name="chunkfn">
  80.     <xsl:if test="$ischunk='1'">
  81.       <xsl:apply-templates mode="chunk-filename" select="."/>
  82.     </xsl:if>
  83.   </xsl:variable>
  84.  
  85.   <xsl:variable name="filename">
  86.     <xsl:call-template name="make-relative-filename">
  87.       <xsl:with-param name="base.dir" select="$base.dir"/>
  88.       <xsl:with-param name="base.name" select="$chunkfn"/>
  89.     </xsl:call-template>
  90.   </xsl:variable>
  91.  
  92.   <xsl:choose>
  93.     <xsl:when test="$ischunk = 0">
  94.       <xsl:apply-imports/>
  95.     </xsl:when>
  96.  
  97.     <xsl:otherwise>
  98.       <xsl:call-template name="write.chunk">
  99.         <xsl:with-param name="filename" select="$filename"/>
  100.         <xsl:with-param name="content">
  101.           <xsl:call-template name="chunk-element-content">
  102.             <xsl:with-param name="prev" select="$prev"/>
  103.             <xsl:with-param name="next" select="$next"/>
  104.           </xsl:call-template>
  105.         </xsl:with-param>
  106.         <xsl:with-param name="quiet" select="$chunk.quietly"/>
  107.       </xsl:call-template>
  108.     </xsl:otherwise>
  109.   </xsl:choose>
  110. </xsl:template>
  111.  
  112. <!-- ==================================================================== -->
  113.  
  114. <xsl:template match="set">
  115.   <xsl:call-template name="process-chunk"/>
  116. </xsl:template>
  117.  
  118. <xsl:template match="book">
  119.   <xsl:call-template name="process-chunk"/>
  120. </xsl:template>
  121.  
  122. <xsl:template match="book/appendix">
  123.   <xsl:call-template name="process-chunk"/>
  124. </xsl:template>
  125.  
  126. <xsl:template match="book/glossary">
  127.   <xsl:call-template name="process-chunk"/>
  128. </xsl:template>
  129.  
  130. <xsl:template match="book/bibliography">
  131.   <xsl:call-template name="process-chunk"/>
  132. </xsl:template>
  133.  
  134. <xsl:template match="dedication" mode="dedication">
  135.   <xsl:call-template name="process-chunk"/>
  136. </xsl:template>
  137.  
  138. <xsl:template match="preface|chapter">
  139.   <xsl:call-template name="process-chunk"/>
  140. </xsl:template>
  141.  
  142. <xsl:template match="part|reference">
  143.   <xsl:call-template name="process-chunk"/>
  144. </xsl:template>
  145.  
  146. <xsl:template match="refentry">
  147.   <xsl:call-template name="process-chunk"/>
  148. </xsl:template>
  149.  
  150. <xsl:template match="colophon">
  151.   <xsl:call-template name="process-chunk"/>
  152. </xsl:template>
  153.  
  154. <xsl:template match="article">
  155.   <xsl:call-template name="process-chunk"/>
  156. </xsl:template>
  157.  
  158. <xsl:template match="article/appendix">
  159.   <xsl:call-template name="process-chunk"/>
  160. </xsl:template>
  161.  
  162. <xsl:template match="article/glossary">
  163.   <xsl:call-template name="process-chunk"/>
  164. </xsl:template>
  165.  
  166. <xsl:template match="article/bibliography">
  167.   <xsl:call-template name="process-chunk"/>
  168. </xsl:template>
  169.  
  170. <xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
  171.   <xsl:variable name="ischunk">
  172.     <xsl:call-template name="chunk"/>
  173.   </xsl:variable>
  174.  
  175.   <xsl:choose>
  176.     <xsl:when test="$ischunk != 0">
  177.       <xsl:call-template name="process-chunk"/>
  178.     </xsl:when>
  179.     <xsl:otherwise>
  180.       <xsl:apply-imports/>
  181.     </xsl:otherwise>
  182.   </xsl:choose>
  183. </xsl:template>
  184.  
  185. <xsl:template match="setindex
  186.                      |book/index
  187.                      |article/index">
  188.   <!-- some implementations use completely empty index tags to indicate -->
  189.   <!-- where an automatically generated index should be inserted. so -->
  190.   <!-- if the index is completely empty, skip it. -->
  191.   <xsl:if test="count(*)>0 or $generate.index != '0'">
  192.     <xsl:call-template name="process-chunk"/>
  193.   </xsl:if>
  194. </xsl:template>
  195.  
  196. <!-- ==================================================================== -->
  197.  
  198. <xsl:template match="/">
  199.   <xsl:choose>
  200.     <xsl:when test="$chunk.toc = ''">
  201.       <xsl:message terminate="yes">
  202.         <xsl:text>The chunk.toc file is not set.</xsl:text>
  203.       </xsl:message>
  204.     </xsl:when>
  205.  
  206.     <xsl:when test="$rootid != ''">
  207.       <xsl:choose>
  208.         <xsl:when test="count(key('id',$rootid)) = 0">
  209.           <xsl:message terminate="yes">
  210.             <xsl:text>ID '</xsl:text>
  211.             <xsl:value-of select="$rootid"/>
  212.             <xsl:text>' not found in document.</xsl:text>
  213.           </xsl:message>
  214.         </xsl:when>
  215.         <xsl:otherwise>
  216.           <xsl:apply-templates select="key('id',$rootid)"/>
  217.         </xsl:otherwise>
  218.       </xsl:choose>
  219.     </xsl:when>
  220.  
  221.     <xsl:otherwise>
  222.       <xsl:apply-templates select="/" mode="process.root"/>
  223.     </xsl:otherwise>
  224.   </xsl:choose>
  225. </xsl:template>
  226.  
  227. <xsl:template match="*" mode="process.root">
  228.   <xsl:apply-templates select="."/>
  229. </xsl:template>
  230.  
  231. </xsl:stylesheet>
  232.