View stylesheet

XML schema http://biodiversity.eionet.europa.eu/schemas/dir9243eec/habitats.xsd
Output type RDF
Description RDF output
XSL file art17-habitats-rdf.xsl (Last modified: 16 Nov 2018 17:19 )
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
 <!ENTITY biogeo "http://dd.eionet.europa.eu/vocabulary/art17_2012/biogeoreg/">
 <!ENTITY countries "http://dd.eionet.europa.eu/vocabulary/art17_2006/countries/">
]>

<!-- $Id: art17-habitats-rdf.xsl 17149 2014-11-18 14:52:33Z roug $ -->

<xsl:stylesheet version="1.0"
  xmlns="http://rdfdata.eionet.europa.eu/article17/ontology/"
  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#"
  xmlns:l="http://biodiversity.eionet.europa.eu/art17dataflow"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="habitat">
    <rdf:RDF>
      <xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>

      <HabitatTypeReport rdf:about="">
        <rdfs:label>Habitats directive art. 17 report for habitat type <xsl:value-of select="habitatcode"/> in <xsl:value-of select="member-state"/></rdfs:label>
        <xsl:call-template name="get-eunis-habitats-code">
          <xsl:with-param name="text" select="normalize-space(habitatcode)" />
        </xsl:call-template>
        <memberstate><xsl:value-of select="member-state"/></memberstate>
        <forCountry><xsl:attribute name="rdf:resource">&countries;<xsl:value-of select="normalize-space(member-state/@countrycode)"/></xsl:attribute></forCountry>
        <xsl:for-each select="regional/region">
          <hasRegionalReport><xsl:attribute name="rdf:resource">#<xsl:value-of select="normalize-space(.)"/></xsl:attribute></hasRegionalReport>
        </xsl:for-each>
      </HabitatTypeReport>
      <xsl:apply-templates/>
    </rdf:RDF>
  </xsl:template>

  <xsl:template match="regional">
    <HabitatTypeRegionalReport>
     <xsl:attribute name="rdf:ID"><xsl:value-of select="normalize-space(region)"/></xsl:attribute>
     <rdfs:label>Report on habitat type <xsl:value-of select="/habitat/habitatcode"/> for <xsl:value-of select="region"/> biogeographical region in <xsl:value-of select="/habitat/member-state"/></rdfs:label>
     <memberstate><xsl:value-of select="/habitat/member-state"/></memberstate>
     <forCountry><xsl:attribute name="rdf:resource">&countries;<xsl:value-of select="normalize-space(/habitat/member-state/@countrycode)"/></xsl:attribute></forCountry>
     <habitatcode><xsl:value-of select="/habitat/habitatcode"/></habitatcode>
     <region><xsl:attribute name="rdf:resource">&biogeo;<xsl:value-of select="normalize-space(region)"/></xsl:attribute></region>
     <xsl:call-template name="break-at-newlines">
      <xsl:with-param name="text" select="published"/>
      <xsl:with-param name="predicate" select="'published'"/>
     </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="range/surface-area"/>
        <xsl:with-param name="predicate" select="'range_surface_area'"/>
    </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="range/date"/>
        <xsl:with-param name="predicate" select="'range_date'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-quality">
      <xsl:with-param name="text" select="range/quality"/>
      <xsl:with-param name="predicate" select="'range_quality'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-trend">
      <xsl:with-param name="text" select="range/trend"/>
      <xsl:with-param name="predicate" select="'range_trend'"/>
    </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="range/trend-magnitude"/>
        <xsl:with-param name="predicate" select="'range_trend_magnitude'"/>
    </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="range/trend-period"/>
        <xsl:with-param name="predicate" select="'range_trend_period'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-multiple">
            <xsl:with-param name="text" select="range/reasons"/>
            <xsl:with-param name="predicate" select="'range_reasons'"/>
            <xsl:with-param name="table" select="'reasons'"/>
    </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="range/reasons-specify"/>
        <xsl:with-param name="predicate" select="'range_reasons'"/>
    </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="coverage/surface-area"/>
        <xsl:with-param name="predicate" select="'coverage_surface_area'"/>
    </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="coverage/date"/>
        <xsl:with-param name="predicate" select="'coverage_date'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-multiple">
            <xsl:with-param name="text" select="coverage/method"/>
            <xsl:with-param name="predicate" select="'coverage_methods'"/>
            <xsl:with-param name="table" select="'methods'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-quality">
      <xsl:with-param name="text" select="coverage/quality"/>
      <xsl:with-param name="predicate" select="'coverage_quality'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-trend">
      <xsl:with-param name="text" select="coverage/trend"/>
      <xsl:with-param name="predicate" select="'coverage_trend'"/>
    </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="coverage/trend-magnitude"/>
        <xsl:with-param name="predicate" select="'coverage_trend_magnitude'"/>
    </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="coverage/trend-period"/>
        <xsl:with-param name="predicate" select="'coverage_trend_period'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-multiple">
            <xsl:with-param name="text" select="coverage/reasons"/>
            <xsl:with-param name="predicate" select="'coverage_reasons'"/>
            <xsl:with-param name="table" select="'reasons'"/>
    </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="coverage/reasons-specify"/>
        <xsl:with-param name="predicate" select="'coverage_reasons'"/>
    </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="coverage/justification"/>
        <xsl:with-param name="predicate" select="'coverage_justification'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-multiple">
            <xsl:with-param name="text" select="coverage/pressures"/>
            <xsl:with-param name="predicate" select="'coverage_pressures'"/>
            <xsl:with-param name="table" select="'activities'"/>
    </xsl:call-template>
    <xsl:call-template name="fill-multiple">
            <xsl:with-param name="text" select="coverage/threats"/>
            <xsl:with-param name="predicate" select="'coverage_threats'"/>
            <xsl:with-param name="table" select="'activities'"/>
    </xsl:call-template>

    <xsl:apply-templates select="complementary/favourable-range"/>
    <xsl:apply-templates select="complementary/favourable-area"/>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="complementary/species-assessment"/>
        <xsl:with-param name="predicate" select="'complementary_species_assessment'"/>
    </xsl:call-template>

    <xsl:call-template name="one-literal-predicate">
        <xsl:with-param name="text" select="complementary/other-information"/>
        <xsl:with-param name="predicate" select="'complementary_other_information'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-assessment">
      <xsl:with-param name="text" select="conclusion/conclusion-range"/>
      <xsl:with-param name="predicate" select="'conclusion_range'"/>
      <xsl:with-param name="table" select="'conclusions'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-assessment">
      <xsl:with-param name="text" select="conclusion/conclusion-area"/>
      <xsl:with-param name="predicate" select="'conclusion_area'"/>
      <xsl:with-param name="table" select="'conclusions'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-assessment">
      <xsl:with-param name="text" select="conclusion/conclusion-structure"/>
      <xsl:with-param name="predicate" select="'conclusion_structure'"/>
      <xsl:with-param name="table" select="'conclusions'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-assessment">
      <xsl:with-param name="text" select="conclusion/conclusion-future"/>
      <xsl:with-param name="predicate" select="'conclusion_future'"/>
      <xsl:with-param name="table" select="'conclusions'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-assessment">
      <xsl:with-param name="text" select="conclusion/conclusion-assessment"/>
      <xsl:with-param name="predicate" select="'conclusion_assessment'"/>
      <xsl:with-param name="table" select="'conclusions'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-assessment">
      <xsl:with-param name="text" select="conclusion-n2000/conclusion-range"/>
      <xsl:with-param name="predicate" select="'conclusion_n2000_range'"/>
      <xsl:with-param name="table" select="'conclusions'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-assessment">
      <xsl:with-param name="text" select="conclusion-n2000/conclusion-area"/>
      <xsl:with-param name="predicate" select="'conclusion_n2000_area'"/>
      <xsl:with-param name="table" select="'conclusions'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-assessment">
      <xsl:with-param name="text" select="conclusion-n2000/conclusion-structure"/>
      <xsl:with-param name="predicate" select="'conclusion_n2000_structure'"/>
      <xsl:with-param name="table" select="'conclusions'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-assessment">
      <xsl:with-param name="text" select="conclusion-n2000/conclusion-future"/>
      <xsl:with-param name="predicate" select="'conclusion_n2000_future'"/>
      <xsl:with-param name="table" select="'conclusions'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-assessment">
      <xsl:with-param name="text" select="conclusion-n2000/conclusion-assessment"/>
      <xsl:with-param name="predicate" select="'conclusion_n2000_assessment'"/>
      <xsl:with-param name="table" select="'conclusions'"/>
    </xsl:call-template>

    <xsl:apply-templates select="complementary/typical-species"/>
    </HabitatTypeRegionalReport>
  </xsl:template>

  <xsl:template match="typical-species">
    <xsl:if test="normalize-space(speciesname)!=''">
      <HabitatTypeTypicalSpecies rdf:parseType="Resource">
        <xsl:call-template name="get-eunis-species-code">
            <xsl:with-param name="text" select="normalize-space(speciesname)" />
        </xsl:call-template>

        <xsl:if test="speciesauthor!=''"><speciesauthor xml:lang=""><xsl:value-of select="speciesauthor"/></speciesauthor></xsl:if>
      </HabitatTypeTypicalSpecies>
    </xsl:if>
  </xsl:template>

  <xsl:template name="fill-multiple">
    <xsl:param name="text"/>
    <xsl:param name="predicate"/>
    <xsl:param name="table"/>
    <xsl:choose>
      <xsl:when test="contains($text, ' ')">
        <xsl:call-template name="one-resource-predicate">
          <xsl:with-param name="text" select="substring-before($text, ' ')"/>
          <xsl:with-param name="predicate" select="$predicate"/>
          <xsl:with-param name="table" select="$table"/>
        </xsl:call-template>

        <xsl:text disable-output-escaping="yes"> </xsl:text>
        <xsl:call-template name="fill-multiple">
          <xsl:with-param name="text" select="substring-after($text, ' ')"/>
          <xsl:with-param name="predicate" select="$predicate"/>
          <xsl:with-param name="table" select="$table"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$text=''"/>
      <xsl:otherwise>
        <xsl:call-template name="one-resource-predicate">
          <xsl:with-param name="text" select="$text"/>
          <xsl:with-param name="predicate" select="$predicate"/>
          <xsl:with-param name="table" select="$table"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="favourable-range">
    <xsl:if test="string-length(@qualifier)!=0 or string-length(.)!=0">
      <complementary_favourable_range>
        <xsl:choose>
          <xsl:when test="string-length(@qualifier)!= 0">
             <xsl:value-of select="@qualifier"/><xsl:text> </xsl:text><xsl:value-of select="../../range/surface-area"/><xsl:text> km2</xsl:text>
          </xsl:when>
          <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
        </xsl:choose>
      </complementary_favourable_range>
    </xsl:if>
  </xsl:template>

  <xsl:template match="favourable-area">
    <xsl:if test="string-length(@qualifier)!=0 or string-length(.)!=0">
      <complementary_favourable_area>
        <xsl:choose>
          <xsl:when test="string-length(@qualifier)!= 0">
             <xsl:value-of select="@qualifier"/><xsl:text> </xsl:text><xsl:value-of select="../../coverage/surface-area"/><xsl:text> km2</xsl:text>
          </xsl:when>
          <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
        </xsl:choose>
      </complementary_favourable_area>
    </xsl:if>
  </xsl:template>


  <xsl:template name="fill-reasons">
    <xsl:param name="text" select="."/>
    <xsl:choose>
      <xsl:when test="$text = 'Unknown'">Unknown</xsl:when>
      <xsl:when test="$text = 'ImprovedKnowledge'">Improved knowledge/more accurate data</xsl:when>
      <xsl:when test="$text = 'ClimateChange'">Climate change</xsl:when>
      <xsl:when test="$text = 'DirectHuman'">Direct human influence (restoration, deterioration, destruction)</xsl:when>
      <xsl:when test="$text = 'IndirectHuman'">Indirect anthropo(zoo)genic influence</xsl:when>
      <xsl:when test="$text = 'NaturalProcesses'">Natural processes</xsl:when>
      <xsl:when test="$text = 'Other'">Other (specify)</xsl:when>
      <xsl:when test="$text = 'NotApplicable'">Not applicable</xsl:when>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="fill-method">
    <xsl:param name="text"/>
    <xsl:param name="predicate"/>
    <xsl:if test="string-length($text)!=0">
      <xsl:element name="{$predicate}">
        <xsl:choose>
          <xsl:when test="$text = 'GroundSurvey'">Ground based survey (based on field mapping, possibly using stratified random sampling</xsl:when>
          <xsl:when test="$text = 'RemoteSensing'">Based on remote sensing data (possibly including an element of ground truthing)</xsl:when>
          <xsl:when test="$text = 'ExpertOpinion'">Based on expert opinion</xsl:when>
        </xsl:choose>
      </xsl:element>
    </xsl:if>
  </xsl:template>

  <xsl:template name="fill-quality">
    <xsl:param name="text"/>
    <xsl:param name="predicate"/>
    <xsl:if test="string-length($text)!=0">
      <xsl:element name="{$predicate}">
        <xsl:choose>
          <xsl:when test="$text = 'Good'">Good e.g based on extensive surveys</xsl:when>
          <xsl:when test="$text = 'Moderate'">Moderate e.g. based on partial data with some extrapolation</xsl:when>
          <xsl:when test="$text = 'Poor'">Poor e.g. based on very incomplete data or on expert judgement</xsl:when>
        </xsl:choose>
      </xsl:element>
    </xsl:if>
  </xsl:template>

  <xsl:template name="fill-trend">
    <xsl:param name="text"/>
    <xsl:param name="predicate"/>
    <xsl:if test="string-length($text)!=0">
      <xsl:element name="{$predicate}">
        <xsl:choose>
          <xsl:when test="$text = '='">Stable (=)</xsl:when>
          <xsl:when test="$text = '+'">Increasing (+)</xsl:when>
          <xsl:when test="$text = '-'">Decreasing (-)</xsl:when>
          <xsl:when test="$text = 'X'">Unknown (X)</xsl:when>
        </xsl:choose>
      </xsl:element>
    </xsl:if>
  </xsl:template>

  <xsl:template name="fill-assessment">
    <xsl:param name="text"/>
    <xsl:param name="predicate"/>
    <xsl:param name="table"/>
    <xsl:if test="string-length($text)!=0">
      <xsl:element name="{$predicate}">
        <xsl:choose>
          <xsl:when test="$text = 'FV'">Favourable (FV)</xsl:when>
          <xsl:when test="$text = 'U1+'">Inadequate but improving (U1+)</xsl:when>
          <xsl:when test="$text = 'U1'">Inadequate (U1)</xsl:when>
          <xsl:when test="$text = 'U1-'">Inadequate and deteriorating (U1-)</xsl:when>
          <xsl:when test="$text = 'U2+'">Bad but improving (U2+)</xsl:when>
          <xsl:when test="$text = 'U2'">Bad (U2)</xsl:when>
          <xsl:when test="$text = 'U2-'">Bad and deteriorating (U2-)</xsl:when>
          <xsl:when test="$text = 'XX'">Unknown (XX)</xsl:when>
        </xsl:choose>
      </xsl:element>
    </xsl:if>
  </xsl:template>

  <xsl:template name="one-resource-predicate">
    <xsl:param name="text"/>
    <xsl:param name="predicate"/>
    <xsl:param name="table"/>
    <xsl:if test="string-length($text)!=0">
      <xsl:element name="{$predicate}">
        <xsl:attribute name="rdf:resource">http://dd.eionet.europa.eu/vocabulary/art17_2006/<xsl:value-of select="$table"/>/<xsl:value-of select="$text"/></xsl:attribute>
      </xsl:element>
    </xsl:if>
  </xsl:template>

  <xsl:template name="break-at-newlines">
    <xsl:param name="text"/>
    <xsl:param name="predicate"/>
    <xsl:choose>
            <xsl:when test="contains($text, '&#13;')">
                    <xsl:call-template name="one-literal-predicate">
                        <xsl:with-param name="text" select="substring-before($text, '&#13;')"/>
                        <xsl:with-param name="predicate" select="$predicate"/>
                    </xsl:call-template>
                    <xsl:call-template name="break-at-newlines">
                        <xsl:with-param name="text" select="substring-after($text, '&#13;')"/>
                        <xsl:with-param name="predicate" select="$predicate"/>
                    </xsl:call-template>
            </xsl:when>
            <xsl:when test="$text=''"/>
            <xsl:otherwise>
                <xsl:call-template name="one-literal-predicate">
                    <xsl:with-param name="text" select="$text"/>
                    <xsl:with-param name="predicate" select="$predicate"/>
                </xsl:call-template>
            </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="one-literal-predicate">
    <xsl:param name="text"/>
    <xsl:param name="predicate"/>
    <xsl:element name="{$predicate}">
      <xsl:value-of select="$text"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="text()"/>

  <xsl:template name="get-eunis-habitats-code">
    <xsl:param name="text" select="."/>
    <habitatcode><xsl:value-of select="$text"/></habitatcode>
    <xsl:if test="document('https://converters.eionet.europa.eu/xmlfile/map-eunis-habitats.xml')/l:n2000habitats/l:n2000[@code=$text] != ''">
      <forHabitat>
        <xsl:attribute name="rdf:resource">http://eunis.eea.europa.eu/habitats/<xsl:value-of select="document('https://converters.eionet.europa.eu/xmlfile/map-eunis-habitats.xml')/l:n2000habitats/l:n2000[@code=$text]"/></xsl:attribute>
      </forHabitat>
    </xsl:if>
  </xsl:template>

  <xsl:template name="get-eunis-species-code">
    <xsl:param name="text" select="."/>
    <speciesname xml:lang=""><xsl:value-of select="$text"/></speciesname>
    <xsl:if test="document('https://converters.eionet.europa.eu/xmlfile/map-eunis-species.xml')/l:eunis/l:species[@name=$text] != ''">
    <forSpecies>
    <xsl:attribute name="rdf:resource">http://eunis.eea.europa.eu/species/<xsl:value-of select="document('https://converters.eionet.europa.eu/xmlfile/map-eunis-species.xml')/l:eunis/l:species[@name=$text]"/></xsl:attribute>
    </forSpecies>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>