<?xml version="1.0"?>
<!--
PUBLIC "+//ISBN 1-894049::CSL::Articles//DOCUMENT XML.COM Article MS Stylesheet//EN"
Copyright (C) Crane Softwrights Ltd. - http://www.CraneSoftwrights.com

    1999-04-20 12:50

CAVEAT - The XSL syntax used in this file follows only a working draft of
         the XSL recommendation and is not necessarily representative of 
         any finalized or authorized recommendation.
-->

<!DOCTYPE xsl:stylesheet [
        <!--because XSL stylesheets are XML documents, all forms of
            XML file content minimization are available to be used-->

<!ENTITY nbsp "&#160;">
<!ENTITY common-colour "#003300">

<!ENTITY toc                "Table of Contents">
<!ENTITY link-sections      "reserved-sections">
<!ENTITY gen-sections       "Alphabetical Table of Sections">
<!ENTITY link-addr-summary  "reserved-addr">
<!ENTITY gen-addr-summary   "Summary of Links (sorted by target address)">
<!ENTITY link-capt-summary  "reserved-captions">
<!ENTITY gen-capt-summary   "Summary of Links (sorted by caption)">
<!ENTITY link-side-summary  "reserved-side">
<!ENTITY gen-side-summary   "Sorted Summary of Sidebars">
<!ENTITY URLset             "Set of URL Addresses">

        <!--the following are small values and sets of CSS properties 
            shared in a number of CSS declaration groups used throughout
            the stylesheet-->
<!ENTITY  mainFontSize          "18pt">
<!ENTITY  textFontSize          "12pt">
<!ENTITY  monoFontSize          "10pt">
<!ENTITY  firstSectionFontSize  "16pt">
<!ENTITY  secondSectionFontSize "14pt">
<!ENTITY  otherSectionFontSize  "&textFontSize;">
<!ENTITY  sectionTitleCommon    "display:block;
                                 font-weight:bold;
                                 font-style:italic;">
]>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"
                xmlns="http://www.w3.org/TR/REC-html40"
                result-ns="">

<!-- default behaviour - - - - - - - - - - - - - - - - - - - - - - - - -->

<xsl:template><xsl:apply-templates/></xsl:template>
<xsl:template match="text()"><xsl:value-of select="."/></xsl:template>

<!-- selective behaviour - - - - - - - - - - - - - - - - - - - - - - - -->

