View stylesheet

XML schema http://dd.eionet.europa.eu/schemas/habitatsdirective/checklist.xsd/utils
Output type HTML
Description Common templates for article 12
XSL file art12_redlist-common-2018.xsl (Last modified: 20 Mar 2019 11:25 )
<?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 12 general report, birds and Redlist birds XSLs.

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

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

    <xsl:import href="art12_validate_fields-2018.xsl"/>
    <!-- <xsl:import href="art12_validate_fields_redlist.xsl"/> -->
    <xsl:import href="art12_lookups-2018.xsl"/>

    <xsl:variable name="isRedList"><xsl:value-of select="/bird_reports/@redlist = 'true'"/></xsl:variable>

    <xsl:param name="xml_folder_uri" />

    <xsl:variable name="xmlPath" select="$xml_folder_uri"/>

    <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;
                vertical-align: text-top;
            }
            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:choose>
            <xsl:when test="$isRedList = 'false'">
                <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:when>
            <!--
                <xsl:otherwise>
                    <xsl:call-template name="getLabelRedlist"><xsl:with-param name="table_name" select="$table_name"/><xsl:with-param name="xml_tag" select="$tagname"/></xsl:call-template>
                </xsl:otherwise>
            -->
        </xsl:choose>
    </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 local-name(parent::*)='bird_report'))
                    or (name(.)='speciesname' and (local-name(parent::*)='species_report' or local-name(parent::*)='bird_report'))
                    or name(.) = 'season' or name(.)='subspecies_name'
                    ">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:choose>
                <xsl:when test="$isRedList = 'false'">
                    <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:when>
                <!--
                    <xsl:otherwise>
                        <xsl:call-template name="getLookupNameRedlist"><xsl:with-param name="table_name" select="$table_name"/><xsl:with-param name="xml_tag" select="$tagname"/></xsl:call-template>
                    </xsl:otherwise>
                -->
            </xsl:choose>
        </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='bird_report' and $report_type='birds'">data_birds</xsl:when>
            <xsl:when test="$entity_type='data_birds_annexII' and $report_type='birds'">data_birds_annexII</xsl:when>
            <xsl:when test="$entity_type='measure' and $report_type='birds'">data_bmeasures</xsl:when>
            <xsl:when test="$entity_type='conservation_measures' and $report_type='birds'">data_bmeasures_info</xsl:when>
            <xsl:when test="$entity_type='pressure' and $report_type='birds'">data_bpressures_threats</xsl:when>
            <xsl:when test="$entity_type='threat' and $report_type='birds'">data_bpressures_threats</xsl:when>
            <xsl:when test="$entity_type='pressures_threats_info' and $report_type='birds'">data_bpressures_threats_info</xsl:when>
            <xsl:when test="$entity_type='birds_general_report' and $report_type='bgeneral'">data_bgreport</xsl:when>
            <xsl:otherwise/>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>