View stylesheet

XML schemas http://biodiversity.eionet.europa.eu/schemas/dir9243eec/species.xsd
Output type RDF
Description RDF
XSL file art17-species-rdf.xsl (Last modified: 18 Nov 2014 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/">
 ]>

<!--
     The deliveries use UK for United Kingdom and GR for Greece
     $Id: art17-species-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="species">
 <rdf:RDF>
   <xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
   <SpeciesReport rdf:about="">
    <rdfs:label>Habitat Directive Art. 17 report on <xsl:value-of select="speciesname"/> in <xsl:value-of select="/species/member-state"/></rdfs:label>
    <xsl:if test="string-length(speciesname)!=0">
        <xsl:call-template name="get-eunis-species-code">
            <xsl:with-param name="text" select="normalize-space(speciesname)" />
        </xsl:call-template>
    </xsl:if>

    <xsl:if test="string-length(speciesauthor)!=0">
        <speciesauthor xml:lang=""><xsl:value-of select="speciesauthor"/></speciesauthor>
    </xsl:if>
    <memberstate><xsl:value-of select="member-state"/></memberstate>
    <forCountry><xsl:attribute name="rdf:resource">&countries;<xsl:value-of select="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>
  </SpeciesReport>
    <xsl:apply-templates/>
  </rdf:RDF>
</xsl:template>

<xsl:template match="regional">
  <SpeciesRegionalReport>
    <xsl:attribute name="rdf:ID"><xsl:value-of select="normalize-space(region)"/></xsl:attribute>
    <rdfs:label>Report on <xsl:value-of select="/species/speciesname"/> for <xsl:value-of select="region"/> biogeographical region in <xsl:value-of select="/species/member-state"/></rdfs:label>
    <memberstate><xsl:value-of select="/species/member-state"/></memberstate>
    <forCountry><xsl:attribute name="rdf:resource">&countries;<xsl:value-of select="normalize-space(/species/member-state/@countrycode)"/></xsl:attribute></forCountry>
    <xsl:if test="string-length(/species/speciesname)!=0">
        <speciesname xml:lang=""><xsl:value-of select="/species/speciesname"/></speciesname>
    </xsl:if>
    <xsl:if test="string-length(/species/speciesauthor)!=0">
        <speciesauthor xml:lang=""><xsl:value-of select="/species/speciesauthor"/></speciesauthor>
    </xsl:if>
    <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>
    <range_surface_area><xsl:value-of select="range/surface-area"/></range_surface_area>
    <range_date><xsl:value-of select="range/date"/></range_date>
    <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>
    <range_trend_magnitude><xsl:value-of select="range/trend-magnitude"/></range_trend_magnitude>
    <range_trend_period><xsl:value-of select="range/trend-period"/></range_trend_period>
    <range_reasons><xsl:value-of select="range/reasons-specify"/></range_reasons>
    <population_minimum_size><xsl:value-of select="population/size/minimum-size"/><xsl:text> </xsl:text><xsl:value-of select="population/size/size-unit"/></population_minimum_size> <!-- should rdf:value here -->
    <population_maximum_size><xsl:value-of select="population/size/maximum-size"/><xsl:text> </xsl:text><xsl:value-of select="population/size/size-unit"/></population_maximum_size> <!-- should rdf:value here -->
    <population_date><xsl:value-of select="population/date"/></population_date>
    <xsl:call-template name="fill-quality">
      <xsl:with-param name="text" select="population/quality"/>
      <xsl:with-param name="predicate" select="'population_quality'"/>
    </xsl:call-template>
    <xsl:call-template name="fill-trend">
      <xsl:with-param name="text" select="population/trend"/>
      <xsl:with-param name="predicate" select="'population_trend'"/>
    </xsl:call-template>
    <population_trend_magnitude><xsl:value-of select="population/trend-magnitude"/></population_trend_magnitude>
    <population_trend_period><xsl:value-of select="population/trend-period"/></population_trend_period>
    <xsl:call-template name="fill-multiple">
            <xsl:with-param name="text" select="population/reasons"/>
            <xsl:with-param name="predicate" select="'population_reasons'"/>
            <xsl:with-param name="table" select="'reasons'"/>
    </xsl:call-template>
    <population_reasons><xsl:value-of select="population/reasons-specify"/></population_reasons>
    <population_justification><xsl:value-of select="population/justification"/></population_justification>
    <xsl:apply-templates select="complementary/favourable-range"/>
    <xsl:apply-templates select="complementary/favourable-population"/>
    <complementary_species_assessment><xsl:value-of select="complementary/species-assessment"/></complementary_species_assessment>
    <complementary_other_information><xsl:value-of select="complementary/other-information"/></complementary_other_information>

    <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-population"/>
      <xsl:with-param name="predicate" select="'conclusion_population'"/>
      <xsl:with-param name="table" select="'conclusions'"/>
    </xsl:call-template>

    <xsl:call-template name="fill-assessment">
      <xsl:with-param name="text" select="conclusion/conclusion-habitat"/>
      <xsl:with-param name="predicate" select="'conclusion_habitat'"/>
      <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-population"/>
      <xsl:with-param name="predicate" select="'conclusion_n2000_population'"/>
      <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-habitat"/>
      <xsl:with-param name="predicate" select="'conclusion_n2000_habitat'"/>
      <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:call-template name="fill-multiple">
            <xsl:with-param name="text" select="population/method"/>
            <xsl:with-param name="predicate" select="'population_methods'"/>
            <xsl:with-param name="table" select="'methods'"/>
    </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="fill-multiple">
            <xsl:with-param name="text" select="population/pressures"/>
            <xsl:with-param name="predicate" select="'population_pressures'"/>
            <xsl:with-param name="table" select="'activities'"/>
    </xsl:call-template>
    <xsl:call-template name="fill-multiple">
            <xsl:with-param name="text" select="population/threats"/>
            <xsl:with-param name="predicate" select="'population_threats'"/>
            <xsl:with-param name="table" select="'activities'"/>
    </xsl:call-template>
    </SpeciesRegionalReport>
</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-population">
  <xsl:if test="string-length(@qualifier)!=0 or string-length(.)!=0">
    <complementary_favourable_population>
      <xsl:choose>
        <xsl:when test="string-length(@qualifier)!= 0">
           <xsl:value-of select="@qualifier"/><xsl:text> </xsl:text><xsl:value-of select="../../population/size/minimum-size"/><xsl:text> </xsl:text><xsl:value-of select="../../population/size/size-unit"/> 
        </xsl:when>
        <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
      </xsl:choose>
    </complementary_favourable_population>
  </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="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-multiple-record">
                        <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-multiple-record">
                    <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 name="one-multiple-record">
  <xsl:param name="text"/>
  <xsl:param name="predicate"/>
  <xsl:param name="table"/>
  <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: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-species-code">
    <xsl:param name="text" select="."/>
    <speciesname xml:lang=""><xsl:value-of select="$text"/></speciesname>
    <xsl:if test="document('http://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('http://converters.eionet.europa.eu/xmlfile/map-eunis-species.xml')/l:eunis/l:species[@name=$text]"/></xsl:attribute>
    </forSpecies>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>