View stylesheet

XML schema http://dd.eionet.europa.eu/schemas/habitatsdirective/art17_habitats_checklist.xsd
Output type RDF
Description RDF output
XSL file habitats-checklist-rdf-2018.xsl (Last modified: 07 Feb 2019 14:00 )
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: habitats-rdf.xsl 10883 2011-12-08 09:44:07Z lainekai $ -->

<!DOCTYPE xsl:stylesheet [
 <!ENTITY biogeo "http://rdfdata.eionet.europa.eu/eea/biogeographic-regions/">
 <!ENTITY countries "http://rdfdata.eionet.europa.eu/eea/countries/">
]>

<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:variable name="countrycode" select="member_state_checklist/country"/>
    <xsl:variable name="countryname" select="member_state_checklist/country/@desc"/>

    <xsl:template match="member_state_checklist">
        <rdf:RDF>
            <!--forCountry>
                <xsl:attribute name="rdf:resource">&countries;<xsl:value-of select="$countrycode" /></xsl:attribute>
            </forCountry-->
            <xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
            <xsl:apply-templates/>
        </rdf:RDF>
    </xsl:template>

    <xsl:template match="habitats">
        <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="habitat">
        <xsl:apply-templates select="regional"/>
    </xsl:template>

    <xsl:template match="region">
        <HabitatChecklistItem rdf:about="">
            <rdfs:label>Habitats directive art. 17 checklist item for habitat code: <xsl:value-of select="../../code"/> region <xsl:value-of select="code"/> in <xsl:value-of select="$countryname"/></rdfs:label>
            <xsl:call-template name="get-eunis-habitats-code">
                <xsl:with-param name="text" select="../../code"/>
            </xsl:call-template>
            <memberstate>
                <xsl:value-of select="$countryname"/>
            </memberstate>
            <forCountry>
                <xsl:attribute name="rdf:resource">&countries;<xsl:value-of select="$countrycode" /></xsl:attribute>
            </forCountry>
            <region>
                <xsl:attribute name="rdf:resource">&biogeo;<xsl:value-of select="code"/></xsl:attribute>
            </region>
            <presence>
                <xsl:value-of select="presence/@desc" />
            </presence>
            <addedByMemberState>
                <xsl:value-of select="ms_added" />
            </addedByMemberState>
            <notChangedByMemberState>
                <xsl:value-of select="predefined" />
            </notChangedByMemberState>
        </HabitatChecklistItem>
    </xsl:template>

    <xsl:template match="country"></xsl:template>

    <xsl:template match="regional">
        <xsl:apply-templates/>
    </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 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://rdfdata.eionet.europa.eu/article17/<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" select="."/>
        <xsl:param name="predicate" select="name(.)"/>
        <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:template match="*">
        <xsl:if test="string-length(@desc)!=0">
            <xsl:call-template name="one-literal-predicate">
                <xsl:with-param name="text">
                    <xsl:value-of select="concat(@desc, ' (' , . , ')') "/>
                </xsl:with-param>
            </xsl:call-template>
        </xsl:if>
        <xsl:if test="not (@desc)">
            <xsl:call-template name="one-literal-predicate"/>
        </xsl:if>
    </xsl:template>

    <xsl:template name="code-name">
        <xsl:param name="text" select="code/@desc"/>
        <!--
            xsl:param name="predicate" select="concat(local-name(parent::*)
            ,'name')"/
        -->
        <xsl:param name="predicate" select="concat(name(.) ,'name')"/>
        <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:template>

</xsl:stylesheet>