<xsl:template match="/">                    <!--root rule-->
  <html>
    <head>
      <title><xsl:value-of select="/article/title"/> - 
             <xsl:value-of select="/article/author/name"/></title>
      <style type="text/css">

        A:visited { color: blue }

        <!--I've chosen here to use class sheets where an entire
            declaration group is used in multiple places;
            
            For all other styles, where the declaration group contents 
            are unique, or the purpose of the sheet is distinct, I've 
            directly used the STYLE= attr in the DIV or SPAN element-->
                                            <!--main article title-->
          .maintitle {display:block;
                      text-align:center;
                      font-weight:bold;
                      color: &common-colour;;
                      font-size:&mainFontSize;}
                                            <!--section titles-->
          .gensectiontitle {&sectionTitleCommon;
                            color: &common-colour;;
                            margin-top: &firstSectionFontSize;;
                            font-size: &firstSectionFontSize;}
      </style>
    </head>
    <body style="font-size:&textFontSize;">

      <A HREF="http://www.xml.com/">
      <IMG SRC="/universal/images/xml_com_logo_small.gif" WIDTH="180"
      HEIGHT="70" ALT="XML.com" BORDER="0" ALIGN="left"/></A><BR CLEAR="all"/>

      <xsl:apply-templates/>                <!--main article content-->
      
      <xsl:apply-templates>                 <!--table of sections-->
        <xsl:template match="article">
          <h2 class="gensectiontitle">
            <a name="&link-sections;">&gen-sections;</a></h2>
          <xsl:apply-templates select="//section" order-by="title"/>
        </xsl:template>
        <xsl:template match="section">
          <div style="font-size:10pt">
               <a><xsl:attribute name="href">#<xsl:value-of select="@id"/>
                  </xsl:attribute>
                  <xsl:value-of select="title"/>
                  (<xsl:apply-templates select=".">
                      <xsl:template match="section">
                        <xsl:apply-templates select="ancestor(section)">
                          <xsl:template match="section">
                            <xsl:apply-templates select="ancestor(section)"/>
                            <xsl:eval>childNumber(this)</xsl:eval
                                     >.</xsl:template>
                        </xsl:apply-templates><xsl:eval
                                     >childNumber(this)</xsl:eval
                                     ></xsl:template>
                   </xsl:apply-templates>)
               </a></div>
        </xsl:template>
      </xsl:apply-templates>
      
      <xsl:apply-templates>             <!--summary of links by href-->
        <xsl:template match="article">
          <h2 class="gensectiontitle">
            <a name="&link-addr-summary;">&gen-addr-summary;</a></h2>
          <table border="1" style="font-size:10pt" 
                summary="Summary of External Links (sorted by target address)">
          <tr valign="top">
            <td width="50%">Target</td><td width="50%">Section</td></tr>
          <xsl:apply-templates select="//extlink" order-by="@href"/>
          </table>
        </xsl:template>
        
        <xsl:template match="extlink">
          <tr valign="top">
              <td width="50%"><p><a>
                     <xsl:attribute name="href">
                       <xsl:value-of select="@href"/>
                     </xsl:attribute>
                   <samp style="font-size:&monoFontSize;"
                     ><xsl:value-of select="@href"/></samp></a></p></td>
              <td width="50%"><p><a>
                     <xsl:attribute name="href">
                       #<xsl:value-of select="ancestor(section|
                                                       sidebar)/@id"/>
                     </xsl:attribute>
                   <xsl:value-of select="ancestor(section|
                                                  sidebar)/title"/>
                    </a></p></td></tr>
        </xsl:template>
      </xsl:apply-templates>

      <xsl:apply-templates>             <!--summary of links by caption-->
        <xsl:template match="article">
          <h2 class="gensectiontitle">
            <a name="&link-capt-summary;">&gen-capt-summary;</a></h2>
          <table border="1" style="font-size:10pt"
               summary="&gen-capt-summary;">
          <tr valign="top"><td width="33%">Caption</td>
                           <td width="33%">Target</td>
                           <td width="33%">Section</td></tr>
          <xsl:apply-templates select="//extlink" order-by=".;@href"/>
          </table>
        </xsl:template>
        
        <xsl:template match="extlink">
          <tr valign="top">
              <td width="33%"><p><a>
                     <xsl:attribute name="href">
                       <xsl:value-of select="@href"/>
                     </xsl:attribute>
                   <xsl:value-of select="."/></a></p></td>
              <td width="33%"><p><a>
                     <xsl:attribute name="href">
                       <xsl:value-of select="@href"/>
                     </xsl:attribute>
                   <samp style="font-size:&monoFontSize;"
                     ><xsl:value-of select="@href"/></samp></a></p></td>
              <td width="33%"><p><a>
                     <xsl:attribute name="href">
                       #<xsl:value-of select="ancestor(section|
                                                       sidebar)/@id"/>
                     </xsl:attribute>
                   <xsl:value-of select="ancestor(section|
                                                  sidebar)/title"/>
                    </a></p></td></tr>
        </xsl:template>
      </xsl:apply-templates>

      <xsl:apply-templates>                 <!--summary of sidebars-->
        <xsl:template match="article">
          <h2 class="gensectiontitle">
            <a name="&link-side-summary;">&gen-side-summary;</a></h2>
          <xsl:apply-templates select="//sidebar" order-by="title"/>
        </xsl:template>
        <xsl:template match="sidebar">
          <xsl:for-each select="title">
            <div style="font-size:10pt"><a>
              <xsl:attribute name="href">
                #<xsl:value-of select="../@id"/>
              </xsl:attribute>
              <xsl:apply-templates/></a></div>
          </xsl:for-each>
        </xsl:template>
      </xsl:apply-templates>

                                            <!--end matter-->
      <div style="margin-top:&textFontSize;;font-style:italic">
        End of article "<xsl:value-of select="/article/title"/>"</div>
      <div style="font-style:italic">
        <xsl:value-of select="/article/author/name"/>
        - <a>
            <xsl:attribute name="href">
              mailto:<xsl:value-of select="/article/author/name/@email"/>
            </xsl:attribute>
            <xsl:value-of select="/article/author/name/@email"/></a></div>
      <div style="font-style:italic">
        <xsl:value-of select="/article/author/affil"/>
        - <a>
            <xsl:attribute name="href">
              <xsl:value-of select="/article/author/affil/@url"/>
            </xsl:attribute>
            <xsl:value-of select="/article/author/affil/@url"/></a></div>
      <div style="font-style:italic">
        Copyright (C) <xsl:value-of select="/article/copyright"/></div>

      <P>&nbsp;</P><FONT FACE="Georgia,Times New Roman,Times Roman,Times"
      SIZE="-1" COLOR="#000080"><P><BR/></P><P>Copyright (C) 1999 Seybold
      Publications and O'Reilly &amp; Associates, Inc.<BR/><a
      href="http://www.w3.org/XML/">XML</a> is a trademark of MIT and a product
      of the <a href="http://www.w3.org/">World Wide Web Consortium</a>.
      </P></FONT>
    </body>
  </html>
