March 22, 2004 Patch to rdfs2html.xsl

Dom,

Here is a patch which brings the CVS version of rdfs2html.xsl on 
dev.w3.org to match the most recent development version I have been using.

Let me know what you think. I have some ideas on how to add more support 
for RDF/XML syntax shortcuts that I may be able to get to in a few days.

Bob
Index: rdfs2html.xsl
===================================================================
RCS file: /sources/public/2004/rdfs2html/rdfs2html.xsl,v
retrieving revision 1.1
diff -u -p -u -r1.1 rdfs2html.xsl
--- rdfs2html.xsl	18 Mar 2004 09:59:09 -0000	1.1
+++ rdfs2html.xsl	22 Mar 2004 17:25:14 -0000
@@ -15,12 +15,13 @@
     xmlns:rdf="&rdfnsuri;"
     xmlns:rdfs="&rdfsnsuri;"
     xmlns:rcs="http://www.w3.org/2001/03swell/rcs#"
-    exclude-result-prefixes="dc ont rdf rdfs rcs r2h"
+    xmlns:owl="http://www.w3.org/2002/07/owl#"
+    exclude-result-prefixes="dc ont rdf rdfs rcs r2h owl"
     xmlns:r2h='http://www.w3.org/2002/06/rdfs2html.xsl'>
 
   <xsl:output method="xml" indent='yes' doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
 
-  <xsl:param name="recursive" select="'yes'"/>
+  <xsl:param name="recursive" select="'no'"/>
   <xsl:variable name="ns" select="/rdf:RDF/rdf:Description/@rdf:about"/>
 
   <html>
@@ -43,33 +44,66 @@ href="http://www.ercim.org/"><acronym
 title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>, <a
 href="http://www.keio.ac.jp/">Keio University</a>). All Rights
     Reserved. http://www.w3.org/Consortium/Legal/. W3C <a href="http://www.w3.org/Consortium/Legal/copyright-software">software licensing</a> rules apply.</p>
-    <address><a href="http://www.w3.org/People/Dom/">Dominique Haza&#235;l-Massieux</a> - $Id: rdfs2html.xsl,v 1.1 2004/03/18 09:59:09 dom Exp $</address>
+    <address><a href="http://www.w3.org/People/Dom/">Dominique Haza&#235;l-Massieux</a> - $Id: rdfs2html.xsl,v 1.4 2004/03/19 16:49:16 bclary Exp $</address>
   </html>
 
   <xsl:template match="/">
+    <xsl:variable name="schemacount" select="count(/rdf:RDF/*[@rdf:about]/dc:title | /rdf:RDF/*[@rdf:about and @dc:title])"/>
     <xsl:variable name="title">
       <xsl:choose>
-        <xsl:when test="//*[@rdf:about='']/dc:title">
-          <xsl:value-of select="//*[@rdf:about]/dc:title"/>
-        </xsl:when>
-        <xsl:when test="//rdf:Description[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:title">
-          <xsl:value-of select="//rdf:Description[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:title"/>
+        <xsl:when test="$schemacount=1">
+          <xsl:choose>
+            <xsl:when test="//*[@rdf:about='']/dc:title">
+              <xsl:value-of select="//*[@rdf:about='']/dc:title"/>
+            </xsl:when>
+            <xsl:when test="//rdf:Description[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:title">
+              <xsl:value-of select="//rdf:Description[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:title"/>
+            </xsl:when>
+            <xsl:when test="//owl:Ontology[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:title">
+              <xsl:value-of select="//owl:Ontology[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:title"/>
+            </xsl:when>
+            <xsl:when test="//rdf:Description[@rdf:about]/dc:title">
+              <xsl:value-of select="//rdf:Description[@rdf:about]/dc:title"/>
+            </xsl:when>
+            <xsl:when test="//*[@rdf:about and @dc:title]">
+              <xsl:value-of select="//*/@dc:title"/>
+            </xsl:when>
+            <xsl:otherwise>
+              Untitled RDF Schema
+            </xsl:otherwise>
+          </xsl:choose>
         </xsl:when>
         <xsl:otherwise>
-          Untitled RDF Schema
+          Multiple Schemas
         </xsl:otherwise>
       </xsl:choose>
     </xsl:variable>
     <xsl:variable name="description">
