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

  1. <?xml version="1.0"?>
  2. <!DOCTYPE xsl:stylesheet [
  3.  
  4. <!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
  5. <!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
  6.  
  7. <!ENTITY primary   'normalize-space(concat(primary/@sortas, primary[not(@sortas)]))'>
  8. <!ENTITY secondary 'normalize-space(concat(secondary/@sortas, secondary[not(@sortas)]))'>
  9. <!ENTITY tertiary  'normalize-space(concat(tertiary/@sortas, tertiary[not(@sortas)]))'>
  10.  
  11. <!ENTITY section   '(ancestor-or-self::set
  12.                      |ancestor-or-self::book
  13.                      |ancestor-or-self::part
  14.                      |ancestor-or-self::reference
  15.                      |ancestor-or-self::partintro
  16.                      |ancestor-or-self::chapter
  17.                      |ancestor-or-self::appendix
  18.                      |ancestor-or-self::preface
  19.                      |ancestor-or-self::section
  20.                      |ancestor-or-self::sect1
  21.                      |ancestor-or-self::sect2
  22.                      |ancestor-or-self::sect3
  23.                      |ancestor-or-self::sect4
  24.                      |ancestor-or-self::sect5
  25.                      |ancestor-or-self::refentry
  26.                      |ancestor-or-self::refsect1
  27.                      |ancestor-or-self::refsect2
  28.                      |ancestor-or-self::refsect3
  29.                      |ancestor-or-self::simplesect
  30.                      |ancestor-or-self::bibliography
  31.                      |ancestor-or-self::glossary
  32.                      |ancestor-or-self::index)[last()]'>
  33.  
  34. <!ENTITY section.id 'generate-id(§ion;)'>
  35. <!ENTITY sep '" "'>
  36. ]>
  37. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  38.                 version="1.0">
  39.  
  40. <!-- ==================================================================== -->
  41. <!-- Jeni Tennison gets all the credit for what follows.
  42.      I think I understand it :-) Anyway, I've hacked it a bit, so the
  43.      bugs are mine. -->
  44.  
  45. <xsl:key name="letter"
  46.          match="indexterm"
  47.          use="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
  48.  
  49. <xsl:key name="primary"
  50.          match="indexterm"
  51.          use="&primary;"/>
  52.  
  53. <xsl:key name="secondary"
  54.          match="indexterm"
  55.          use="concat(&primary;, &sep;, &secondary;)"/>
  56.  
  57. <xsl:key name="tertiary"
  58.          match="indexterm"
  59.          use="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
  60.  
  61. <xsl:key name="primary-section"
  62.          match="indexterm[not(secondary) and not(see)]"
  63.          use="concat(&primary;, &sep;, §ion.id;)"/>
  64.  
  65. <xsl:key name="secondary-section"
  66.          match="indexterm[not(tertiary) and not(see)]"
  67.          use="concat(&primary;, &sep;, &secondary;, &sep;, §ion.id;)"/>
  68.  
  69. <xsl:key name="tertiary-section"
  70.          match="indexterm[not(see)]"
  71.          use="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, §ion.id;)"/>
  72.  
  73. <xsl:key name="see-also"
  74.          match="indexterm[seealso]"
  75.          use="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso)"/>
  76.  
  77. <xsl:key name="see"
  78.          match="indexterm[see]"
  79.          use="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see)"/>
  80.  
  81. <xsl:key name="sections" match="*[@id]" use="@id"/>
  82.  
  83. <xsl:template name="generate-index">
  84.   <xsl:variable name="terms" select="//indexterm[count(.|key('letter',
  85.                                      translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[1]) = 1]"/>
  86.  
  87.   <xsl:variable name="alphabetical"
  88.                 select="$terms[contains(concat(&lowercase;, &uppercase;),
  89.                                         substring(&primary;, 1, 1))]"/>
  90.   <xsl:variable name="others" select="$terms[not(contains(concat(&lowercase;,
  91.                                                  &uppercase;),
  92.                                              substring(&primary;, 1, 1)))]"/>
  93.   <div class="index">
  94.     <xsl:if test="$others">
  95.       <div class="indexdiv">
  96.         <h3>
  97.           <xsl:call-template name="gentext">
  98.             <xsl:with-param name="key" select="'index symbols'"/>
  99.           </xsl:call-template>
  100.         </h3>
  101.         <dl>
  102.           <xsl:apply-templates select="$others[count(.|key('primary',
  103.                                        &primary;)[1]) = 1]"
  104.                                mode="index-symbol-div">
  105.             <xsl:sort select="&primary;"/>
  106.           </xsl:apply-templates>
  107.         </dl>
  108.       </div>
  109.     </xsl:if>
  110.     <xsl:apply-templates select="$alphabetical[count(.|key('letter',
  111.                                  translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[1]) = 1]"
  112.                          mode="index-div">
  113.       <xsl:sort select="&primary;"/>
  114.     </xsl:apply-templates>
  115.   </div>
  116. </xsl:template>
  117.  
  118. <xsl:template match="indexterm" mode="index-div">
  119.   <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
  120.   <div class="indexdiv">
  121.     <h3>
  122.       <xsl:value-of select="translate($key, &lowercase;, &uppercase;)"/>
  123.     </h3>
  124.     <dl>
  125.       <xsl:apply-templates select="key('letter', $key)[count(.|key('primary', &primary;)[1]) = 1]"
  126.                            mode="index-primary">
  127.         <xsl:sort select="&primary;"/>
  128.       </xsl:apply-templates>
  129.     </dl>
  130.   </div>
  131. </xsl:template>
  132.  
  133. <xsl:template match="indexterm" mode="index-symbol-div">
  134.   <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
  135.   <xsl:apply-templates select="key('letter', $key)[count(.|key('primary', &primary;)[1]) = 1]"
  136.                        mode="index-primary">
  137.     <xsl:sort select="&primary;"/>
  138.   </xsl:apply-templates>
  139. </xsl:template>
  140.  
  141. <xsl:template match="indexterm" mode="index-primary">
  142.   <xsl:variable name="key" select="&primary;"/>
  143.   <xsl:variable name="refs" select="key('primary', $key)"/>
  144.   <dt>
  145.     <xsl:value-of select="primary"/>
  146.     <xsl:for-each select="$refs[generate-id() = generate-id(key('primary-section', concat($key, &sep;, §ion.id;))[1])]">
  147.       <xsl:apply-templates select="." mode="reference"/>
  148.     </xsl:for-each>
  149.  
  150.     <xsl:if test="$refs[not(secondary)]/*[self::see]">
  151.       <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[1])]"
  152.                            mode="index-see">
  153.         <xsl:sort select="see"/>
  154.       </xsl:apply-templates>
  155.     </xsl:if>
  156.   </dt>
  157.   <xsl:if test="$refs/secondary or $refs[not(secondary)]/*[self::seealso]">
  158.     <dd>
  159.       <dl>
  160.         <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[1])]"
  161.                              mode="index-seealso">
  162.           <xsl:sort select="seealso"/>
  163.         </xsl:apply-templates>
  164.         <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[1]) = 1]" 
  165.                              mode="index-secondary">
  166.           <xsl:sort select="&secondary;"/>
  167.         </xsl:apply-templates>
  168.       </dl>
  169.     </dd>
  170.   </xsl:if>
  171. </xsl:template>
  172.  
  173. <xsl:template match="indexterm" mode="index-secondary">
  174.   <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;)"/>
  175.   <xsl:variable name="refs" select="key('secondary', $key)"/>
  176.   <dt>
  177.     <xsl:value-of select="secondary"/>
  178.     <xsl:for-each select="$refs[generate-id() = generate-id(key('secondary-section', concat($key, &sep;, §ion.id;))[1])]">
  179.       <xsl:apply-templates select="." mode="reference"/>
  180.     </xsl:for-each>
  181.  
  182.     <xsl:if test="$refs[not(tertiary)]/*[self::see]">
  183.       <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[1])]"
  184.                            mode="index-see">
  185.         <xsl:sort select="see"/>
  186.       </xsl:apply-templates>
  187.     </xsl:if>
  188.   </dt>
  189.   <xsl:if test="$refs/tertiary or $refs[not(tertiary)]/*[self::seealso]">
  190.     <dd>
  191.       <dl>
  192.         <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[1])]"
  193.                              mode="index-seealso">
  194.           <xsl:sort select="seealso"/>
  195.         </xsl:apply-templates>
  196.         <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[1]) = 1]" 
  197.                              mode="index-tertiary">
  198.           <xsl:sort select="&tertiary;"/>
  199.         </xsl:apply-templates>
  200.       </dl>
  201.     </dd>
  202.   </xsl:if>
  203. </xsl:template>
  204.  
  205. <xsl:template match="indexterm" mode="index-tertiary">
  206.   <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
  207.   <xsl:variable name="refs" select="key('tertiary', $key)"/>
  208.   <dt>
  209.     <xsl:value-of select="tertiary"/>
  210.     <xsl:for-each select="$refs[generate-id() = generate-id(key('tertiary-section', concat($key, &sep;, §ion.id;))[1])]">
  211.       <xsl:apply-templates select="." mode="reference"/>
  212.     </xsl:for-each>
  213.  
  214.     <xsl:if test="$refs/see">
  215.       <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[1])]"
  216.                            mode="index-see">
  217.         <xsl:sort select="see"/>
  218.       </xsl:apply-templates>
  219.     </xsl:if>
  220.   </dt>
  221.   <xsl:if test="$refs/seealso">
  222.     <dd>
  223.       <dl>
  224.         <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[1])]"
  225.                              mode="index-see">
  226.           <xsl:sort select="see"/>
  227.         </xsl:apply-templates>
  228.         <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[1])]"
  229.                              mode="index-seealso">
  230.           <xsl:sort select="seealso"/>
  231.         </xsl:apply-templates>
  232.       </dl>
  233.     </dd>
  234.   </xsl:if>
  235. </xsl:template>
  236.  
  237. <xsl:template match="indexterm" mode="reference">
  238.   <xsl:text>, </xsl:text>
  239.   <xsl:choose>
  240.     <xsl:when test="@zone and string(@zone)">
  241.       <xsl:call-template name="reference">
  242.         <xsl:with-param name="zones" select="normalize-space(@zone)"/>
  243.       </xsl:call-template>
  244.     </xsl:when>
  245.     <xsl:otherwise>
  246.       <a>
  247.         <xsl:variable name="title">
  248.           <xsl:apply-templates select="§ion;" mode="title.markup"/>
  249.         </xsl:variable>
  250.  
  251.         <xsl:attribute name="href">
  252.           <xsl:call-template name="href.target">
  253.             <xsl:with-param name="object" select="§ion;"/>
  254.           </xsl:call-template>
  255.         </xsl:attribute>
  256.  
  257.         <xsl:value-of select="$title"/> <!-- text only -->
  258.       </a>
  259.     </xsl:otherwise>
  260.   </xsl:choose>
  261. </xsl:template>
  262.  
  263. <xsl:template name="reference">
  264.   <xsl:param name="zones"/>
  265.   <xsl:choose>
  266.     <xsl:when test="contains($zones, ' ')">
  267.       <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
  268.       <xsl:variable name="target" select="key('sections', $zone)"/>
  269.  
  270.       <a>
  271.         <xsl:attribute name="href">
  272.           <xsl:call-template name="href.target">
  273.             <xsl:with-param name="object" select="$target[1]"/>
  274.           </xsl:call-template>
  275.         </xsl:attribute>
  276.         <xsl:apply-templates select="$target[1]" mode="index-title-content"/>
  277.       </a>
  278.       <xsl:text>, </xsl:text>
  279.       <xsl:call-template name="reference">
  280.         <xsl:with-param name="zones" select="substring-after($zones, ' ')"/>
  281.       </xsl:call-template>
  282.     </xsl:when>
  283.     <xsl:otherwise>
  284.       <xsl:variable name="zone" select="$zones"/>
  285.       <xsl:variable name="target" select="key('sections', $zone)"/>
  286.  
  287.       <a>
  288.         <xsl:attribute name="href">
  289.           <xsl:call-template name="href.target">
  290.             <xsl:with-param name="object" select="$target[1]"/>
  291.           </xsl:call-template>
  292.         </xsl:attribute>
  293.         <xsl:apply-templates select="$target[1]" mode="index-title-content"/>
  294.       </a>
  295.     </xsl:otherwise>
  296.   </xsl:choose>
  297. </xsl:template>
  298.  
  299. <xsl:template match="indexterm" mode="index-see">
  300.   <xsl:text> (</xsl:text>
  301.   <xsl:call-template name="gentext">
  302.     <xsl:with-param name="key" select="'see'"/>
  303.   </xsl:call-template>
  304.   <xsl:text> </xsl:text>
  305.   <xsl:value-of select="see"/>
  306.   <xsl:text>)</xsl:text>
  307. </xsl:template>
  308.  
  309. <xsl:template match="indexterm" mode="index-seealso">
  310.   <xsl:text>(</xsl:text>
  311.   <xsl:call-template name="gentext">
  312.     <xsl:with-param name="key" select="'seealso'"/>
  313.   </xsl:call-template>
  314.   <xsl:text> </xsl:text>
  315.   <xsl:value-of select="seealso"/>
  316.   <xsl:text>)</xsl:text>
  317. </xsl:template>
  318.  
  319. <xsl:template match="*" mode="index-title-content">
  320.   <xsl:variable name="title">
  321.     <xsl:apply-templates select="§ion;" mode="title.markup"/>
  322.   </xsl:variable>
  323.  
  324.   <xsl:value-of select="$title"/>
  325. </xsl:template>
  326.  
  327. </xsl:stylesheet>
  328.