</xsl:template>

<xsl:template match="article/title">        <!--title the article-->
  <h1 class="maintitle"><xsl:apply-templates/></h1>
  <h4 style="text-align:center">
    <a><xsl:attribute name="href">
        mailto:<xsl:value-of select="/article/author/name/@email"/>
       </xsl:attribute>
       <xsl:value-of select="/article/author/name"/></a>
  - <a><xsl:attribute name="href">
        <xsl:value-of select="/article/author/affil/@url"/>
       </xsl:attribute>
       <xsl:value-of select="/article/author/affil"/></a></h4>
  
  <h2 class="gensectiontitle">&toc;</h2><!--add TOC-->
  <table summary="&toc;" border="0">
  <xsl:apply-templates select="//section/title">
    <xsl:template match="title">
      <tr><td>&nbsp;&nbsp;&nbsp;<b>
        <xsl:apply-templates select="ancestor(section)">
          <xsl:template match="section">
            <xsl:apply-templates select="ancestor(section)">
              <xsl:template match="section">
                <xsl:apply-templates select="ancestor(section)"/>
                <xsl:eval>childNumber(this)</xsl:eval>.</xsl:template>
            </xsl:apply-templates><xsl:eval>childNumber(this)</xsl:eval>
          </xsl:template>
        </xsl:apply-templates></b></td>
        <td><div>&nbsp;&nbsp;&nbsp;<a><xsl:attribute name="href">
                 #<xsl:value-of select="../@id"/></xsl:attribute>
                 <xsl:apply-templates/></a></div></td></tr>
    </xsl:template>
  </xsl:apply-templates>
  <tr><td></td><td>
  <div>&nbsp;&nbsp;&nbsp;
       <a href="#&link-sections;">&gen-sections;</a></div></td></tr>
  <tr><td></td><td>
  <div>&nbsp;&nbsp;&nbsp;
       <a href="#&link-addr-summary;">&gen-addr-summary;</a></div></td></tr>
  <tr><td></td><td>
  <div>&nbsp;&nbsp;&nbsp;
       <a href="#&link-capt-summary;">&gen-capt-summary;</a></div></td></tr>
  <tr><td></td><td>
  <div>&nbsp;&nbsp;&nbsp;
       <a href="#&link-side-summary;">&gen-side-summary;</a></div></td></tr>
  </table>
</xsl:template>

<xsl:template match="copyright"/>  <!--show when needed, not in parse order-->

<xsl:template match="author"/>                <!--author of document-->
                     <!--don't show in parse order, shown with title-->

<xsl:template match="section">     <!--a section of the article-->
  <xsl:apply-templates/>           <!--nothing special-->
</xsl:template>