-     <xsl:choose>
-      <xsl:when test=".//*[@rdf:about='']/dc:description">
-       <xsl:value-of select=".//*[@rdf:about='']/dc:description"/>
-      </xsl:when>
-      <xsl:when test=".//rdf:Description[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:description">
-       <xsl:value-of select=".//rdf:Description[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:description"/>
-      </xsl:when>
-      <xsl:otherwise></xsl:otherwise>
-     </xsl:choose>
+      <xsl:choose>
+        <xsl:when test="$schemacount=1">
+          <xsl:choose>
+           <xsl:when test=".//*[@rdf:about='']/dc:description">
+            <xsl:value-of select=".//*[@rdf:about='']/dc:description"/>
+           </xsl:when>
+           <xsl:when test=".//rdf:Description[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:description">
+            <xsl:value-of select=".//rdf:Description[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:description"/>
+           </xsl:when>
+           <xsl:when test=".//owl:Ontology[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:description">
+             <xsl:value-of select=".//owl:Ontology[@rdf:about and contains(@rdf:about,'#') and substring-after(@rdf:about,'#')='']/dc:description"/>
+           </xsl:when>
+           <xsl:when test=".//rdf:Description[@rdf:about]/dc:description">
+            <xsl:value-of select=".//rdf:Description[@rdf:about]/dc:description"/>
+           </xsl:when>
+           <xsl:when test=".//*[@rdf:about and @dc:title and @dc:description]">
+            <xsl:value-of select=".//*/@dc:description"/>
+           </xsl:when>
+           <xsl:otherwise></xsl:otherwise>
+          </xsl:choose>
+        </xsl:when>
+        <xsl:otherwise>
+          This document contains multiple schemas
+        </xsl:otherwise>
+      </xsl:choose>
     </xsl:variable>
     <html>
       <head>
@@ -84,9 +118,16 @@ href="http://www.keio.ac.jp/">Keio Unive
       <body>
         <div id="header">
         <h1><xsl:value-of select="$title"/></h1>
-        <xsl:if test="normalize-space($description)">
-          <p><xsl:value-of select="$description"/></p>
-        </xsl:if>
+        <xsl:choose>
+          <xsl:when test="$schemacount=1">
+            <xsl:if test="normalize-space($description)">
+              <p><xsl:value-of select="$description"/></p>
+            </xsl:if>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:apply-templates select="/rdf:RDF/*[@rdf:about]/dc:title"/>
+          </xsl:otherwise>
+        </xsl:choose>
         </div>
         <div id="note">
         <h4>Important note</h4>
@@ -133,7 +174,7 @@ href="http://www.keio.ac.jp/">Keio Unive
         </ul>
         <hr/>
         <address>
