<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="./xsltdoc.xsl" type="text/xsl" media="screen"?>
<!DOCTYPE xsl:stylesheet [
 <!ENTITY owl  'http://www.w3.org/2002/07/owl#'>
]>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xmlns:owl="&owl;"
  xmlns:h="http://www.w3.org/1999/xhtml"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:dcterms="http://purl.org/dc/terms/"
  xmlns:ex="http://purl.org/net/ns/ex#"
  xmlns:doas="http://purl.org/net/ns/doas#"
  exclude-result-prefixes="rdf rdfs dc owl dcterms ex doas"
>

 <xsl:output indent="yes"/>
 <xsl:param name="xmlfile"/>
 <xsl:variable name="_doas" select="document('')//rdf:Description[1]"/>

 <xsl:template name="_doas_description">
  <rdf:RDF xmlns="http://purl.org/net/ns/doas#">
   <rdf:Description rdf:about="">
    <title>RDFS/OWL presentation stylesheet</title>
    <description>This stylesheet is designed to convert RDF Schema / OWL Ontology file to visible XHTML with structured definition list.</description>
    <author rdf:parseType="Resource">
     <name>Masahide Kanzaki</name>
     <mbox rdf:resource="mailto:webmaster@kanzaki.com"/>
    </author>
    <created>2003</created>
    <release rdf:parseType="Resource">
     <revision>1.5</revision>
     <created>2005-04-21</created>
    </release>
    <rights>(c) 2003-2005 by the author, copyleft under GPL</rights>
    <license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/"/>
   </rdf:Description>
  </rdf:RDF>
 </xsl:template>


 <!-- find namespace URI -->
 <xsl:variable name="nstestlen" select="string-length($xmlfile)-9"/>
 <xsl:variable name="nsuri">
  <xsl:choose>
   <xsl:when test="/rdf:RDF/@xml:base">
    <xsl:value-of select="/rdf:RDF/@xml:base"/>
   </xsl:when>
   <xsl:when test="/rdf:RDF/owl:Ontology/@rdf:about">
    <xsl:value-of select="/rdf:RDF/owl:Ontology/@rdf:about"/>
   </xsl:when>
   <xsl:when test="substring($xmlfile,$nstestlen)='/index.rdf'">
    <xsl:value-of select="substring($xmlfile,1,$nstestlen)"/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="$xmlfile"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:variable>
 <xsl:variable name="nslen" select="string-length($nsuri)"/>
 <xsl:variable name="localst" select="$nslen + 1"/>
 <xsl:variable name="needhash">
  <xsl:if test="not(substring($nsuri,$nslen,1)='/')">#</xsl:if>
 </xsl:variable>
 <xsl:template match="/">
  <xsl:apply-templates select="rdf:RDF"/>
 </xsl:template>

 <xsl:template match="rdf:RDF">
  <html>
   <xsl:if test="@xml:lang"><xsl:attribute name="lang"><xsl:value-of select="@xml:lang"/></xsl:attribute></xsl:if>
   <head>
    <title>RDF Schema View: <xsl:value-of select="owl:Ontology/dc:title|rdf:Description/dc:title"/></title>
    <xsl:call-template name="htmlhead"/>
   </head>
   <body>
    <xsl:call-template name="banner"/>
    <xsl:call-template name="toc"/>
    <xsl:choose>
     <xsl:when test="owl:Ontology[@rdf:about='']|rdf:Description[@rdf:about='']">
      <xsl:apply-templates select="owl:Ontology[@rdf:about='']|rdf:Description[@rdf:about='']"/>
     </xsl:when>
     <xsl:otherwise>
      <dl><dt>Namespace</dt><dd><xsl:value-of select="concat($nsuri,$needhash)"/></dd></dl>
     </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="generalexamples"/>

    <h2 id="class_def">Classes</h2>
    <xsl:call-template name="cplist">
     <xsl:with-param name="l" select="rdfs:Class[*]|owl:Class[*]"/>
    </xsl:call-template>
    <dl>
     <xsl:apply-templates select="rdfs:Class|owl:Class"/>
    </dl>

    <h2 id="property_def">Properties</h2>
    <xsl:call-template name="cplist">
     <xsl:with-param name="l" select="rdf:Property[*]|owl:ObjectProperty[*]|owl:DatatypeProperty[*]|owl:AnnotationProperty[*]"/>
    </xsl:call-template>
    <dl>
     <xsl:apply-templates select="rdf:Property|owl:ObjectProperty|owl:DatatypeProperty|owl:AnnotationProperty"/>
    </dl>

     <xsl:apply-templates select="rdf:Description[rdf:type]"/>

    <xsl:call-template name="findmore">
     <xsl:with-param name="l" select="*[local-name()!='Class' and name()!='rdf:Property' and name()!='owl:ObjectProperty' and name()!='owl:DatatypeProperty' and name()!='owl:AnnotationProperty' and name()!='owl:Ontology' and name()!='ex:Example' and name()!='rdf:Description']"/>
    </xsl:call-template>

    <xsl:call-template name="footer">
     <xsl:with-param name="status">Status: Schema updated <xsl:value-of select="owl:Ontology/dcterms:modified"/>.XSLT modified <xsl:value-of select="$_doas/doas:release/doas:created"/>. Stylesheet copyleft under GPL.</xsl:with-param>
    </xsl:call-template>
   </body>
  </html>
 </xsl:template>

 <xsl:template match="*">
 <!-- Catch all - general properties handler -->
  <dt>
   <xsl:choose>
    <xsl:when test="substring(name(),1,3)='rdf'">
     <xsl:value-of select="local-name()"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="name()"/>
    </xsl:otherwise>
   </xsl:choose>
   <xsl:if test="@xml:lang">
    (@<xsl:value-of select="@xml:lang"/>)
   </xsl:if>
  </dt>
  <dd>
   <xsl:choose>
    <xsl:when test="*|@*[name!='xml:lang']">
     <dl>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates select="*"/>
     </dl>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="."/>
    </xsl:otherwise>
   </xsl:choose>
  </dd>
 </xsl:template>

 <xsl:template match="@*">
 <!--** Displays attribute values  -->
  <dt>
   <xsl:choose>
    <xsl:when test="substring(name(),1,3)='rdf'">
     <xsl:value-of select="local-name()"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="name()"/>
    </xsl:otherwise>
   </xsl:choose>
  </dt>
  <dd><xsl:value-of select="."/></dd>
 </xsl:template>

 <xsl:template match="@xml:lang">
 <!--** xml:lang is displayed with element name as (@en) etc.  -->
 </xsl:template>

 <xsl:template match="*[@rdf:resource|@rdf:about]">
 <!--** If the element has URI ref (rdf:about/rdf:resource) -->
  <dt><xsl:value-of select="name()"/></dt>
  <dd><xsl:value-of select="@rdf:resource|@rdf:about"/></dd>
 </xsl:template>

 <xsl:template match="rdfs:*[@rdf:resource|@rdf:about]">
 <!--** RDFS element with URI ref (rdf:about/rdf:resource) -->
  <dt><xsl:value-of select="local-name()"/></dt>
  <dd><xsl:value-of select="@rdf:resource|@rdf:about"/></dd>
 </xsl:template>

 <xsl:template match="rdf:RDF/rdf:Property|rdf:RDF/rdfs:Class|rdf:RDF/owl:*[local-name() != 'Ontology']|rdf:RDF/rdf:Description[rdf:type]">
 <!--** Class and Property definition  -->
  <dt>
   <xsl:call-template name="idabout"/>
  </dt>
  <dd><dl>
   <xsl:apply-templates select="@*[name()!='rdf:about' and name()!='rdf:ID' and name()!='rdfs:label']"/>
   <xsl:apply-templates select="*[name()!='rdfs:label']"/>
  </dl></dd>
 </xsl:template>

 <xsl:template match="rdfs:domain[@rdf:resource]|rdfs:range[@rdf:resource]|rdfs:subClassOf[@rdf:resource]|rdfs:subPropertyOf[@rdf:resource]">
 <!--** domain, range, subClassOf, subPropertyOf treated specially  -->
  <dt class="essential"><xsl:value-of select="local-name()"/></dt>
  <dd class="essential"><xsl:value-of select="@rdf:resource"/></dd>
 </xsl:template>

 <xsl:template match="owl:Ontology/dc:*|dc:Desciption/dc:*|owl:Ontology/dcterms:*|dc:Desciption/dcterms:*|owl:versionInfo">
 <!--** Annotation properties in ontology/schema description  -->
  <dt><xsl:value-of select="local-name()"/></dt>
  <dd><xsl:value-of select="."/></dd>
 </xsl:template>

 <xsl:template match="owl:Ontology/dc:*[@rdf:resource]|dc:Desciption/dc:*[@rdf:resource]|owl:Ontology/dcterms:*[@rdf:resource]|dc:Desciption/dcterms:*[@rdf:resource]">
 <!--** source, relation be put hyper link  -->
  <dt><xsl:value-of select="local-name()"/></dt>
  <dd><a href="{@rdf:resource}"><xsl:value-of select="@dc:title"/></a> <xsl:apply-templates select="@dc:format"/></dd>
 </xsl:template>

 <xsl:template match="owl:Ontology/dc:description|owl:Ontology/rdfs:comment|dc:Desciption/dc:description">
 <!--** Ontology/Schema description property -->
  <p>
   <xsl:if test="@xml:lang='ja'"><img src="/parts/ja.png" alt="[ja]"/></xsl:if>
   <xsl:value-of select="."/>
  </p>
 </xsl:template>

 <xsl:template match="owl:Ontology[@rdf:about='']|rdf:Description[@rdf:about='']">
 <!--** Description of this ontoloty/schema itself  -->
  <h1><xsl:value-of select="dc:title|@dc:title"/></h1>
  <div class="abstract">
  <xsl:apply-templates select="dc:description|rdfs:comment"/>
  </div>
  <dl>
   <dt>Namespace</dt>
   <dd><xsl:value-of select="concat($nsuri,$needhash)"/></dd>
   <xsl:apply-templates select="dcterms:created"/>
   <xsl:apply-templates select="dcterms:modified"/>
   <xsl:apply-templates select="dc:date"/>
   <xsl:apply-templates select="owl:versionInfo"/>
   <xsl:apply-templates select="dc:source"/>
   <xsl:apply-templates select="dc:relation"/>
  </dl>
 </xsl:template>

 <xsl:template match="@dc:format">
  (<xsl:value-of select="."/>)
 </xsl:template>

 <xsl:template match="*/rdfs:label|*/@rdfs:label">
 <!--** Labels of class/property will be shown in a [] blacket. -->
  <span class="label"> [<xsl:value-of select="."/>]</span>
 </xsl:template>
 
 <xsl:template match="ex:example">
 <!--** Show examples of the ontology/schema for readers -->
  <dt>Example</dt>
  <dd>
   <xsl:if test=".//dc:description"><p><xsl:value-of select=".//dc:description"/></p></xsl:if>
   <div class="example"><pre class="ex {.././@rdf:ID}"><xsl:value-of select=".//ex:code"/></pre></div>
  </dd>
 </xsl:template>

 <!-- named templates -->
 <xsl:template name="toc">
  <p>
   <xsl:if test="/rdf:RDF/ex:Example"><a href="#ex">Example</a> | </xsl:if>
   <a href="#class_def">Class</a> (<xsl:value-of select="count(/rdf:RDF/rdfs:Class|/rdf:RDF/owl:Class)"/>) | 
   <a href="#property_def">Property</a> (<xsl:value-of select="count(/rdf:RDF/rdf:Property|/rdf:RDF/owl:ObjectProperty|/rdf:RDF/owl:DatatypeProperty|/rdf:RDF/owl:AnnotationProperty)"/>)
  </p>
 </xsl:template>

 <xsl:template name="namespace">
  <dt>Namespace</dt>
  <dd>
   <xsl:choose>
    <xsl:when test="@xml:base"><xsl:value-of select="@xml:base"/>#</xsl:when>
    <xsl:when test="$xmlfile"><xsl:value-of select="$xmlfile"/># (guess from source)</xsl:when>
    <xsl:otherwise>unknown</xsl:otherwise>
   </xsl:choose>
  </dd>
 </xsl:template>

 <xsl:template name="generalexamples">
  <xsl:variable name="ex" select="./*[local-name()='Example']"/>
  <xsl:variable name="exc" select="count($ex)"/>
  <xsl:if test="$ex">
   <h2 id="ex">Example<xsl:if test="$exc &gt; 1">s</xsl:if></h2>
   <xsl:for-each select="$ex">
    <xsl:if test="$exc &gt; 1"><h3>Example <xsl:value-of select="position()"/></h3></xsl:if>
    <p><xsl:value-of select="dc:description"/><br/><img src="/parts/ja.png" alt="[ja]"/> <xsl:value-of select="dc:description[@xml:lang='ja']"/>
    <xsl:apply-templates select="ex:pfx"/></p>
    
    <xsl:if test="ex:trial">
     <p>Try example(s) at <a href="{ex:trial/@rdf:resource}"><xsl:value-of select="ex:trial/@rdf:resource"/></a> .</p>
    </xsl:if>
    <xsl:if test="h:img">
     <p><img src="{h:img/@rdf:resource}"/></p>
    </xsl:if>
    <div class="example"><pre class="{ex:pfx}"><xsl:value-of select="ex:code"/></pre></div>
   </xsl:for-each>
  </xsl:if>
 </xsl:template>

 <!-- for example prefix -->
 <xsl:template match="ex:pfx">
  <br/>(Note: vocabulary of this schema represented with prefix <strong><xsl:value-of select="."/></strong>)
 </xsl:template>

 <!-- Class/Proprty list with link -->
 <xsl:template name="cplist">
  <xsl:param name="l"/>
  <p>
  <xsl:choose>
   <xsl:when test="$l"> |
    <xsl:for-each select="$l">
     <a>
      <xsl:choose>
       <xsl:when test="@rdf:ID">
        <xsl:attribute name="href">#<xsl:value-of select="@rdf:ID"/></xsl:attribute>
        <xsl:value-of select="@rdf:ID"/>
       </xsl:when>
       <xsl:when test="contains(@rdf:about,'#')">
        <xsl:attribute name="href">#<xsl:value-of select="substring-after(@rdf:about,'#')"/></xsl:attribute>
        <xsl:value-of select="substring-after(@rdf:about,'#')"/>
       </xsl:when>
       <xsl:when test="contains(@rdf:about,$nsuri)">
        <xsl:attribute name="href">#<xsl:value-of select="substring(@rdf:about,$localst)"/></xsl:attribute>
        <xsl:value-of select="substring(@rdf:about,$localst)"/>
       </xsl:when>
