Created
December 2, 2011 22:20
-
-
Save ljos/1425099 to your computer and use it in GitHub Desktop.
Transforms xml-keys documents from SSB to RDF/XML (in a horrible way). / Transformerer SSB dokumenter til RDF/XML (på en forferdelig måte). Code released under GPLv3 / Koden er sluppet under GPLv3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE rdf:RDF [ | |
<!ENTITY owl "http://www.w3.org/2002/07/owl#" > | |
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" > | |
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" > | |
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" > | |
<!ENTITY ssbont "http://localhost/ssbont.owl#" > | |
<!ENTITY dbpedia "http://dbpedia.org/resource/"> | |
]> | |
<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:dc="http://purl.org/dc/elements/1.1/" | |
> | |
<xsl:output method="xml" indent="yes" encoding="UTF-8"/> | |
<xsl:template match="/"> | |
<rdf:RDF xmlns="http://localhost/ssbont.owl#" | |
xml:base="http://localhost/ssbont.owl" | |
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" | |
xmlns:ssbont="http://localhost/ssbont.owl#" | |
xmlns:owl="http://www.w3.org/2002/07/owl#" | |
xmlns:xsd="http://www.w3.org/2001/XMLSchema#" | |
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/"> | |
<owl:Ontology | |
rdf:about="http://localhost/ssbont.owl"/> | |
<!-- | |
/////////////////////////////////////////////////////////////////////////////////////// | |
// | |
// Object Properties | |
// | |
/////////////////////////////////////////////////////////////////////////////////////// | |
--> | |
<xsl:for-each | |
select="//array/axis[name/textlang!='time']/name/textlang"> | |
<owl:ObjectProperty rdf:about="&ssbont;in_{translate(., ' ', '_')}"> | |
<rdfs:range rdf:resource="&ssbont;observation"/> | |
<rdfs:domain rdf:resource="&ssbont;{translate(., ' ', '_')}"/> | |
</owl:ObjectProperty> | |
</xsl:for-each> | |
<!-- | |
/////////////////////////////////////////////////////////////////////////////////////// | |
// | |
// Classes | |
// | |
/////////////////////////////////////////////////////////////////////////////////////// | |
--> | |
<xsl:for-each select="//axis/name/textlang[.!=time]"> | |
<owl:Class rdf:about="&ssbont;{translate(., ' ', '_')}"> | |
<rdfs:subClassOf rdf:resource="&owl;Thing"/> | |
</owl:Class> | |
</xsl:for-each> | |
<owl:Class rdf:about="&ssbont;observation"> | |
<rdfs:subClassOf rdf:resource="&owl;Thing"/> | |
</owl:Class> | |
<!-- | |
/////////////////////////////////////////////////////////////////////////////////////// | |
// | |
// Individuals | |
// | |
/////////////////////////////////////////////////////////////////////////////////////// | |
--> | |
<xsl:for-each select="//array/axis[name/textlang!='time']/value"> | |
<owl:NamedIndividual rdf:about="&ssbont;{translate(./textlang, ' ', | |
'_')}"> | |
<rdf:type rdf:resource="&ssbont;{translate(../name/textlang, | |
' ', '_')}"/> | |
<xsl:if test="translate(../name/textlang, | |
' ', '_')='region' and | |
./textlang!='County not stated'"> | |
<owl:sameAs> | |
<xsl:attribute name="resource" namespace="&rdf;"> | |
<xsl:choose> | |
<xsl:when test="./textlang='The whole country' or | |
./textlang='All counties'"> | |
<xsl:value-of select="'&dbpedia;Norway'"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="concat('&dbpedia;', translate(./textlang, ' ', | |
'_'))"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:attribute> | |
</owl:sameAs> | |
</xsl:if> | |
<dc:title> | |
<xsl:value-of select="./textlang"/> | |
</dc:title> | |
</owl:NamedIndividual> | |
</xsl:for-each> | |
<xsl:for-each select="//data/cell[.!='..']"> | |
<owl:AnonymousIndividual> | |
<rdf:type rdf:resource="&ssbont;observation"/> | |
<xsl:call-template name="recur"> | |
<xsl:with-param name="axis" select="current()/@cellIdRefs"/> | |
</xsl:call-template> | |
<rdf:value rdf:datatype="&xsd;long"> | |
<xsl:value-of select="."/> | |
</rdf:value> | |
</owl:AnonymousIndividual> | |
</xsl:for-each> | |
</rdf:RDF> | |
</xsl:template> | |
<xsl:template name="recur"> | |
<xsl:param name="axis" select="cell/@cellIdRefs"/> | |
<xsl:choose> | |
<xsl:when test="substring-before($axis, ' ')"> | |
<xsl:call-template name="do-transform"> | |
<xsl:with-param name="string" select="substring-before($axis, ' ')"/> | |
</xsl:call-template> | |
<xsl:call-template name="recur"> | |
<xsl:with-param name="axis" select="substring-after($axis, ' ')"/> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:call-template name="do-transform"> | |
<xsl:with-param name="string" select="$axis"/> | |
</xsl:call-template> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
<xsl:template name="do-transform"> | |
<xsl:param name="string" select="''"/> | |
<xsl:variable name="var" select="//axis/value[@valueId=$string]"/> | |
<xsl:choose> | |
<xsl:when test="$var/../name/textlang!='time'"> | |
<xsl:element | |
name="in_{translate($var/../name/textlang, ' ', '_')}" namespace="&ssbont;"> | |
<xsl:attribute name="resource" namespace='&rdf;'> | |
<xsl:value-of select="concat('&ssbont;', translate($var/textlang, ' ', | |
'_'))"/> | |
</xsl:attribute> | |
</xsl:element> | |
</xsl:when> | |
<xsl:otherwise> | |
<dc:date> | |
<xsl:value-of select="translate($var/textlang, ' ', '_')"/> | |
</dc:date> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment