Difference between revisions of "MediaWiki:SMWToSKOS.xsl"

From TDWG Terms Wiki
Jump to: navigation, search
(added export for skos:exactMatch, skos:closeMatch, skos:broader and skos:narrower)
Line 127: Line 127:
 
</xsl:for-each>
 
</xsl:for-each>
 
 
 +
<xsl:copy-of select="skos:exactMatch" copy-namespaces="no"/>
 +
<xsl:copy-of select="skos:closeMatch" copy-namespaces="no"/>
 +
<xsl:copy-of select="skos:broader" copy-namespaces="no"/>
 +
<xsl:copy-of select="skos:narrower" copy-namespaces="no"/>
 
 
 
<skos:inScheme>
 
<skos:inScheme>

Revision as of 17:24, 21 January 2015

<?xml version="1.0" encoding="UTF-8"?>


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:swivt="http://semantic-mediawiki.org/swivt/1.0#" version="1.0">


<xsl:output indent="yes" />

<xsl:variable name="terms" select="rdf:RDF/swivt:Subject" />



<xsl:template match="/"> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/">


<rdf:Description> <xsl:attribute name="rdf:value"> <xsl:value-of select="$terms[1]/dc:identifier/@rdf:resource" /></xsl:attribute> </rdf:Description>

<dcterms:title> <xsl:attribute name="xml:lang"> <xsl:text>en</xsl:text></xsl:attribute> <xsl:value-of select="$terms[1]/rdfs:label"/> </dcterms:title>

<dcterms:description> <xsl:value-of select="$terms[1]/dcterms:description" /> </dcterms:description>

<dc:publisher> <xsl:value-of select="$terms[1]/dc:publisher" /> </dc:publisher>

<dcterms:bibliographicCitation> <xsl:value-of select="$terms[1]/dcterms:bibliographicCitation" /> </dcterms:bibliographicCitation>


<xsl:for-each select="$terms[1]/dcterms:contributor"> <dcterms:contributor> <xsl:value-of select="."/> </dcterms:contributor> </xsl:for-each>


<xsl:for-each select="$terms[position() != 1]">

    <xsl:variable name="nameSpace"><xsl:value-of select="@rdf:about"/></xsl:variable>
    <xsl:variable name="nameSpaceStripped"><xsl:value-of select="substring-before($nameSpace,'terms')" /></xsl:variable>
    
     

<skos:Concept> <xsl:attribute name="rdf:about"> <xsl:value-of select="@rdf:about" /></xsl:attribute>

<skos:historyNote> <xsl:attribute name="rdf:about"> <xsl:text>modified</xsl:text></xsl:attribute> <xsl:attribute name="dc:date"> <xsl:value-of select="dcterms:modified"/></xsl:attribute> </skos:historyNote>

<xsl:for-each select="skos:prefLabel"> <xsl:variable name="langLabel"><xsl:value-of select="."/></xsl:variable> <xsl:variable name="cleanLabel"><xsl:value-of select="substring-after($langLabel,':')"/></xsl:variable> <xsl:variable name="language"><xsl:value-of select="substring-before($langLabel,':')"/></xsl:variable> <skos:prefLabel> <xsl:attribute name="xml:lang"> <xsl:value-of select="$language" /></xsl:attribute> <xsl:value-of select="$cleanLabel" /> </skos:prefLabel> </xsl:for-each>

<xsl:for-each select="skos:definition"> <xsl:variable name="langDefinition"><xsl:value-of select="."/></xsl:variable> <xsl:variable name="cleanDefinition"><xsl:value-of select="substring-after($langDefinition,':')"/></xsl:variable> <xsl:variable name="language"><xsl:value-of select="substring-before($langDefinition,':')"/></xsl:variable> <skos:definition> <xsl:attribute name="xml:lang"> <xsl:value-of select="$language" /></xsl:attribute> <xsl:value-of select="$cleanDefinition" /> </skos:definition> </xsl:for-each>

<xsl:for-each select="skos:broader">

  <xsl:variable name="nameBroader" select="@rdf:resource" />
       <xsl:variable name="shortNameBroader"><xsl:value-of select="substring-after($nameBroader,':')" /></xsl:variable>						

<skos:broader> <xsl:attribute name="rdf:resource"> <xsl:value-of select="concat($nameSpaceStripped,'terms/',$shortNameBroader)"/></xsl:attribute> </skos:broader> </xsl:for-each>

<xsl:for-each select="skos:narrower">

 <xsl:variable name="nameNarrower" select="@rdf:resource" />
       <xsl:variable name="shortNameNarrower"><xsl:value-of select="substring-after($nameNarrower,':')" /></xsl:variable>						

<skos:narrower> <xsl:attribute name="rdf:resource"> <xsl:value-of select="concat($nameSpaceStripped,'terms/',$shortNameNarrower)"/></xsl:attribute> </skos:narrower> </xsl:for-each>


<xsl:for-each select="skos:example"> <xsl:variable name="langExample"><xsl:value-of select="."/></xsl:variable> <xsl:variable name="cleanExample"><xsl:value-of select="substring-after($langExample,':')"/></xsl:variable> <xsl:variable name="language"><xsl:value-of select="substring-before($langExample,':')"/></xsl:variable> <skos:example> <xsl:attribute name="xml:lang"> <xsl:value-of select="$language" /></xsl:attribute> <xsl:value-of select="$cleanExample" /> </skos:example> </xsl:for-each>

<xsl:copy-of select="skos:exactMatch" copy-namespaces="no"/> <xsl:copy-of select="skos:closeMatch" copy-namespaces="no"/> <xsl:copy-of select="skos:broader" copy-namespaces="no"/> <xsl:copy-of select="skos:narrower" copy-namespaces="no"/>

<skos:inScheme> <xsl:attribute name="rdf:resource"><xsl:text>URL for published SKOS file</xsl:text></xsl:attribute> </skos:inScheme> <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property" />

</skos:Concept>


</xsl:for-each> </rdf:RDF> </xsl:template>

</xsl:stylesheet>