View stylesheet

XML schemas http://converters.eionet.europa.eu/util/Art17/2012
Output type HTML
Description Common XSL templates for Article 12 and 17 dataflows (2013)
XSL file art12_art17-common.xsl (Last modified: 07 Jan 2014 15:08 )
<?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.xsl"/>
    <xsl:import href="art17_lookups.xsl"/>

    <xsl:param name="xml_folder_uri" />

    <xsl:variable name="xmlPath" select="$xml_folder_uri"/>
    <!--
    <xsl:variable name="xmlPath" select="'http://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>

    <!-- 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='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='pollution_qualifier' and ($report_type='species' or $report_type='habitats')">data_pressures_threats_pol</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:stylesheet>