View stylesheet

XML schema http://dd.eionet.europa.eu/schemas/habitatsdirective/checklist.xsd/utils
Output type HTML
Description Common templates
XSL file art12_art17-common-2018.xsl (Last modified: 20 Mar 2019 11:18 )
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
<!--
    Common templates for article 17 general report, habitats and species XSLs.

    For optimisation reasons the validate fields info and lookup tables are converted into static variables in XSLs.

    After updating xml_lookups/art17_validate_fields.xml or xml_lookups/art17_lu_all.xml, do the following:
        1. Convert art17_validate_fields.xml with art12_art17_validate_fields_converter.xsl -> art17_validate_fields.xsl
        2. Convert art17_lu_all.xml with art12_art17_lookups_converter.xsl -> art17_lookups.xsl
        3. Commit the results in SVN
        4. Updated the resulting XSLs to Converters and Converterstest
-->

    <xsl:import href="art17_validate_fields-2018.xsl"/>
    <xsl:import href="art17_lookups-2018.xsl"/>

    <xsl:param name="xml_folder_uri" />

    <xsl:variable name="xmlPath" select="$xml_folder_uri"/>
    <!--
    <xsl:variable name="xmlPath" select="'https://converters.eionet.europa.eu/xmlfile/'"/>
    -->
    <!--
    <xsl:variable name="lookupPath" select="document(concat($xmlPath, 'art17_lu_all.xml'))"/>
    <xsl:variable name="lookupValues" select="$lookupPath/dataroot"/>

    <xsl:variable name="labels_doc" select="document(concat($xmlPath, 'art17_validate_fields_', $report_type, '.xml'))"/>
    <xsl:variable name="labels" select="$labels_doc/dataroot"/>
    -->

    <xsl:template name="getCss">
        <style type="text/css"><![CDATA[
            img {
                border: 2px solid #ccc;
                margin: 10px;
            }
            h2 {
                font-family: arial, verdana, sans-serif;
            }
            h1 {
                font-size: 160%;
                padding-bottom: 0.5em;
                border-bottom: 1px solid #999999;
            }
            body {
                font-size: 80%;
                font-family: verdana, helvetica, arial, sans-serif;
                color: #333;
            }
            caption {
                display: none;
                font-family: vardana, verdana, helvetica, arial, sans-serif;
                text-align: left;
                font-size: 150%;
            }
            th {
                background-color: #f6f6f6;
                text-align: left;
                vertical-align: top;
                font-weight: bold;
                color: black;
            }
            table {
                font-size: 100%;
                border: 1px solid #bbb;
                width: 100%;
                margin: 0 0 2em 0;
                border-collapse: collapse;

            }
            table table {
                border: 0px solid #bbb;
                margin: 0;
            }
            th, td {
                font-size: 100%;
                border: 1px solid #bbb;
                padding: 2px 2px 2px 2px;
            }
            th.header_3 {
                background-color: #C6C6C6;
                padding: 0.4em 0;
                font-size: 1.1em;
                font-weight: bold;
            }
            p.report_end {
                border-bottom: dashed;
                border-width: 2px;
                border-color: #000000;
            }
            .label {
                font-weight: bold;
                color: #413839;
            }
            .optional {
                font-weight: normal;
                float: right;
                margin-right: 1.5em;
            }
            .value {
                font-weight: normal;
            }
            .value-highlighted, .value-highlighted span.value {
                color: #000082;
                font-weight: bold;
                font-size: 1.1em;
            }
            .value {
                margin-left: 0.3em;
            }
            .value-bold, .value-bold span.value {
                margin-left: 0.3em;
                font-weight: bold;
            }
            .value-fv span.value {
                background-color: green;
                color: white;
                padding-left: 5px;
                padding-right: 5px;
                text-align: center;
                font-weight: normal;
            }
            .value-bad span.value {
                background-color: red;
                color: white;
                padding-left: 5px;
                padding-right: 5px;
                text-align: center;
                font-weight: normal;
            }
            .value-inadequate span.value {
                background-color: orange;
                color: white;
                padding-left: 5px;
                padding-right: 5px;
                text-align: center;
                font-weight: normal;
            }
            .table_region {
                margin-top: 1em;
            }
            ]]>
        </style>
    </xsl:template>

    <!-- Replaces line breaks with <br/> tags -->
    <xsl:template name="break">
        <xsl:param name="text" select="."/>
        <xsl:choose>

            <xsl:when test="contains($text, '&#10;')">
                <xsl:value-of select="substring-before($text, '&#10;')" />
                <br/>
                <xsl:call-template name="break">
                    <xsl:with-param name="text" select="substring-after($text, '&#10;')" />
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$text"/>

            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <!-- Get field label from validate_fields.xml -->
    <xsl:template name="tag-label">
        <xsl:param name="tagname" select="name(.)"/>
        <xsl:param name="entity_type" select="local-name(parent::*)"/>
        <xsl:variable name="table_name">
            <xsl:call-template name="getTableName"><xsl:with-param name="entity_type" select="$entity_type"/></xsl:call-template>
        </xsl:variable>
        <xsl:call-template name="getLabel"><xsl:with-param name="table_name" select="$table_name"/><xsl:with-param name="xml_tag" select="$tagname"/></xsl:call-template>
        <!--
        <xsl:variable name="field_def" select="$labels/validate_fields_compact[table_name = $table_name and xml_tag = $tagname]"/>
        <xsl:variable name="label" select="$field_def/label"/>
        <xsl:variable name="optional" select="$field_def/optional_by_spec"/>
        <xsl:variable name="label" select="'TEST'"/>
        <xsl:variable name="optional" select="'0'"/>

        <span class="label"><xsl:value-of select="$label"/></span>
        <xsl:if test="$optional=1"><span class="optional">(Optional)</span></xsl:if>
        -->
    </xsl:template>

    <!-- format boolean strings, if they have different output value than Yes/No -->
    <xsl:template name="boolean-string">
        <xsl:param name="text" select="."/>
        <xsl:param name="out-text"/>
        <xsl:choose>
            <xsl:when test="lower-case($text)='true'">
                <xsl:value-of select="$out-text"/>
            </xsl:when>
            <xsl:otherwise/>
        </xsl:choose>
    </xsl:template>

    <!-- Default matching for all top level elements -->
    <xsl:template match="*">
        <xsl:variable name="valueClass" select="'value'"/>
        <xsl:variable name="valueClass">
            <xsl:choose>
                <xsl:when test="(name(.)='code' and local-name(parent::*)='region')
                    or (name(.)='speciescode' and (local-name(parent::*)='species_report'))
                    or (name(.)='speciesname' and (local-name(parent::*)='species_report'))
                    ">value-highlighted</xsl:when>
                <xsl:when test="name(.)='country'">value-bold</xsl:when>
                <xsl:when test="starts-with(name(.), 'conclusion_') and . = 'U1'">value-inadequate</xsl:when>
                <xsl:when test="starts-with(name(.), 'conclusion_') and . = 'U2'">value-bad</xsl:when>
                <xsl:when test="starts-with(name(.), 'conclusion_') and . = 'FV'">value-fv</xsl:when>
                <xsl:otherwise>value</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <tr>
            <th>
                <xsl:call-template name="tag-label">
                    <xsl:with-param name="tagname" select="name(.)"/>
                    <xsl:with-param name="entity_type" select="local-name(parent::*)"/>
                </xsl:call-template>
            </th>
            <td colspan="2">
                <xsl:attribute name="class" select="$valueClass"/>
                <xsl:call-template name="getValue"/>
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="getYesNoValue">
        <xsl:param name="elem" select="."/>
        <xsl:variable name="val">
            <xsl:if test="string-length($elem)!=0">
                <xsl:choose>
                    <xsl:when test="lower-case($elem)='true'">
                        Yes
                    </xsl:when>
                    <xsl:when test="lower-case($elem)='false'">
                        No
                    </xsl:when>
                </xsl:choose>
            </xsl:if>
        </xsl:variable>
        <span class="value"><xsl:value-of select="$val"/></span>
    </xsl:template>

    <!-- FORMAT value -->
    <xsl:template name="getValue">
        <xsl:param name="elem" select="."/>
        <xsl:variable name="val">
            <xsl:if test="string-length($elem)!=0">
                <xsl:choose>
                    <xsl:when test="lower-case($elem)='true'">
                        Yes
                    </xsl:when>
                    <xsl:when test="lower-case($elem)='false'">
                        No
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$elem"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
        </xsl:variable>
        <span class="value"><xsl:value-of select="$val"/></span>
        <xsl:call-template name="getValueLabel">
            <xsl:with-param name="elem" select="$elem"/>
        </xsl:call-template>
    </xsl:template>

    <!-- get label for lookup code. At first try lookup xml and if it is missing, then try @desc -->
    <xsl:template name="getValueLabel">
        <xsl:param name="elem" select="."/>

        <xsl:variable name="lookupLabel">
            <xsl:call-template name="getValueLabelFromLookup">
                <xsl:with-param name="elem" select="$elem"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:choose>
            <xsl:when test="string-length($lookupLabel)!=0">
                - <xsl:value-of select="$lookupLabel"/>
            </xsl:when>
            <xsl:when test="string-length($elem/@desc)!=0">
                - <xsl:value-of select="$elem/@desc"/>
            </xsl:when>
        </xsl:choose>
    </xsl:template>

    <!-- get LOOKUP value from XML -->
    <xsl:template name="getValueLabelFromLookup">

        <xsl:param name="elem" select="."/>

        <xsl:param name="tagname" select="name($elem)"/>
        <xsl:param name="entity_type" select="local-name($elem/parent::*)"/>

        <xsl:variable name="table_name">
            <xsl:call-template name="getTableName"><xsl:with-param name="entity_type" select="$entity_type"/></xsl:call-template>
        </xsl:variable>

        <xsl:variable name="lu_name"><xsl:call-template name="getLookupName"><xsl:with-param name="table_name" select="$table_name"/><xsl:with-param name="xml_tag" select="$tagname"/></xsl:call-template></xsl:variable>

        <!--
        <xsl:variable name="lu_name" select="$labels/validate_fields_compact[table_name = $table_name and xml_tag = $tagname]/lu_table"/>
        <xsl:variable name="name_field" select="$labels/validate_fields_compact[table_name = $table_name and xml_tag = $tagname]/lu_name_field"/>
        -->

        <xsl:if test="string-length($lu_name) != 0">
            <xsl:call-template name="getLookupCodeLabel"><xsl:with-param name="lu_name" select="$lu_name"/><xsl:with-param name="code" select="lower-case($elem)"/></xsl:call-template>
            <!--
            <xsl:variable name="label" select="$lookupValues/child::*[name(.) = $lu_name]/child::*[name(.) = $name_field and ../lower-case(code) = lower-case($elem)][1]"/>
            <xsl:if test="string-length($label) != 0">
                <xsl:value-of select="$label"/>
            </xsl:if>
            -->
        </xsl:if>
    </xsl:template>

    <!-- XML element and data_ table name mapping -->
    <xsl:template name="getTableName">
        <xsl:param name="entity_type" select="local-name(parent::*)"/>
        <xsl:choose>
            <xsl:when test="$entity_type='habitat_report'">data_habitats</xsl:when>
            <xsl:when test="$entity_type='species_report'">data_species</xsl:when>
            <xsl:when test="$entity_type='region' and $report_type='habitats'">data_habitattype_regions</xsl:when>
            <xsl:when test="$entity_type='region' and $report_type='species'">data_species_regions</xsl:when>
            <xsl:when test="$entity_type='annexV_species' and $report_type='species'">data_species_annexV</xsl:when>
            <xsl:when test="$entity_type='pressure' and ($report_type='species' or $report_type='habitats')">data_pressures_threats</xsl:when>
            <xsl:when test="$entity_type='threat' and ($report_type='species' or $report_type='habitats')">data_pressures_threats</xsl:when>
            <xsl:when test="$entity_type='data_pressures_threats_info' and ($report_type='species' or $report_type='habitats')">data_pressures_threats_info</xsl:when>
            <xsl:when test="$entity_type='conservation_measures' and ($report_type='species' or $report_type='habitats')">data_measures_info</xsl:when>
            <xsl:when test="$entity_type='measure' and ($report_type='species' or $report_type='habitats')">data_measures</xsl:when>
            <xsl:when test="$entity_type='report' and $report_type='greport'">data_greport</xsl:when>
            <xsl:when test="$entity_type='measure' and $report_type='greport'">data_gmeasures</xsl:when>
            <xsl:when test="$entity_type='species' and $report_type='greport'">data_greintroduction_of_species</xsl:when>
            <xsl:when test="$entity_type='bird_report' and $report_type='birds'">data_birds</xsl:when>
            <xsl:otherwise/>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="getPressuresThreatsSection">
        <table>
            <tbody>
                <tr>
                    <th colspan="3" class="header_3">
                        <xsl:choose>
                            <xsl:when test="$report_type='species'">8. </xsl:when>
                            <xsl:otherwise>7. </xsl:otherwise>
                        </xsl:choose>
                        Main pressures and threats
                    </th>
                </tr>
                <tr>
                    <th colspan="3">
                        <xsl:choose>
                            <xsl:when test="$report_type='species'">8.1 </xsl:when>
                            <xsl:otherwise>7.1 </xsl:otherwise>
                        </xsl:choose>
                        Characterisation of pressures/threats
                    </th>
                </tr>
                <xsl:apply-templates select="pressures"/>
                <xsl:apply-templates select="threats"/>
                <xsl:apply-templates select="data_pressures_threats_info"/>
            </tbody>
        </table>
    </xsl:template>

    <xsl:template match="pressures">
        <tr>
            <th>a) Pressure</th>
            <th>b) Ranking</th>
        </tr>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="threats">
        <tr>
            <th>a) Threat</th>
            <th>b) Ranking</th>
        </tr>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="data_pressures_threats_info">
        <xsl:variable name="sectionNumber">
            <xsl:choose>
                <xsl:when test="$report_type='species'">8</xsl:when>
                <xsl:otherwise>7</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <tr>
            <th><xsl:value-of select="$sectionNumber"/>.2 Sources of information<span class="optional">(Optional)</span></th>
            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="pressures_source"/></xsl:call-template></td>
        </tr>
        <tr>
            <th><xsl:value-of select="$sectionNumber"/>.3 Additional information<span class="optional">(Optional)</span></th>
            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="pressures_info"/></xsl:call-template></td>
        </tr>
    </xsl:template>
    
    <xsl:template match="pressure|threat">
        <tr>
            <td>
                <xsl:call-template name="getValue"><xsl:with-param name="elem" select="code"/></xsl:call-template>
            </td>
            <td>
                <xsl:call-template name="getValue"><xsl:with-param name="elem" select="ranking"/></xsl:call-template>
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="getConservationMeasuresSection">
        <xsl:variable name="sectionNumber">
            <xsl:choose>
                <xsl:when test="$report_type='species'">9</xsl:when>
                <xsl:otherwise>8</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <table>
            <tbody>
                <tr><th colspan="3" class="header_3"><xsl:value-of select="$sectionNumber"/>. Conservation measures</th></tr>
                <tr>
                    <th><xsl:value-of select="$sectionNumber"/>.1a Status of measures - Are measures needed?</th>
                    <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="conservation_measures/measures_needed"/></xsl:call-template></td>
                </tr>
                <tr>
                    <th><xsl:value-of select="$sectionNumber"/>.1b Status of measures - Indicate the status of measures</th>
                    <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="conservation_measures/measures_status"/></xsl:call-template></td>
                </tr>
                <tr>
                    <th><xsl:value-of select="$sectionNumber"/>.2 Main purpose of the measures taken</th>
                    <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="conservation_measures/measures_purpose"/></xsl:call-template></td>
                </tr>
                <tr>
                    <th><xsl:value-of select="$sectionNumber"/>.3 Location of the measures taken</th>
                    <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="conservation_measures/measures_location"/></xsl:call-template></td>
                </tr>
                <tr>
                    <th><xsl:value-of select="$sectionNumber"/>.4 Response to the measures</th>
                    <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="conservation_measures/measures_response"/></xsl:call-template></td>
                </tr>
                <tr>
                    <th><xsl:value-of select="$sectionNumber"/>.5 List of main conservation measures</th>
                    <td><xsl:apply-templates select="conservation_measures/measures/measure"/></td>
                </tr>
                <tr>
                    <th><xsl:value-of select="$sectionNumber"/>.6 Additional information<span class="optional">(Optional)</span></th>
                    <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="conservation_measures/measures_info"/></xsl:call-template></td>
                </tr>
            </tbody>
        </table>
    </xsl:template>

    <xsl:template match="measure">
        <xsl:call-template name="getValue"><xsl:with-param name="elem" select="code"/></xsl:call-template>
        <br />
    </xsl:template>

    <xsl:template name="getDataChangeSection">
        <xsl:param name="elem" select="."/>
        <xsl:param name="title"/>

        <tr>
            <xsl:choose>
                <xsl:when test="$elem/no_change='true'"><th><xsl:value-of select="$title"/></th></xsl:when>
                <xsl:otherwise><th rowspan="6"><xsl:value-of select="$title"/></th></xsl:otherwise>
            </xsl:choose>
            <td>Is there a change between reporting periods?</td>
            <td>
                <span class="value">
                    <xsl:choose>
                        <xsl:when test="$elem/no_change='true'">No</xsl:when>
                        <xsl:otherwise>Yes</xsl:otherwise>
                    </xsl:choose>
                </span>
            </td>
        </tr>
        <xsl:if test="$elem/no_change='false'">
            <tr>
                <td>a) yes, due to genuine change</td>
                <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="$elem/genuine"/></xsl:call-template></td>
            </tr>
            <tr>
                <td>b) yes, due to improved knowledge/more accurate data</td>
                <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="$elem/knowledge"/></xsl:call-template></td>
            </tr>
            <tr>
                <td>c) yes, due to the use of different method</td>
                <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="$elem/method"/></xsl:call-template></td>
            </tr>
            <tr>
                <td>d) yes, but there is no information on the nature of change</td>
                <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="$elem/no_info"/></xsl:call-template></td>
            </tr>
            <tr>
                <td colspan="2">The change is mainly due to: <xsl:call-template name="getValue"><xsl:with-param name="elem" select="$elem/main_reason/@desc"/></xsl:call-template></td>
            </tr>
        </xsl:if>
    </xsl:template>

    <xsl:template name="getConservationStatusDataChange">
        <xsl:variable name="sectionNumber">
            <xsl:choose>
                <xsl:when test="$report_type='species'">11</xsl:when>
                <xsl:otherwise>10</xsl:otherwise>
            </xsl:choose>
         </xsl:variable>

         <tr>
            <th><xsl:value-of select="$sectionNumber"/>.7 Change and reasons for change in conservation status and conservation status trend</th>
            <td colspan="2">
                <table>
                    <tbody>
                        <th></th>
                        <th>Overall assessment of conservation status (<xsl:value-of select="$sectionNumber"/>.5)</th>
                        <th>Overall trend in conservation status (<xsl:value-of select="$sectionNumber"/>.6)</th>
                        <tr>
                            <td>a) no, there is no difference</td>
                            <td>
                                <span class="value">
                                    <xsl:choose>
                                        <xsl:when test="status_reasons_for_change/no_change='true'">Yes</xsl:when>
                                        <xsl:otherwise>No</xsl:otherwise>
                                    </xsl:choose>
                                </span>
                            </td>
                            <td>
                                <span class="value">
                                    <xsl:choose>
                                        <xsl:when test="trend_reasons_for_change/no_change='true'">Yes</xsl:when>
                                        <xsl:otherwise>No</xsl:otherwise>
                                    </xsl:choose>
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <td>b) yes, due to genuine change</td>
                            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="status_reasons_for_change/genuine"/></xsl:call-template></td>
                            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="trend_reasons_for_change/genuine"/></xsl:call-template></td>
                        </tr>
                        <tr>
                            <td>c) yes, due to improved knowledge/more accurate data</td>
                            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="status_reasons_for_change/knowledge"/></xsl:call-template></td>
                            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="trend_reasons_for_change/knowledge"/></xsl:call-template></td>
                        </tr>
                        <tr>
                            <td>d) yes, due to the use of different method</td>
                            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="status_reasons_for_change/method"/></xsl:call-template></td>
                            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="trend_reasons_for_change/method"/></xsl:call-template></td>
                        </tr>
                        <tr>
                            <td>e) yes, but there is no information on the nature of change</td>
                            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="status_reasons_for_change/no_info"/></xsl:call-template></td>
                            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="trend_reasons_for_change/no_info"/></xsl:call-template></td>
                        </tr>
                        <tr>
                            <td>The change is mainly due to:</td>
                            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="status_reasons_for_change/main_reason/@desc"/></xsl:call-template></td>
                            <td><xsl:call-template name="getValue"><xsl:with-param name="elem" select="trend_reasons_for_change/main_reason/@desc"/></xsl:call-template></td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </xsl:template>

</xsl:stylesheet>