<?xml version="1.0" encoding="UTF-8" ?>

<!--
    Document   : multidoc 
    Created on : 23 April 2003 
    Author     : jjc
    Comment
        purpose of transformation follows.
-->

<xsl:stylesheet version="1.1"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:saxon="http://icl.com/saxon"
    xmlns:xhtml="http://www.w3.org/1999/xhtml">

    
  
     <!-- template rule matching source root element -->
    <xsl:template match="/">
       <xsl:document method="saxon:xhtml"
        encoding="iso-8859-1" href="Overview.html"
    doctype-public= "-//W3C//DTD XHTML 1.0 Transitional//EN"
    doctype-system =  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
        <xsl:apply-templates/>
      </xsl:document>
    </xsl:template>
    
    <xsl:template match="node()">
     <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
    </xsl:template>    
    
     
    <xsl:template match="@href" priority="2">
      <xsl:if test="starts-with(.,'#')" >
        <xsl:variable name="multi" select="id(substring-after(.,'#'))/
          ancestor::xhtml:div[@class='multipart']/*/xhtml:a/@id"/>
       <xsl:attribute name="href">
        <xsl:if test="''=string($multi)">./</xsl:if>
        <xsl:value-of select="$multi"/>
         <xsl:value-of select="."/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="not(starts-with(.,'#'))" >
     <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
      </xsl:if>
    </xsl:template>    
    
    <xsl:template match="@*">
     <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
    </xsl:template>
    
    <xsl:template match="xhtml:div[@class='multipart']">
       <xsl:variable name="title" select="*[/a][1]/a/node()"/>
       <xsl:call-template name="toc"/>
       <xsl:document method="saxon:xhtml"
        encoding="iso-8859-1" href="{concat(*/xhtml:a/@id,'.html')}"
    doctype-public= "-//W3C//DTD XHTML 1.0 Transitional//EN"
    doctype-system =  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
       <html lang="en-US" xml:lang="en-US">
       <head>
        <title>
        OWL Test <xsl:apply-templates select="*[./xhtml:a][1]/xhtml:a/text()"/>
        </title>
        <xsl:apply-templates select="//xhtml:head/node()" mode="head"/>
       </head>
       <body>
        <xsl:call-template name="nav"/>
        <hr/>
        <div class="head">
        <h1><a id="title" name="title">
        <xsl:apply-templates select="//xhtml:div[@class='head']/xhtml:h1[1]/xhtml:a/node()"/>
        <br/>
        <xsl:apply-templates select="*[./xhtml:a][1]/xhtml:a/node()"/>
        </a></h1>
        <xsl:apply-templates select="//xhtml:p[@class='copyright']" />
        </div>
        <hr/>
       <xsl:call-template name="toc"/>
        <hr/>
        <xsl:apply-templates select="node()"/>
        <hr/>
        <xsl:call-template name="nav"/>
       </body>
       </html>
       </xsl:document>
    </xsl:template>
    
    
    <xsl:template name="toc">
       <xsl:variable name="entry" select="*/xhtml:a/@id"/>
       <div class="subtoc">
        <p><strong>Contents</strong></p>
       <ul class='toc'>
       <xsl:apply-templates select="/*//xhtml:div[@class='contents']//xhtml:a[@href=concat('#',$entry)]/.."/>
       </ul>
       </div>
    </xsl:template>
    
    <xsl:template name="nav">
     <!-- previous -->
     
     <xsl:if test="count(preceding::xhtml:div[@class='multipart'])!=0">
       <a>
       <xsl:attribute name="href">
        <xsl:value-of select="preceding::xhtml:div[@class='multipart'][1]/*/xhtml:a/@id"/>
       </xsl:attribute>
        previous
       </a>
     </xsl:if>
     <!-- next -->
     <xsl:if test="count(following::xhtml:div[@class='multipart'])!=0">
       <a>
       <xsl:attribute name="href">
        <xsl:value-of select="following::xhtml:div[@class='multipart'][1]/*/xhtml:a/@id"/>
       </xsl:attribute>
        next
       </a>
     </xsl:if>
     
     <!-- top -->
     <a href="./"> top </a>
     <!-- contents -->
     <a href="./#toc"> contents </a>    
     <!-- index-->
     <a href="./testIndex"> index </a>   
    </xsl:template>
    
    
    <xsl:template match="xhtml:title" mode="head" priority="2">
    </xsl:template>  
    <xsl:template match="@*|node()" mode="head">
     <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
    </xsl:template>   
    
    <xsl:template match="xhtml:span[@class='reference-to-normative-version']" priority="2">
    This normative version is a compound document.
    </xsl:template>
    <xsl:template match="xhtml:span[@class='informative-version-only']" priorty="2">
    </xsl:template>

</xsl:stylesheet> 