« Querying OWL | Main | Funding opportunities RDF example »
June 09, 2010
XSLT to turn RDFS into an HTML view
<xsl:stylesheet version="1.0" id="my_style" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:dubcore="http://dublincore.org/2003/03/24/dces#" xmlns:dc="http://orlando.drc.com/SemanticWeb/DAML/Ontology/DC/ver/0.1.0/dces-ont#" xmlns:ves="http://orlando.drc.com/SemanticWeb/DAML/Ontology/VES/ver/0.1.0/drc-ves-ont#" xmlns:event="http://purl.org/rss/1.0/modules/event/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:fundops="http://www.medev.ac.uk/interoperability/rss/1.0/modules/fundops/rss1.0fundopsmodule#"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/> <!-- <xsl:strip-space elements ="*" /> --> <xsl:template match="/"> <div id="schema" xmlns="http://www.w3.org/1999/xhtml" class="example"> <xsl:apply-templates/> </div> </xsl:template> <xsl:template match="owl:Ontology"> <h3><xsl:value-of select="@dubcore:title"/></h3> <p><xsl:value-of select="rdfs:comment"/></p> </xsl:template> <xsl:template match="rdfs:Class"> <xsl:if test="@rdfs:label"> <h4><xsl:value-of select="@rdfs:label"/> Class</h4> <p><xsl:value-of select="@rdfs:comment"/></p> </xsl:if> <xsl:if test="rdfs:label"> <h4><xsl:value-of select="rdfs:label"/> Class</h4> <p><xsl:value-of select="rdfs:comment"/></p> </xsl:if> <xsl:if test="rdfs:subClassOf"> <p>This is a sub-class of:</p> <ul> <xsl:for-each select="rdfs:subClassOf"> <li><xsl:value-of select="./@rdf:resource"/></li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="rdfs:isDefinedBy"> <p>Class defined by:</p> <ul> <xsl:for-each select="rdfs:isDefinedBy"> <li><xsl:value-of select="./@rdf:resource"/></li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="rdfs:domain"> <p>This class is in the following domains:</p> <ul> <xsl:for-each select="rdfs:domain"> <li><xsl:value-of select="./@rdf:resource"/></li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="rdfs:range/owl:oneOf"> <p>Range should be one of:</p> <ul> <xsl:for-each select="rdfs:range/owl:oneOf/owl:Thing"> <li><xsl:value-of select="./@rdf:about"/></li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="rdfs:range/owl:someValuesFrom"> <p>Range should be some values from:</p> <ul> <xsl:for-each select="rdfs:range/owl:someValuesFrom/owl:Thing"> <li> <xsl:value-of select="./@rdf:about"/> <xsl:if test="./rdf:value"><xsl:value-of select="./rdf:value"/></xsl:if> </li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="owl:equivalentClass"> <p>This class is an equivalent of:</p> <ul> <xsl:for-each select="owl:equivalentClass"> <li> <xsl:value-of select="./@rdf:resource"/> </li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="owl:disjointWith"> <p>This class is disjoint with:</p> <ul> <xsl:for-each select="owl:disjointWith"> <li> <xsl:value-of select="./@rdf:resource"/> </li> </xsl:for-each> </ul> </xsl:if> </xsl:template> <xsl:template match="rdf:Property"> <xsl:if test="@rdfs:label"> <h4><xsl:value-of select="@rdfs:label"/> property</h4> <p><xsl:value-of select="@rdfs:comment"/></p> </xsl:if> <xsl:if test="rdfs:label"> <h4><xsl:value-of select="rdfs:label/@rdf:value"/> property</h4> <p><xsl:value-of select="@rdfs:comment"/></p> </xsl:if> <xsl:if test="rdfs:subPropertyOf"> <p>This is a sub-property of:</p> <ul> <xsl:for-each select="rdfs:subPropertyOf"> <li><xsl:value-of select="./@rdf:resource"/></li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="rdfs:isDefinedBy"> <p>Property defined by:</p> <ul> <xsl:for-each select="rdfs:isDefinedBy"> <li><xsl:value-of select="./@rdf:resource"/></li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="rdfs:domain"> <p>Property is in the following domains:</p> <ul> <xsl:for-each select="rdfs:domain"> <li><xsl:value-of select="./@rdf:resource"/></li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="rdfs:range/@rdf:resource"> <p>Is in the range of:</p> <ul> <xsl:for-each select="rdfs:range/@rdf:resource"> <li><xsl:value-of select="."/></li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="rdfs:range/owl:oneOf"> <p>Range should be one of:</p> <ul> <xsl:for-each select="rdfs:range/owl:oneOf/owl:Thing"> <li> <xsl:value-of select="./@rdf:about"/> <xsl:if test="./rdf:value"><xsl:value-of select="./rdf:value"/></xsl:if> </li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="rdfs:range/owl:someValuesFrom"> <p>Range should be some values from:</p> <ul> <xsl:for-each select="rdfs:range/owl:someValuesFrom/owl:Thing"> <li> <xsl:value-of select="./@rdf:about"/><xsl:if test="./rdf:value"> <xsl:value-of select="./rdf:value"/></xsl:if> </li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="owl:equivalentProperty"> <p>This property is an equivalent of:</p> <ul> <xsl:for-each select="owl:equivalentProperty"> <li> <xsl:value-of select="./@rdf:resource"/> </li> </xsl:for-each> </ul> </xsl:if> <xsl:if test="owl:disjointWith"> <p>This property is disjoint with:</p> <ul> <xsl:for-each select="owl:disjointWith"> <li> <xsl:value-of select="./@rdf:resource"/> </li> </xsl:for-each> </ul> </xsl:if> </xsl:template> </xsl:stylesheet>
Tags: RDF
Posted by pj at June 9, 2010 10:53 AM