Skip to content

Instantly share code, notes, and snippets.

@stain stain/example.xml
Created Jan 28, 2013

Embed
What would you like to do?
XSLT for translating OWL ontologies in RDF/XML format (specifically from OWL API/Protege) to a simplistic HTML, with a hyperlink to documentation.html. To use, modify the XML headers of the OWL file as in the example.xml below.
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="owl2html.xslt"?>
<rdf:RDF xmlns="http://example.com/ontology/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:dct="http://purl.org/dc/terms/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<owl:Ontology rdf:about="http://example.com/ontology/">
<dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2013-01-09T12:29:35+01:00</dct:modified>
<dc:creator rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Tha Creator</dc:creator>
<dc:contributor rdf:datatype="http://www.w3.org/2001/XMLSchema#string">John Doe</dc:contributor>
<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2013-02-09T12:29:35+01:00</dct:issued>
<dct:title xml:lang="en">This is the title</dct:title>
</owl:Ontology>
<owl:ObjectProperty rdf:about="http://example.com/ontology/property1">
<rdfs:label xml:lang="en">First property</rdfs:label>
<rdfs:comment xml:lang="en">Provides the very first object property</rdfs:comment>
</owl:ObjectProperty>
<owl:DatatypeProperty rdf:about="http://example.com/ontology/property2">
<rdfs:label xml:lang="en">Second property</rdfs:label>
<rdfs:comment xml:lang="en">This is a data type property</rdfs:comment>
</owl:DatatypeProperty>
</rdf:RDF>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:dct="http://purl.org/dc/terms/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>
<xsl:template match="/">
<html>
<body>
<h1><xsl:value-of select="rdf:RDF/owl:Ontology/dct:title"/></h1>
<h2>OWL ontology</h2>
<dl>
<dt>Ontology IRI</dt>
<dd><xsl:value-of select="rdf:RDF/owl:Ontology/@rdf:about"/></dd>
<dt>Version IRI</dt>
<dd><xsl:value-of select="rdf:RDF/owl:Ontology/owl:versionIRI/@rdf:resource"/></dd>
<dt>Creator</dt>
<xsl:for-each select="//dc:creator">
<dd><xsl:value-of select="." /></dd>
</xsl:for-each>
<dt>Contributors</dt>
<xsl:for-each select="//dc:contributor">
<dd><xsl:value-of select="." /></dd>
</xsl:for-each>
<dt>Issued</dt>
<xsl:for-each select="//dct:issued">
<dd><xsl:value-of select="." /></dd>
</xsl:for-each>
<dt>Last modified</dt>
<xsl:for-each select="//dct:modified">
<dd><xsl:value-of select="." /></dd>
</xsl:for-each>
</dl>
<p>Please see the <a href="documentation.html">documentation for
<xsl:value-of select="rdf:RDF/owl:Ontology/dct:title"/>
</a>.</p>
<p>This HTML is meant to show a simple browser introduction to the ontology and has been
automatically created using XSLT. To see the
source OWL as RDF/XML, either use "Save As" or "View Source".
</p>
<h3>Defined object properties</h3>
<dl>
<xsl:for-each select="//owl:ObjectProperty">
<dt>
<em><xsl:value-of select="rdfs:label" /></em>
&#xa0;
<code><xsl:value-of select="@rdf:about" /></code>
</dt>
<dd><small><xsl:value-of select="rdfs:comment" /></small></dd>
</xsl:for-each>
</dl>
<h3>Defined data type properties</h3>
<dl>
<xsl:for-each select="//owl:DatatypeProperty">
<dt><code><xsl:value-of select="@rdf:about" /></code>
&#xa0;
<em><xsl:value-of select="rdfs:label" /></em></dt>
<dd><small><xsl:value-of select="rdfs:comment" /></small></dd>
</xsl:for-each>
</dl>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
@stain

This comment has been minimized.

Copy link
Owner Author

commented Jan 28, 2013

TODO:

  • Auto-generate link to http://www.essepuntato.it/lode/ - by javascript window.location ?
  • Include classes
  • Show ontology comment and description
  • Select documentation link(s) from annotation property (rdfs:seeAlso ? dcterms:hasFormat ? )
@karimmahmoudshawky

This comment has been minimized.

Copy link

commented Nov 4, 2014

it great solution, but i want to transform owl to html directly. it is doable ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.