Difference between revisions of "MediaWiki:SMWToRDF.xsl"

From TDWG Terms Wiki
Jump to: navigation, search
m (some refactoring (make the RDF at least resolve the SKOS terms))
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
 
  
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"  
+
  xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:swivt="http://semantic-mediawiki.org/swivt/1.0#"
+
  xmlns:swivt="http://semantic-mediawiki.org/swivt/1.0#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
+
  xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:property="http://terms.gbif.org/wiki/Special:URIResolver/Property-3A"
+
  xmlns:property="http://terms.gbif.org/wiki/Special:URIResolver/Property-3A"
version="1.0">
+
  version="1.0">
  
 +
  <xsl:output indent="yes" />
  
<xsl:output indent="yes" />
+
  <xsl:variable name="terms" select=" rdf:RDF/swivt:Subject" />
  
<xsl:variable name="terms" select=" rdf:RDF/swivt:Subject" />
+
  <xsl:template match="/">
 
+
    <rdf:RDF xmlns:vs="http://www.w3.org/2003/06/sw-vocab-status/ns#"
 
+
    xmlns:vann="http://purl.org/vocab/vann/"
 
+
    xmlns:dcterms="http://purl.org/dc/terms/"
<xsl:template match="/">
+
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
<rdf:RDF xmlns:vs="http://www.w3.org/2003/06/sw-vocab-status/ns#"
+
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:vann="http://purl.org/vocab/vann/"  
+
    xml:base="http://rs.tdwg.org/dwc/terms/"
xmlns:dcterms="http://purl.org/dc/terms/"  
+
    xmlns:dwcattributes="http://rs.tdwg.org/dwc/terms/attributes/">
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"  
+
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"  
+
xml:base="http://rs.tdwg.org/dwc/terms/"
+
xmlns:dwcattributes="http://rs.tdwg.org/dwc/terms/attributes/">
+
  
 
<!--
 
<!--
+
 
 
   Each RDF description uses the following:
 
   Each RDF description uses the following:
 
     rdfs:label
 
     rdfs:label
Line 37: Line 32:
 
     dcterms:modified
 
     dcterms:modified
 
     rdf:type
 
     rdf:type
 
+
 
   
+
 
+
 
-->
 
-->
 
<!--  Mutable RDF goes here  -->
 
<!--  Mutable RDF goes here  -->
Line 45: Line 38:
 
<!-- the first $term element describes the ConceptScheme-->
 
<!-- the first $term element describes the ConceptScheme-->
  
<rdf:Description>
+
            <rdf:Description>
<xsl:attribute name="rdf:value">
+
              <xsl:attribute name="rdf:value"><xsl:value-of select="$terms[1]/dc:identifier/@rdf:resource" /></xsl:attribute>
<xsl:value-of select="$terms[1]/dc:identifier/@rdf:resource" /></xsl:attribute>
+
            </rdf:Description>
</rdf:Description>
+
 
+
            <dcterms:title>
<dcterms:title>
+
              <xsl:attribute name="xml:lang"><xsl:text>en</xsl:text></xsl:attribute>
<xsl:attribute name="xml:lang">
+
            <xsl:value-of select="$terms[1]/rdfs:label"/>
<xsl:text>en</xsl:text></xsl:attribute>
+
            </dcterms:title>
<xsl:value-of select="$terms[1]/rdfs:label"/>
+
            <xsl:if test="boolean($terms[1]/dcterms:description)">
</dcterms:title>
+
              <dcterms:description><xsl:value-of select="$terms[1]/dcterms:description" /></dcterms:description>
+
            </xsl:if>
<dcterms:description>
+
            <xsl:if test="boolean($terms[1]/dc:description)">
<xsl:value-of select="$terms[1]/dcterms:description" />
+
              <dc:description><xsl:value-of select="$terms[1]/dc:description" /></dc:description>
</dcterms:description>
+
            </xsl:if>
+
 
<dc:publisher>
+
            <dc:publisher><xsl:value-of select="$terms[1]/dc:publisher" /></dc:publisher>
<xsl:value-of select="$terms[1]/dc:publisher" />
+
 
</dc:publisher>
+
            <dcterms:bibliographicCitation><xsl:value-of select="$terms[1]/dcterms:bibliographicCitation" /></dcterms:bibliographicCitation>
