home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 October / INTERNET108.ISO / pc / software / windows / building / xmlspy / xmlspyentcomplete5.exe / Data1.cab / _AF3B4C30F5F34879BBCE5627ACF0DBDD < prev    next >
Encoding:
Text File  |  2002-10-21  |  12.5 KB  |  381 lines

  1. <!-- 
  2. TEI XSLT stylesheet family version 1.2
  3. RCS: $Date: 2002/10/21 13:44:30 $, $Revision: 1.1.2.1 $, $Author: jdj $
  4.  
  5. XSL stylesheet to format TEI XML documents to HTML or XSL FO
  6.  
  7.  Copyright 1999-2002 Sebastian Rahtz/Oxford University  <sebastian.rahtz@oucs.ox.ac.uk>
  8.  
  9.  Permission is hereby granted, free of charge, to any person obtaining
  10.  a copy of this software and any associated documentation files (the
  11.  ``Software''), to deal in the Software without restriction, including
  12.  without limitation the rights to use, copy, modify, merge, publish,
  13.  distribute, sublicense, and/or sell copies of the Software, and to
  14.  permit persons to whom the Software is furnished to do so, subject to
  15.  the following conditions:
  16.  
  17.  The above copyright notice and this permission notice shall be included
  18.  in all copies or substantial portions of the Software.
  19. --> 
  20. <xsl:stylesheet
  21.   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  22.  
  23.  
  24. <!-- cross-referencing -->
  25.  
  26. <!-- work out an ID for a given <div> -->
  27.  <xsl:template match="*" mode="ident">
  28.  <xsl:variable name="BaseFile">
  29.  <xsl:value-of select="$masterFile"/>
  30.   <xsl:if test="ancestor::teiCorpus.2">
  31.     <xsl:text>-</xsl:text>
  32.      <xsl:choose>
  33.       <xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when> 
  34.       <xsl:otherwise><xsl:number/></xsl:otherwise>
  35.      </xsl:choose>
  36.   </xsl:if>
  37. </xsl:variable>
  38.   <xsl:choose>
  39.   <xsl:when test="@id">
  40.     <xsl:choose>
  41.      <xsl:when test="$useIDs">
  42.        <xsl:value-of select="@id"/>
  43.      </xsl:when>
  44.      <xsl:otherwise>
  45.       <xsl:value-of select="$BaseFile"/>-<xsl:value-of select="name(.)"/>-<xsl:value-of select="generate-id()"/>
  46.      </xsl:otherwise>
  47.     </xsl:choose>
  48.   </xsl:when>
  49.   <xsl:when test="self::div and not(ancestor::div)"> 
  50.   <xsl:variable name="xpath">
  51.        <xsl:for-each select="ancestor-or-self::*">
  52.     <xsl:value-of select="name()" />
  53.     <xsl:text />.<xsl:number />
  54.     <xsl:if test="position() != last()">_</xsl:if>
  55.   </xsl:for-each>
  56.   </xsl:variable>
  57.   <xsl:value-of select="substring-after($xpath,'text.1_')"/>
  58.   </xsl:when>
  59.   <xsl:when test="self::divGen"> 
  60.   <xsl:variable name="xpath">
  61.        <xsl:for-each select="ancestor-or-self::*">
  62.     <xsl:value-of select="name()" />
  63.     <xsl:text />.<xsl:number />
  64.     <xsl:if test="position() != last()">_</xsl:if>
  65.   </xsl:for-each>
  66.   </xsl:variable>
  67.   <xsl:value-of select="substring-after($xpath,'text.1_')"/>
  68.   </xsl:when>
  69.   <xsl:otherwise>
  70.    <xsl:value-of select="$BaseFile"/>-<xsl:value-of select="name(.)"/>-<xsl:value-of select="generate-id()"/>
  71.   </xsl:otherwise>
  72.   </xsl:choose>
  73. </xsl:template>
  74.  
  75. <!-- when a <div> is referenced, see whether its  plain anchor, 
  76.  or needs a parent HTML name prepended -->
  77.  
  78.  
  79. <xsl:template match="TEI.2" mode="xrefheader">
  80. <xsl:variable name="BaseFile">
  81.   <xsl:value-of select="$masterFile"/>
  82.   <xsl:if test="ancestor::teiCorpus.2">
  83.     <xsl:text>-</xsl:text>
  84.      <xsl:choose>
  85.       <xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when> 
  86.       <xsl:otherwise><xsl:number/></xsl:otherwise>
  87.      </xsl:choose>
  88.   </xsl:if>
  89. </xsl:variable>
  90.   <xsl:value-of select="concat($BaseFile,$standardSuffix)"/>
  91. </xsl:template>
  92.  
  93. <xsl:template match="div|div0|div1|div2|div3|div4|div5|div6" mode="xrefheader">
  94.   <xsl:variable name="ident">
  95.    <xsl:apply-templates select="." mode="ident"/>
  96.   </xsl:variable>
  97.   <xsl:variable name="depth">
  98.    <xsl:apply-templates select="." mode="depth"/>
  99.   </xsl:variable>
  100.   <xsl:variable name="Hash">
  101.    <xsl:if test="$makeFrames='true' and not($STDOUT='true')">
  102.     <xsl:value-of select="$masterFile"/>
  103.     <xsl:if test="ancestor::teiCorpus.2">
  104.      <xsl:text>-</xsl:text>
  105.       <xsl:choose>
  106.       <xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when> 
  107.       <xsl:otherwise><xsl:number/></xsl:otherwise>
  108.      </xsl:choose>
  109.     </xsl:if>
  110.     <xsl:text>.html</xsl:text>
  111.    </xsl:if>
  112.    <xsl:text>#</xsl:text>
  113.   </xsl:variable>
  114.   <xsl:choose>
  115.    <xsl:when test="$rawIE='true' and $depth <= $splitLevel">
  116.        <xsl:text>JavaScript:void(gotoSection('','</xsl:text>
  117.        <xsl:value-of select="$ident"/>
  118.        <xsl:text>'));</xsl:text>
  119.    </xsl:when>
  120.    <xsl:when test="$STDOUT='true' and $depth <= $splitLevel">
  121.      <xsl:value-of select="$masterFile"/>
  122.      <xsl:value-of select="$urlChunkPrefix"/>
  123.      <xsl:value-of select="$ident"/>
  124.    </xsl:when>
  125.    <xsl:when test="ancestor::back and not($splitBackmatter)">
  126.        <xsl:value-of select="concat($Hash,$ident)"/>
  127.    </xsl:when>
  128.    <xsl:when test="ancestor::front and not($splitFrontmatter)">
  129.        <xsl:value-of select="concat($Hash,$ident)"/>
  130.    </xsl:when>
  131.    <xsl:when test="$splitLevel= -1">
  132.     <xsl:value-of select="concat($Hash,$ident)"/>
  133.    </xsl:when>
  134.    <xsl:when test="$depth <= $splitLevel">
  135.      <xsl:value-of select="concat($ident,$standardSuffix)"/>
  136.    </xsl:when>
  137.    <xsl:otherwise>
  138.    <xsl:variable name="parent">
  139.       <xsl:call-template name="locateParentdiv"/>
  140.    </xsl:variable>
  141.    <xsl:choose>
  142.      <xsl:when test="$rawIE='true'">
  143.        <xsl:text>JavaScript:void(gotoSection("</xsl:text>
  144.        <xsl:value-of select="$ident"/>
  145.        <xsl:text>","</xsl:text>
  146.        <xsl:value-of select="$parent"/>
  147.      <xsl:text>"));</xsl:text>
  148.      </xsl:when>
  149.      <xsl:when test="$STDOUT='true'">
  150.        <xsl:value-of select="$masterFile"/>
  151.        <xsl:text>.ID=</xsl:text>
  152.        <xsl:value-of select="$parent"/>
  153.        <xsl:value-of select="concat($standardSuffix,'#')"/>
  154.        <xsl:value-of select="$ident"/>
  155.      </xsl:when>
  156.      <xsl:otherwise>
  157.        <xsl:value-of select="$parent"/>
  158.       <xsl:value-of select="concat($standardSuffix,'#')"/>
  159.       <xsl:value-of select="$ident"/>
  160.      </xsl:otherwise>
  161.    </xsl:choose>
  162.    </xsl:otherwise>
  163.   </xsl:choose>
  164. </xsl:template>
  165.  
  166. <xsl:template name="locateParentdiv">
  167.   <xsl:choose>
  168.   <xsl:when test="ancestor-or-self::div">
  169.   <xsl:apply-templates
  170.      select="ancestor::div[last() - $splitLevel]" mode="ident"/>
  171.   </xsl:when>
  172.   <xsl:otherwise>
  173.    <xsl:choose>
  174.     <xsl:when test="$splitLevel = 0">
  175.       <xsl:apply-templates select="ancestor::div1|ancestor::div0" mode="ident"/>
  176.     </xsl:when>
  177.     <xsl:when test="$splitLevel = 1">
  178.       <xsl:apply-templates select="(ancestor::div2|ancestor::div1|ancestor::div0)[last()]" mode="ident"/>
  179.     </xsl:when>
  180.     <xsl:when test="$splitLevel = 2">
  181.       <xsl:apply-templates select="(ancestor::div3|ancestor::div2)[last()]" mode="ident"/>
  182.     </xsl:when>
  183.     <xsl:when test="$splitLevel = 3">
  184.       <xsl:apply-templates select="(ancestor::div4|ancestor::div3)[last()]" mode="ident"/>
  185.     </xsl:when>
  186.     <xsl:when test="$splitLevel = 4">
  187.       <xsl:apply-templates select="(ancestor::div5|ancestor::div4)[last()]" mode="ident"/>
  188.     </xsl:when>
  189.    </xsl:choose>
  190.   </xsl:otherwise>
  191.   </xsl:choose>
  192. </xsl:template>
  193.  
  194. <xsl:template name="locateParent">
  195.   <xsl:choose>
  196.   <xsl:when test="self::div">
  197.   <xsl:apply-templates
  198.      select="ancestor::div[last() - $splitLevel + 1]" mode="ident"/>
  199.   </xsl:when>
  200.   <xsl:when test="ancestor::div">
  201.   <xsl:apply-templates
  202.      select="ancestor::div[last() - $splitLevel]" mode="ident"/>
  203.   </xsl:when>
  204.   <xsl:otherwise>
  205.    <xsl:choose>
  206.     <xsl:when test="$splitLevel = 0">
  207.       <xsl:apply-templates select="ancestor::div1|ancestor::div0" mode="ident"/>
  208.     </xsl:when>
  209.     <xsl:when test="$splitLevel = 1">
  210.       <xsl:apply-templates select="ancestor::div2|ancestor::div1|ancestor::div0" mode="ident"/>
  211.     </xsl:when>
  212.     <xsl:when test="$splitLevel = 2">
  213.       <xsl:apply-templates select="ancestor::div3|ancestor::div2" mode="ident"/>
  214.     </xsl:when>
  215.     <xsl:when test="$splitLevel = 3">
  216.       <xsl:apply-templates select="ancestor::div4|ancestor::div3" mode="ident"/>
  217.     </xsl:when>
  218.     <xsl:when test="$splitLevel = 4">
  219.       <xsl:apply-templates select="ancestor::div5|ancestor::div4" mode="ident"/>
  220.     </xsl:when>
  221.    </xsl:choose>
  222.   </xsl:otherwise>
  223.   </xsl:choose>
  224. </xsl:template>
  225.  
  226. <xsl:template match="ref">
  227.  <a class="ref">
  228.  <xsl:attribute name="href">
  229.       <xsl:apply-templates mode="xrefheader" select="key('IDS',@target)"/>
  230.  </xsl:attribute>
  231.  <xsl:apply-templates/>
  232.  </a>
  233. </xsl:template>
  234.  
  235. <xsl:template match="anchor">
  236.    <a name="{@id}"/>
  237. </xsl:template>
  238.  
  239. <xsl:template match="note" mode="header">
  240.    <xsl:number level="any"/>
  241. </xsl:template>
  242.  
  243. <xsl:template match="note" mode="xrefheader">
  244.     <xsl:text>#Note</xsl:text>
  245.     <xsl:call-template name="noteID"/>
  246. </xsl:template>
  247.  
  248.  
  249. <xsl:template match="anchor|p" mode="header">
  250.   <xsl:text>here</xsl:text>
  251. </xsl:template>
  252.  
  253. <xsl:template match="label|figure|item|p|bibl|anchor|cell|lg|list" 
  254.   mode="xrefheader">
  255.   <xsl:variable name="ident">
  256.    <xsl:apply-templates select="." mode="ident"/>
  257.   </xsl:variable>
  258.  <xsl:variable name="file">
  259.  <xsl:apply-templates 
  260.    select="ancestor::*[starts-with(name(),'div')][1]"  
  261.    mode="xrefheader"/>
  262.  </xsl:variable>
  263.  <xsl:choose>
  264.   <xsl:when test="starts-with($file,'#')">
  265.     <xsl:text>#</xsl:text><xsl:value-of select="$ident"/>
  266.   </xsl:when>
  267.   <xsl:when test="contains($file,'#')">
  268.     <xsl:value-of select="substring-before($file,'#')"/>
  269.     <xsl:text>#</xsl:text><xsl:value-of select="$ident"/>
  270.   </xsl:when>
  271.   <xsl:otherwise>
  272.     <xsl:value-of select="$file"/>
  273.     <xsl:text>#</xsl:text><xsl:value-of select="$ident"/>
  274.   </xsl:otherwise>
  275.  </xsl:choose>
  276. </xsl:template>
  277.  
  278. <xsl:template match="ptr">
  279.  <a class="ptr">
  280.  <xsl:attribute name="href">
  281.       <xsl:apply-templates mode="xrefheader" select="key('IDS',@target)"/>
  282.  </xsl:attribute>
  283.  <xsl:variable name="xx">
  284.   <xsl:apply-templates mode="header" select="key('IDS',@target)">
  285.     <xsl:with-param name="minimal" select="$minimalCrossRef"/>
  286.  </xsl:apply-templates>
  287.  </xsl:variable>
  288.  <xsl:value-of select="normalize-space($xx)"/>
  289.  </a>
  290. </xsl:template>
  291.  
  292. <xsl:template match="xref">
  293.  <xsl:variable name="url">
  294.     <xsl:call-template name="lookupURL"/>
  295.  </xsl:variable>
  296.  <a href="{$url}">
  297.   <xsl:call-template name="urltargets">
  298.     <xsl:with-param name="url"><xsl:value-of select="$url"/></xsl:with-param>
  299.   </xsl:call-template>
  300.  <xsl:attribute name="class">
  301.  <xsl:choose>
  302.      <xsl:when test="@rend"><xsl:value-of select="@rend"/></xsl:when>
  303.  <xsl:otherwise>quicklink</xsl:otherwise>     
  304.  </xsl:choose>
  305.    </xsl:attribute>
  306.  <xsl:apply-templates/>
  307.  </a>
  308. </xsl:template>
  309.  
  310. <xsl:template match="xptr">
  311.   <xsl:variable name="url">
  312.     <xsl:call-template name="lookupURL"/>
  313.   </xsl:variable>
  314.   <xsl:variable name="URL">
  315.     <xsl:choose>
  316.      <xsl:when test="starts-with($url,'mailto:')">
  317.      <xsl:value-of select="substring-after($url,'mailto:')"/>
  318.      </xsl:when>
  319.      <xsl:when test="starts-with($url,'file:')">
  320.       <xsl:value-of select="substring-after($url,'file:')"/>
  321.      </xsl:when>
  322.      <xsl:otherwise>
  323.      <xsl:value-of select="$url"/>
  324.      </xsl:otherwise>
  325.      </xsl:choose>
  326.     </xsl:variable>
  327.   <a href="{$url}">
  328.   <xsl:call-template name="urltargets">
  329.     <xsl:with-param name="url"><xsl:value-of select="$url"/></xsl:with-param>
  330.   </xsl:call-template>
  331.    <xsl:attribute name="class">
  332.    <xsl:choose>
  333.      <xsl:when test="@rend"><xsl:value-of select="@rend"/></xsl:when>
  334.      <xsl:otherwise>quicklink</xsl:otherwise>     
  335.    </xsl:choose>
  336.    </xsl:attribute>
  337.    <xsl:element name="{$fontURL}">
  338.     <xsl:value-of select="$URL"/>
  339.    </xsl:element>
  340.   </a>
  341. </xsl:template>
  342.  
  343. <xsl:template name="urltargets">
  344.   <xsl:param name="url"/>
  345.      <xsl:choose>
  346.      <xsl:when test="contains($url,'://') or starts-with($url,'.') or starts-with($url,'/')">
  347.        <xsl:attribute name="target">_top</xsl:attribute>
  348.      </xsl:when>
  349.      <xsl:when test="substring($url,string-length($url),1)='/'">
  350.        <xsl:attribute name="target">_top</xsl:attribute>
  351.      </xsl:when>
  352.      <xsl:when test="$splitLevel=-1">
  353.        <xsl:attribute name="target">_top</xsl:attribute>
  354.      </xsl:when>
  355.      <xsl:when test="@rend='noframe'">
  356.        <xsl:attribute name="target">_top</xsl:attribute>
  357.      </xsl:when>
  358.      <xsl:when test="@rend='new'">
  359.        <xsl:attribute name="target">_blank</xsl:attribute>
  360.      </xsl:when>
  361.      </xsl:choose>
  362. </xsl:template>
  363.  
  364. <xsl:template name="lookupURL">
  365.   <xsl:choose>
  366.     <xsl:when test="@url"><xsl:value-of select="@url"/></xsl:when>
  367.     <xsl:otherwise>
  368.       <xsl:value-of select="unparsed-entity-uri(@doc)"/>
  369.       <xsl:choose>
  370.         <xsl:when test="contains(@from,'id (')">
  371.           <xsl:text>#</xsl:text>
  372.            <xsl:value-of select="substring(@from,5,string-length(normalize-space(@from))-1)"/>
  373.         </xsl:when>
  374.       </xsl:choose>
  375.     </xsl:otherwise>
  376.   </xsl:choose>
  377. </xsl:template>
  378.  
  379.  
  380. </xsl:stylesheet>
  381.