MediaWiki:SMWToHumanRead.xsl
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet 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#" version="2.0" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dwc="http://rs.tdwg.org/dwc/terms/" xmlns:dwctype="http://rs.tdwg.org/dwc/terms/vocabulary/" xmlns:owl="http://www.w3.org/2002/07/owl#">
<xsl:output method="html" encoding="UTF-8" indent="yes" /> <xsl:template match="rdf:RDF"> <html> <head> <title>RDF description</title> <style> .subject { margin: 2em; padding: 1em; border-style: outset; border-width: 2px; font-family: sans-serif; } .subject p { display: inline-block; background-color: #0b479d; color: white; padding: 1.5em; border-radius: 50%; } .subject h3 { display: inline-block; font-weight: normal; padding: 1em; } .property { color: darkgray; padding: 0.5em; } .object { color: gray; padding: 0.5em; text-align: justify; } .lang { color: silver;
} .attribute .name { color: black; padding: 0.5em; border-radius: 50%; border-style: solid; border-width: 1px; } .attribute .lang { background-color: lightgray; color: black; padding: 0.5em; border-radius: 50%; } .attribute .resource { background-color: #0b479d; color: white; padding: 0.5em; border-radius: 50%; } .attribute .value { background-color: none; border-color: #0b479d; border-style: dashed; border-width: 1px; padding: 0.5em; border-radius: 0.3em; color: gray; } a, a:visited, a:hover { color: #0b479d; white-space: nowrap; } </style> <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> </head> <body>
<a href="https://www.w3.org/RDF/"> <img src="http://www.w3.org/RDF/icons/rdf_w3c_icon.64" alt="RDF logo" border="0" id="logo" /> </a>
<xsl:for-each select="rdf:Description"> <xsl:call-template name="subject"> <xsl:with-param name="subject" select = "." /> </xsl:call-template> </xsl:for-each>
</body> </html> </xsl:template> <xsl:template name="subject"> <xsl:param name = "subject" /> <xsl:variable name="uri"><xsl:value-of select="@rdf:about" /></xsl:variable>
<xsl:attribute name="id"><xsl:value-of select="$uri"/></xsl:attribute>
Subject
<a target="_blank" rel="noopener noreferrer"> <xsl:attribute name="href"><xsl:value-of select="$uri"/></xsl:attribute> <xsl:value-of select="$uri" /> </a>
Property | Object |
---|
</xsl:template> <xsl:template name="property"> <xsl:param name = "property" /> <xsl:param name = "attributes" /> <xsl:choose> <xsl:when test=". != "> <tr> <td class="property"> <xsl:variable name="propertyUrl"><xsl:value-of select="namespace-uri(.)" /><xsl:value-of select="local-name(.)"/></xsl:variable> <a target="_blank" rel="noopener noreferrer"> <xsl:attribute name="href"><xsl:value-of select="$propertyUrl"/></xsl:attribute> <xsl:value-of select="$propertyUrl" /> </a> <xsl:for-each select="$attributes"> <xsl:call-template name="attribute"> <xsl:with-param name="attribute" select = "." /> </xsl:call-template> </xsl:for-each> </td> <td class="object"> <xsl:call-template name="content"> <xsl:with-param name="content" select = "." /> </xsl:call-template> </td> </tr> </xsl:when> <xsl:otherwise> <tr> <td class="property"> <xsl:variable name="propertyUrl"><xsl:value-of select="namespace-uri(.)" /><xsl:value-of select="local-name(.)"/></xsl:variable> <a target="_blank" rel="noopener noreferrer"> <xsl:attribute name="href"><xsl:value-of select="$propertyUrl"/></xsl:attribute> <xsl:value-of select="$propertyUrl" /> </a> </td> <td class="object">
</td> </tr> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="attribute"> <xsl:param name = "attribute" /> <tr class="attribute"> <td class="name"> <xsl:attribute name="class"><xsl:value-of select="local-name()"/></xsl:attribute> <xsl:value-of select="name()"/> </td> <td class="value"> <xsl:call-template name="content"> <xsl:with-param name="content" select = "." /> </xsl:call-template> </td> </tr> </xsl:template> <xsl:template name="content"> <xsl:param name = "content" /> <xsl:choose>
<xsl:when test="starts-with($content, 'http') and (not(contains($content, '|')))">
<a target="_blank" rel="noopener noreferrer"> <xsl:attribute name="href"><xsl:value-of select="."/></xsl:attribute> <xsl:value-of select="." /> </a>
</xsl:when> <xsl:otherwise> <xsl:value-of select="$content" /> </xsl:otherwise> </xsl:choose>
</xsl:template> </xsl:stylesheet>