+
 
<dcterms:bibliographicCitation>
+
            <xsl:for-each select="$terms[1]/dcterms:contributor">
<xsl:value-of select="$terms[1]/dcterms:bibliographicCitation" />
+
            <dcterms:contributor><xsl:value-of select="."/></dcterms:contributor>
</dcterms:bibliographicCitation>
+
            </xsl:for-each>
+
 
+
            <xsl:for-each select="$terms[1]/dc:contributor">
<xsl:for-each select="$terms[1]/dcterms:contributor">
+
            <dc:contributor><xsl:value-of select="."/></dc:contributor>
<dcterms:contributor>
+
            </xsl:for-each>
<xsl:value-of select="."/>
+
 
</dcterms:contributor>
+
            <xsl:for-each select="$terms[1]/dcterms:creator">
</xsl:for-each>
+
            <dcterms:creator><xsl:value-of select="."/></dcterms:creator>
+
            </xsl:for-each>
 +
 
 +
            <xsl:for-each select="$terms[1]/dc:creator">
 +
            <dc:creator><xsl:value-of select="."/></dc:creator>
 +
            </xsl:for-each>
 +
 
 
<!-- the remaining $term elements describe individual Concepts in the ConceptScheme -->
 
<!-- the remaining $term elements describe individual Concepts in the ConceptScheme -->
  
<xsl:for-each select="$terms[position() != 1]">
+
      <xsl:for-each select="$terms[position() != 1]">
 +
 
 +
 
 +
            <rdf:Description>
 +
              <xsl:attribute name="rdf:value">
 +
            <xsl:value-of select="@rdf:about" /></xsl:attribute>
 +
 
 +
 
 +
          <!-- ?there is no equivalent in rdf for skos:altLabel -->
 +
          <xsl:for-each select="skos:altLabel">
 +
            <xsl:variable name="thisContent"><xsl:value-of select="."/></xsl:variable>
 +
            <xsl:variable name="thisContentStrippedIsoLanguage"><xsl:value-of select="substring-after($thisContent,':')"/></xsl:variable>
 +
            <xsl:variable name="isoLanguage"><xsl:value-of select="substring-before($thisContent,':')"/></xsl:variable>
 +
            <skos:altLabel>
 +
              <xsl:attribute name="xml:lang"> <xsl:value-of select="$isoLanguage" /> </xsl:attribute>
 +
              <xsl:value-of select="$thisContentStrippedIsoLanguage" />
 +
            </skos:altLabel>
 +
          </xsl:for-each>
 +
 
 +
            <xsl:for-each select="skos:prefLabel">
 +
              <xsl:variable name="thisContent"><xsl:value-of select="."/></xsl:variable>
 +
              <xsl:variable name="thisContentStrippedIsoLanguage"><xsl:value-of select="substring-after($thisContent,':')"/></xsl:variable>
 +
              <xsl:variable name="isoLanguage"><xsl:value-of select="substring-before($thisContent,':')"/></xsl:variable>
 +
              <!--<xsl:if test="$isoLanguage ='en'">-->
 +
            <rdfs:label>
 +
              <xsl:attribute name="xml:lang"> <xsl:value-of select="$isoLanguage" /></xsl:attribute>
 +
              <xsl:value-of select="$thisContentStrippedIsoLanguage" />
 +
            </rdfs:label>
 +
              <!--</xsl:if>-->
 +
            </xsl:for-each>
 +
 
 +
            <xsl:for-each select="skos:definition">
 +
              <xsl:variable name="thisContent"><xsl:value-of select="."/></xsl:variable>
 +
              <xsl:variable name="thisContentStrippedIsoLanguage"><xsl:value-of select="substring-after($thisContent,':')"/></xsl:variable>
 +
              <xsl:variable name="isoLanguage"><xsl:value-of select="substring-before($thisContent,':')"/></xsl:variable>
 +
              <!--<xsl:if test="$isoLanguage ='en'">-->
 +
            <rdfs:comment>
 +
              <xsl:attribute name="xml:lang"> <xsl:value-of select="$isoLanguage" /></xsl:attribute>
 +
              <xsl:value-of select="$thisContentStrippedIsoLanguage" />
 +
            </rdfs:comment>
 +
            <!--</xsl:if>-->
 +
            </xsl:for-each>
  
 +
            <!--  dcterms:description is not needed for concepts - use rdfs:comment instead
 +
            <xsl:for-each select="skos:definition">
 +
              <xsl:variable name="thisContent"><xsl:value-of select="."/></xsl:variable>
 +
              <xsl:variable name="thisContentStrippedIsoLanguage"><xsl:value-of select="substring-after($thisContent,':')"/></xsl:variable>
 +
              <xsl:variable name="isoLanguage"><xsl:value-of select="substring-before($thisContent,':')"/></xsl:variable>
 +
              <xsl:if test="$isoLanguage ='en'">
 +
                <dcterms:description> <xsl:attribute name="xml:lang"> <xsl:value-of select="$isoLanguage" /></xsl:attribute>
 +
                <xsl:value-of select="$thisContentStrippedIsoLanguage" />
 +
                </dcterms:description>
 +
              </xsl:if>
 +
            </xsl:for-each>
 +
            -->
  