<!--
       <xsl:when test="$needhash=''">
        <xsl:attribute name="href">#<xsl:value-of select="substring(@rdf:about,$localst)"/></xsl:attribute>
        <xsl:value-of select="substring(@rdf:about,$localst)"/>
       </xsl:when>
-->
       <xsl:when test="rdfs:label|@rdfs:label">
        <xsl:attribute name="href">#<xsl:value-of select="generate-id(.)"/></xsl:attribute>
        <xsl:value-of select="rdfs:label|@rdfs:label"/>
       </xsl:when>
       <xsl:otherwise>
        <xsl:attribute name="href">#<xsl:value-of select="generate-id(.)"/></xsl:attribute>
        unlabeled(<xsl:value-of select="position()"/>)
       </xsl:otherwise>
      </xsl:choose>
     </a> |
    </xsl:for-each>
   </xsl:when>
   <xsl:otherwise>
   No instance defined.
   </xsl:otherwise>
  </xsl:choose>
  </p>
 </xsl:template>

 <xsl:template name="findmore">
  <xsl:param name="l"/>
  <xsl:if test="$l">
   <h2>More Elements</h2>
   <dl>
    <xsl:for-each select="$l">
     <dt class="more-elt"><xsl:call-template name="idabout"/></dt>
     <dd><dl>
      <dt>rdf:type</dt><dd class="rdftype"><xsl:value-of select="name()"/></dd>
      <xsl:apply-templates select="@*|*"/>
     </dl></dd>
    </xsl:for-each>
   </dl>
  </xsl:if>
 </xsl:template>

 <xsl:template name="idabout">
 <!--** determines class and id of the node -->
  <xsl:attribute name="class">
   <xsl:value-of select="translate(name(),':',' ')"/>
   <xsl:if test="rdf:type">
    <xsl:value-of select="concat(' ',substring-after('#',rdf:type/@rdf:resource))"/>
   </xsl:if>
  </xsl:attribute>
   <xsl:choose>
    <xsl:when test="@rdf:ID">
     <xsl:attribute name="id"><xsl:value-of select="@rdf:ID"/></xsl:attribute>
     <xsl:value-of select="@rdf:ID"/>
    </xsl:when>
    <xsl:when test="contains(@rdf:about,'#')">
     <xsl:attribute name="id"><xsl:value-of select="substring-after(@rdf:about,'#')"/></xsl:attribute>
     <xsl:value-of select="substring-after(@rdf:about,'#')"/>
    </xsl:when>
    <!--xsl:when test="$needhash=''"
     <xsl:attribute name="id"><xsl:value-of select="substring(@rdf:about,$localst)"/></xsl:attribute>
     <xsl:value-of select="substring(@rdf:about,$localst)"/>
    </xsl:when>-->
    <xsl:when test="contains(@rdf:about,$nsuri)">
     <xsl:attribute name="id"><xsl:value-of select="substring(@rdf:about,$localst)"/></xsl:attribute>
     <xsl:value-of select="substring(@rdf:about,$localst)"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:attribute name="id"><xsl:value-of select="generate-id(.)"/></xsl:attribute>
     <xsl:value-of select="@rdf:about"/>
    </xsl:otherwise>
   </xsl:choose>
   <xsl:apply-templates select="rdfs:label|@rdfs:label"/>
   <span class="cp-type"> (<xsl:value-of select="name()"/><xsl:call-template name="owltypes"/>)</span>
 </xsl:template>

 <xsl:template name="owltypes">
  <xsl:for-each select="./rdf:type/@rdf:resource">
   <xsl:if test="contains(.,'&owl;')">
    <xsl:value-of select="concat(', owl:', substring-after(.,'#'))"/>
   </xsl:if>
  </xsl:for-each>
 </xsl:template>

 <xsl:template name="htmlhead">
 <!--** Generates some XHTML head elements -->
  <link rel="stylesheet" href="/parts/kan01.css" type="text/css" />
  <style type="text/css">/*<![CDATA[*/
.Class, .Property, .DatatypeProperty, .ObjectProperty, .AnnotationProperty, .more-elt {padding:0.4em; width:90%}
.Class {background:#fee}
.Property, .DatatypeProperty, .ObjectProperty, .AnnotationProperty {background:#eef} .more-elt {background:#efe}
.owl {border:#88f 1px solid} .rdfs, .rdf {border:#f88 1px solid}
    /*.DatatypeProperty {border:#88f 1px solid}*/ .ObjectProperty {border:#33c 1px solid}
.label {font-weight: normal; color: gray}
.cp-type {font-weight: normal; font-size:90%; color: maroon}
dd dt {font-weight: normal; color: #060}
dt.essential {font-weight:bold}
dd.rdftype {color:maroon}
.abstract {border: dotted 1px gray; padding:1em}
pre {white-space: pre}
/*dd.dr {color:#00c}*/
/*   ]]>*/</style>
<!--<script type="text/javascript" src="/ns/ns-schema.js">//</script>-->
 </xsl:template>

 
 <xsl:include href="./banner-footer.xsl"/>

</xsl:stylesheet>