-          <xsl:value-of select=".//*[@rdf:about='']/rcs:id"/> (HTML display done through <a href="http://www.w3.org/2002/06/rdfs2html.xsl">http://www.w3.org/2002/06/rdfs2html.xsl</a> $Id: rdfs2html.xsl,v 1.1 2004/03/18 09:59:09 dom Exp $)
+          <xsl:value-of select=".//*[@rdf:about='']/rcs:id"/> (HTML display done through <a href="http://www.w3.org/2002/06/rdfs2html.xsl">http://www.w3.org/2002/06/rdfs2html.xsl</a> $Id: rdfs2html.xsl,v 1.4 2004/03/19 16:49:16 bclary Exp $)
         </address>
       </body>
     </html>
@@ -157,14 +198,12 @@ href="http://www.keio.ac.jp/">Keio Unive
          </xsl:when>
        </xsl:choose>
      </xsl:variable>
+
      <dt>
+      <span class="about">
       <xsl:call-template name="labelize">
         <xsl:with-param name="resource" select="$ref"/>
       </xsl:call-template>
-      <span class="about">
-      <xsl:text> [</xsl:text>
-      <a href="{$ref}"><xsl:value-of select="substring-after($ref,'#')"/></a>
-      <xsl:text>]</xsl:text>
       </span>
     </dt>
     <xsl:if test="rdfs:comment">
@@ -198,18 +237,25 @@ href="http://www.keio.ac.jp/">Keio Unive
           <xsl:text>Sub class of </xsl:text>
         </xsl:when>
         <xsl:otherwise>
-          <a href="{concat(namespace-uri(),local-name())}"><xsl:call-template name="labelize">
+          <xsl:call-template name="labelize">
             <xsl:with-param name="resource" select="concat(namespace-uri(),local-name())"/>
           </xsl:call-template>
-          </a><xsl:text> </xsl:text>
+          <xsl:text> </xsl:text>
         </xsl:otherwise>
       </xsl:choose>
-      <a href="{@rdf:resource}"><xsl:call-template name="labelize"><xsl:with-param name="resource" select='@rdf:resource'/></xsl:call-template></a>
+      <xsl:call-template name="labelize"><xsl:with-param name="resource" select='@rdf:resource'/></xsl:call-template>
     </dd>
   </xsl:template>
 
   <xsl:template name="labelize">
     <xsl:param name="resource"/>
+
+    <xsl:variable name="qname">
+      <xsl:call-template name="create-qname">
+        <xsl:with-param name="resource"><xsl:value-of select="$resource"/></xsl:with-param>
+      </xsl:call-template>
+    </xsl:variable>
+
     <xsl:choose>
       <!-- Testing if this is a URI relative to the current doc, an HTTP URI, or something else -->
       <xsl:when test="starts-with($resource,'#')">
@@ -218,14 +264,25 @@ href="http://www.keio.ac.jp/">Keio Unive
             <xsl:value-of select="/rdf:RDF/*[@rdf:about=$resource  or @rdf:ID=substring-after($resource,'#') or (@ID=substring-after($resource,'#') and namespace-uri()='&rdfnsuri;') or (@about=$resource and namespace-uri()='&rdfnsuri;')]/rdfs:label"/>
           </xsl:when>
           <xsl:otherwise>
-            <xsl:value-of select="$resource"/>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:when>
+      <xsl:when test="starts-with($resource,'http://') and
+              /rdf:RDF/*[@rdf:about=$resource or @rdf:ID=substring-after($resource,'#') or (@about=$resource and namespace-uri()='&rdfnsuri;') or (@ID=substring-after($resource,'#') and namespace-uri()='&rdfnsuri;')]/rdfs:label">
+            <xsl:choose>
+              <!-- This test doesn't handle the case where the resouce doesn't use #-->
+              <xsl:when test="/rdf:RDF/*[@rdf:about=$resource or @rdf:ID=substring-after($resource,'#') or (@about=$resource and namespace-uri()='&rdfnsuri;') or (@ID=substring-after($resource,'#') and namespace-uri()='&rdfnsuri;')]/rdfs:label">
+                <xsl:value-of select="/rdf:RDF/*[@rdf:about=$resource or @rdf:ID=substring-after($resource,'#') or (@about=$resource and namespace-uri()='&rdfnsuri;') or (@ID=substring-after($resource,'#') and namespace-uri()='&rdfnsuri;')]/rdfs:label[1]"/>
+              </xsl:when>
+              <xsl:otherwise>
+              </xsl:otherwise>
+            </xsl:choose>
+          </xsl:when>
       <xsl:otherwise>
         <xsl:choose>
           <xsl:when test="starts-with($resource,'http://') and contains($resource,'#') and concat(substring-before($resource,'#'),'#')=$ns and /rdf:RDF/*[@rdf:about=$resource or @about=$resource]/rdfs:label">
             <xsl:value-of select="/rdf:RDF/*[@rdf:about=$resource or @about=$resource]/rdfs:label"/>
+            <xsl:value-of select="$qname"/>
           </xsl:when>
           <xsl:when test="starts-with($resource,'http://') and $recursive='yes'">
             <xsl:message>
@@ -238,7 +295,6 @@ href="http://www.keio.ac.jp/">Keio Unive
                 <xsl:value-of select="document($resource)/rdf:RDF/*[@rdf:about=$resource or @rdf:ID=substring-after($resource,'#') or (@about=$resource and namespace-uri()='&rdfnsuri;') or (@ID=substring-after($resource,'#') and namespace-uri()='&rdfnsuri;')]/rdfs:label[1]"/>
               </xsl:when>
               <xsl:otherwise>
-                <xsl:value-of select="$resource"/>
               </xsl:otherwise>
             </xsl:choose>
           </xsl:when>
@@ -246,10 +302,132 @@ href="http://www.keio.ac.jp/">Keio Unive
             <xsl:text>this schema</xsl:text>
           </xsl:when>
           <xsl:otherwise>
-            <xsl:value-of select="$resource"/>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:otherwise>
     </xsl:choose>
+    <xsl:if test="$resource!='' and $qname!=''"> <!-- bc handle sick cases like log.n3->log.rdfs -->
+      [<a href="{$resource}"><xsl:value-of select="$qname"/></a>]
+    </xsl:if>
   </xsl:template>
+
+  <xsl:template name="get-name">
+    <xsl:param name="head"/>
+
+    <xsl:choose>
+
+      <xsl:when test="contains($head, '#')">
+
+        <xsl:value-of select="substring-after($head, '#')"/>
+
+      </xsl:when>
+
+      <xsl:otherwise>
+
+        <xsl:variable name="tail">
+          <xsl:if test="contains($head, '/')">
+            <xsl:value-of select="substring-after($head, '/')"/>
+          </xsl:if>
+        </xsl:variable> 
+
+        <xsl:choose>
+          <xsl:when test="$tail!=''">
+            <xsl:call-template name="get-name">
+              <xsl:with-param name="head">
+                <xsl:value-of select="$tail"/>
+              </xsl:with-param>
+            </xsl:call-template>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$head"/>
+          </xsl:otherwise>
+        </xsl:choose>
+
+      </xsl:otherwise>
+
+    </xsl:choose>
+
+  </xsl:template>
+
+  <xsl:template name="get-namespace">
+    <xsl:param name="uri"/>
+
+    <xsl:variable name="name">
+      <xsl:call-template name="get-name">
+        <xsl:with-param name="head">
+          <xsl:value-of select="$uri"/>
+        </xsl:with-param>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:value-of select="substring-before($uri, $name)"/>
+  </xsl:template>
+
+  <xsl:template name="get-prefix">
+    <xsl:param name="uri"/>
+
+    <xsl:variable name="namespace">
+       <xsl:call-template name="get-namespace">
+         <xsl:with-param name="uri">
+           <xsl:value-of select="$uri"/>
+         </xsl:with-param>
+       </xsl:call-template>
+     </xsl:variable>
+
+     <xsl:for-each select="/rdf:RDF/namespace::*">
+       <xsl:if test=".=$namespace">
+         <xsl:value-of select="name()"/>
+       </xsl:if>
+     </xsl:for-each>
+
+  </xsl:template>
+
+  <xsl:template name="create-qname">
+    <xsl:param name="resource"/>
+
+     <xsl:variable name="name">
+       <xsl:call-template name="get-name">
+         <xsl:with-param name="head">
+           <xsl:value-of select="$resource"/>
+         </xsl:with-param>
+       </xsl:call-template>
+     </xsl:variable>
+
+     <xsl:variable name="namespace">
+       <xsl:call-template name="get-namespace">
+         <xsl:with-param name="uri">
+           <xsl:value-of select="$resource"/>
+         </xsl:with-param>
+       </xsl:call-template>
+     </xsl:variable>
+
+     <xsl:variable name="prefix">
+       <xsl:call-template name="get-prefix">
+         <xsl:with-param name="uri">
+           <xsl:value-of select="$resource"/>
+         </xsl:with-param>
+       </xsl:call-template>
+     </xsl:variable>
+
+    <xsl:choose>
+      <xsl:when test="$prefix!='' and $name!=''">
+        <xsl:value-of select="$prefix"/>:<xsl:value-of select="$name"/>
+      </xsl:when>
+      <xsl:when test="$namespace!='' and $name!=''">
+        <xsl:value-of select="$namespace"/><xsl:value-of select="$name"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$resource"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+  
+  <xsl:template match="dc:title">
+    <xsl:if test="parent::rdf:Description or parent::owl:Ontology">
+      <h2><xsl:value-of select="."/></h2>
+      <p><xsl:value-of select="../dc:description"/></p>
+    </xsl:if>
+  </xsl:template>
+ 
+
 </xsl:stylesheet>

Received on Monday, 22 March 2004 12:34:54 UTC