<rdf:Description>
+
            <rdfs:isDefinedBy>
<xsl:attribute name="rdf:value">
+
              <xsl:attribute name="rdf:resource">
<xsl:value-of select="@rdf:about" /></xsl:attribute>
+
              <xsl:choose>
+
                <xsl:when test="string-length(rdfs:isDefinedBy[2]/@rdf:resource) != 0"><xsl:value-of select="rdfs:isDefinedBy[2]/@rdf:resource" /></xsl:when>
+
                <xsl:otherwise><xsl:value-of select="rdfs:isDefinedBy/@rdf:resource" /></xsl:otherwise>
<xsl:for-each select="skos:prefLabel">
+
              </xsl:choose>
<xsl:variable name="langLabel"><xsl:value-of select="."/></xsl:variable>  
+
              </xsl:attribute>
<xsl:variable name="cleanLabel"><xsl:value-of select="substring-after($langLabel,':')"/></xsl:variable>
+
            </rdfs:isDefinedBy>
<xsl:variable name="language"><xsl:value-of select="substring-before($langLabel,':')"/></xsl:variable>
+
        <xsl:if test="dcterms:issued != ''">
<xsl:if test="$language ='en'">
+
            <dcterms:issued> <xsl:value-of select="dcterms:issued" /> </dcterms:issued>
<rdfs:label>
+
        </xsl:if>
<xsl:attribute name="xml:lang">
+
        <xsl:if test="dcterms:modified != ''">
<xsl:value-of select="$language" /></xsl:attribute>
+
            <dcterms:modified> <xsl:value-of select="dcterms:modified" /> </dcterms:modified>
<xsl:value-of select="$cleanLabel" />
+
        </xsl:if>
</rdfs:label>
+
        <xsl:for-each select="swivt:type/@rdf:resource">
</xsl:if>
+
            <rdf:type>
</xsl:for-each>
+
              <!--<xsl:attribute name="rdf:resource">
+
                <xsl:value-of select="property:concept_type/@rdf:resource" /> -->
<xsl:for-each select="skos:definition">
+
              <xsl:value-of select="./." /> <!--</xsl:attribute> -->
<xsl:variable name="langDefinition"><xsl:value-of select="."/></xsl:variable>  
+
            </rdf:type>
<xsl:variable name="cleanDefinition"><xsl:value-of select="substring-after($langDefinition,':')"/></xsl:variable>
+
        </xsl:for-each>
<xsl:variable name="language"><xsl:value-of select="substring-before($langDefinition,':')"/></xsl:variable>
+
        <!--
<xsl:if test="$language ='en'">
+
            <dcterms:hasVersion>
<rdfs:comment>
+
              <xsl:attribute name="rdf:resource">
<xsl:attribute name="xml:lang">
+
                <xsl:value-of select="ZZZ" /></xsl:attribute>
<xsl:value-of select="$language" /></xsl:attribute>
+
            </dcterms:hasVersion>
<xsl:value-of select="$cleanDefinition" />
+
</rdfs:comment>
+
</xsl:if>
+
</xsl:for-each>
+
  
+
            <dcterms:replaces>
+
              <xsl:attribute name="rdf:resource">