<xsl:template match="section/title">
  <xsl:choose>
    <xsl:when test="../../../../section"> <!--three or more levels down-->
      <h4  style="font-weight : bold;
                  color: &common-colour;;
                  margin-top : &otherSectionFontSize;;
                  font-size : &otherSectionFontSize;">
        <a><xsl:attribute name="name">
             <xsl:value-of select="../@id"/></xsl:attribute>
          <xsl:apply-templates select="ancestor(section)">
            <xsl:template match="section">
              <xsl:apply-templates select="ancestor(section)">
                <xsl:template match="section">
                  <xsl:apply-templates select="ancestor(section)"/>
                  <xsl:eval>childNumber(this)</xsl:eval>.</xsl:template>
              </xsl:apply-templates><xsl:eval>childNumber(this)</xsl:eval>
            </xsl:template>
          </xsl:apply-templates>
          <xsl:apply-templates/></a></h4>
    </xsl:when>
    <xsl:when test="../../../section">    <!--only two levels down-->
      <h3 style="font-weight : bold;
                  color: &common-colour;;
                  margin-top : &otherSectionFontSize;;
                  font-size : &secondSectionFontSize;">
        <a><xsl:attribute name="name">
             <xsl:value-of select="../@id"/></xsl:attribute>
          <xsl:apply-templates select="ancestor(section)">
            <xsl:template match="section">
              <xsl:apply-templates select="ancestor(section)">
                <xsl:template match="section">
                  <xsl:eval>childNumber(this)</xsl:eval>.</xsl:template>
              </xsl:apply-templates><xsl:eval>childNumber(this)</xsl:eval>
            </xsl:template>
          </xsl:apply-templates>
           <xsl:apply-templates/></a></h3>
    </xsl:when>
    <xsl:otherwise>
      <h2  style="font-weight : bold;
                  color: &common-colour;;
                  margin-top : &otherSectionFontSize;;
                  font-size : &firstSectionFontSize;">
        <a><xsl:attribute name="name">
              <xsl:value-of select="../@id"/></xsl:attribute>
           <xsl:eval>ancestorChildNumber("section",this)</xsl:eval>
           <xsl:apply-templates/></a></h2>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="sidebar">                  <!--sidebar stuff-->
  <span style="float: right; 
               clear: right; 
               background-color: #eeeeee;
               width:            40%;
               border-style:     solid;
               border-color:     red;
               border-width:     2pt;
               padding-top:      4pt;
               padding-bottom:   4pt;
               padding-left:     10pt;
               padding-right:    10pt;
               margin-top:       5pt;
               margin-bottom:    5pt;
               margin-left:      5pt;
               margin-right:     5pt;">
        <hr style="display:none"/>
        <xsl:apply-templates/>
        <hr style="display:none"/>
        </span>
</xsl:template>

 <!--note the following template rule is the only specification difference
     from the "xmlcom.xsl" stylesheet; that stylesheet is assumed to be
     used for HTML rendering only and not XML rendering; this stylesheet
     is assumed to be used for XML rendering only, therefore, it must
     suppress those sidebars indicating they are to be suppressed-->
<xsl:template match="sidebar[@xml-rendering='suppress']"/>

<xsl:template match="sidebar/title">
  <h3  style="text-align:center;
              font-weight:bold;
              text-decoration:underline">
  <a>
    <xsl:attribute name="name">
      <xsl:value-of select="../@id"/></xsl:attribute>
    <span style="display:none">Sidebar: </span>
    <xsl:apply-templates/></a></h3>
</xsl:template>

                        <!--generic content of the article-->

<xsl:template match="para">             <!--a block of information-->
  <p style="margin-top: &textFontSize;"><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="emph">             <!--emphasized content-->
  <i><xsl:apply-templates/>
  </i></xsl:template>    <!--whitespace removed for IE5 rendering-->

<xsl:template match="image">            <!--image with a caption-->
  <center>
    <img>
      <xsl:attribute name="src"><xsl:value-of select="@href"/>
        </xsl:attribute>
      <xsl:attribute name="alt"><xsl:value-of select="."/><!--caption-->
        </xsl:attribute>
    </img>
    <br/><b><xsl:value-of select="."/></b></center>
</xsl:template>

<xsl:template match="extlink">          <!--an external link-->
  <a><xsl:attribute name="href">
      <xsl:value-of select="@href"/></xsl:attribute>
    <xsl:apply-templates/></a></xsl:template>

<xsl:template match="intlink">          <!--an internal reference-->
  <a><xsl:attribute name="href">
      #<xsl:value-of select="@idref"/></xsl:attribute>
    <xsl:value-of select="id(@idref)/title"/></a></xsl:template>

<xsl:template match="extlinkset">   <!--handy, dandy collection of URLs-->
  <table border="1" summary="&URLset;" style="margin-top:&textFontSize;">
    <xsl:for-each select="extlink" order-by="@href">
      <tr valign="top">
        <td><a>
               <xsl:attribute name="href">
                 <xsl:value-of select="@href"/>
               </xsl:attribute>
               <samp style="font-size:&monoFontSize;"
                 ><xsl:value-of select="@href"/></samp></a></td>
        <td><xsl:value-of select="."/></td>
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>

                                        <!--monospaced presentation-->
<xsl:template match="monospc">
  <samp style="font-size:&monoFontSize;"
       ><xsl:apply-templates/></samp></xsl:template><!--note whitespace-->

<xsl:template match="section/monospc|sidebar/monospc">
  <pre style="font-size:&monoFontSize;"><xsl:apply-templates/></pre>
</xsl:template>

</xsl:stylesheet>