<!--  dcterms:description is not needed for concepts - use rdfs:comment instead
+
                <xsl:value-of select="ZZZ" /></xsl:attribute>
<xsl:for-each select="skos:definition">
+
            </dcterms:replaces>
<xsl:variable name="langExample"><xsl:value-of select="."/></xsl:variable>  
+
        -->
<xsl:variable name="cleanExample"><xsl:value-of select="substring-after($langExample,':')"/></xsl:variable>
+
        <xsl:for-each select="vs:term_status" >
<xsl:variable name="language"><xsl:value-of select="substring-before($langExample,':')"/></xsl:variable>
+
          <vs:term_status><xsl:value-of select="vs:term_status"/></vs:term_status>
<xsl:if test="$language ='en'">
+
        </xsl:for-each>
<dcterms:description>
+
            <!-- AP (2019-12-17 14:13:56) is there a rdf equivalent?
<xsl:attribute name="xml:lang">
+
            <skos:closeMatch><xsl:value-of select="skos:closeMatch/@rdf:resource" /></skos:closeMatch>
<xsl:value-of select="$language" /></xsl:attribute>
+
            -->
<xsl:value-of select="$cleanExample" />
+
</dcterms:description>
+
</xsl:if>
+
</xsl:for-each>
+
-->
+
+
<rdfs:isDefinedBy>
+
<xsl:attribute name="rdf:resource">
+
<xsl:value-of select="rdfs:isDefinedBy[2]/@rdf:resource" /></xsl:attribute>
+
</rdfs:isDefinedBy>
+
+
<dcterms:issued>
+
<xsl:value-of select="dcterms:issued" />
+
</dcterms:issued>
+
<dcterms:modified>
+
<xsl:value-of select="dcterms:modified" />
+
</dcterms:modified>
+
+
<rdf:type>
+
<xsl:attribute name="rdf:resource">
+
<xsl:value-of select="property:concept_type/@rdf:resource" /></xsl:attribute>
+
</rdf:type>
+
<!--
+
<dcterms:hasVersion>
+
<xsl:attribute name="rdf:resource">
+
<xsl:value-of select="ZZZ" /></xsl:attribute>
+
</dcterms:hasVersion>
+
+
<dcterms:replaces>
+
<xsl:attribute name="rdf:resource">
+
<xsl:value-of select="ZZZ" /></xsl:attribute>
+
</dcterms:replaces>
+
-->
+
+
<vs:term_status>
+
          <xsl:value-of select="vs:term_status"/>
+
      </vs:term_status>
+
  
+
        <!--   
<skos:closeMatch>
+
        vann:termGroup replaces dwc:organizedInClass
<xsl:value-of select="skos:closeMatch/@rdf:resource" />
+
            <vann:termGroup>
</skos:closeMatch>
+
              <xsl:attribute name="rdf:resource">
+
                <xsl:value-of select="ZZZ" /></xsl:attribute>
+
            </vann:termGroup>
<!--  vann:termGroup replaces dwc:organizedInClass
+
        -->
<vann:termGroup>
+
<xsl:attribute name="rdf:resource">
+
<xsl:value-of select="ZZZ" /></xsl:attribute>
+
</vann:termGroup>
+
-->
+
+
</rdf:Description>
+
  
+
            </rdf:Description>
</xsl:for-each>
+
      </xsl:for-each>
</rdf:RDF>
+
    </rdf:RDF>
</xsl:template>
+
  </xsl:template>
  
 
</xsl:stylesheet>
 
</xsl:stylesheet>

Latest revision as of 15:15, 17 December 2019

<?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#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:property="http://terms.gbif.org/wiki/Special:URIResolver/Property-3A"
 version="1.0">
 <xsl:output indent="yes" />
 <xsl:variable name="terms" select=" rdf:RDF/swivt:Subject" />
 <xsl:template match="/">
   <rdf:RDF xmlns:vs="http://www.w3.org/2003/06/sw-vocab-status/ns#"
   xmlns:vann="http://purl.org/vocab/vann/"
   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#"
   xml:base="http://rs.tdwg.org/dwc/terms/"
   xmlns:dwcattributes="http://rs.tdwg.org/dwc/terms/attributes/">


           <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>
           <xsl:if test="boolean($terms[1]/dcterms:description)">
             <dcterms:description><xsl:value-of select="$terms[1]/dcterms:description" /></dcterms:description>
           </xsl:if>
           <xsl:if test="boolean($terms[1]/dc:description)">
             <dc:description><xsl:value-of select="$terms[1]/dc:description" /></dc:description>
           </xsl:if>
           <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[1]/dc:contributor">
           <dc:contributor><xsl:value-of select="."/></dc:contributor>
           </xsl:for-each>
           <xsl:for-each select="$terms[1]/dcterms:creator">
           <dcterms:creator><xsl:value-of select="."/></dcterms:creator>
           </xsl:for-each>
           <xsl:for-each select="$terms[1]/dc:creator">
           <dc:creator><xsl:value-of select="."/></dc:creator>
           </xsl:for-each>


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


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


         <xsl:for-each select="skos:altLabel">
           <xsl:variable name="thisContent"><xsl:value-of select="."/></xsl:variable>
           <xsl:variable name="thisContentStrippedIsoLanguage"><xsl:value-of select="substring-after($thisContent,':')"/></xsl:variable>
           <xsl:variable name="isoLanguage"><xsl:value-of select="substring-before($thisContent,':')"/></xsl:variable>
           <skos:altLabel>
             <xsl:attribute name="xml:lang"> <xsl:value-of select="$isoLanguage" /> </xsl:attribute>
             <xsl:value-of select="$thisContentStrippedIsoLanguage" />
           </skos:altLabel>
         </xsl:for-each>
           <xsl:for-each select="skos:prefLabel">
             <xsl:variable name="thisContent"><xsl:value-of select="."/></xsl:variable>
             <xsl:variable name="thisContentStrippedIsoLanguage"><xsl:value-of select="substring-after($thisContent,':')"/></xsl:variable>
             <xsl:variable name="isoLanguage"><xsl:value-of select="substring-before($thisContent,':')"/></xsl:variable>
           <rdfs:label>
             <xsl:attribute name="xml:lang"> <xsl:value-of select="$isoLanguage" /></xsl:attribute>
             <xsl:value-of select="$thisContentStrippedIsoLanguage" />
           </rdfs:label>
           </xsl:for-each>
           <xsl:for-each select="skos:definition">
             <xsl:variable name="thisContent"><xsl:value-of select="."/></xsl:variable>
             <xsl:variable name="thisContentStrippedIsoLanguage"><xsl:value-of select="substring-after($thisContent,':')"/></xsl:variable>
             <xsl:variable name="isoLanguage"><xsl:value-of select="substring-before($thisContent,':')"/></xsl:variable>
           <rdfs:comment>
             <xsl:attribute name="xml:lang"> <xsl:value-of select="$isoLanguage" /></xsl:attribute>
             <xsl:value-of select="$thisContentStrippedIsoLanguage" />
           </rdfs:comment>
           </xsl:for-each>


           <rdfs:isDefinedBy>
             <xsl:attribute name="rdf:resource">
             <xsl:choose>
               <xsl:when test="string-length(rdfs:isDefinedBy[2]/@rdf:resource) != 0"><xsl:value-of select="rdfs:isDefinedBy[2]/@rdf:resource" /></xsl:when>
               <xsl:otherwise><xsl:value-of select="rdfs:isDefinedBy/@rdf:resource" /></xsl:otherwise>
             </xsl:choose>
             </xsl:attribute>
           </rdfs:isDefinedBy>
       <xsl:if test="dcterms:issued != ">
           <dcterms:issued> <xsl:value-of select="dcterms:issued" /> </dcterms:issued>
       </xsl:if>
       <xsl:if test="dcterms:modified != ">
           <dcterms:modified> <xsl:value-of select="dcterms:modified" /> </dcterms:modified>
       </xsl:if>
       <xsl:for-each select="swivt:type/@rdf:resource">
           <rdf:type>
             <xsl:value-of select="./." /> 
           </rdf:type>
       </xsl:for-each>
       <xsl:for-each select="vs:term_status" >
         <vs:term_status><xsl:value-of select="vs:term_status"/></vs:term_status>
       </xsl:for-each>


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

</xsl:stylesheet>