View stylesheet

XML schema http://dd.eionet.europa.eu/schemas/CO2-monitoring-vans_2014/vans-aggregated.xsd
Output type HTML
Description HTML table
XSL file vans_co2_aggregations_html_2014.xsl (Last modified: 22 Mar 2014 10:19 )
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
    <!--
        $Id$
        For http://dd.eionet.europa.eu/schemas/CO2-monitoring-vans_2013/vans-aggregated.xsd
    -->
    <xsl:variable name="heading" select="'CO2 Emissions for vans - aggregates'"/>

    <xsl:template match="/">
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
                <title><xsl:value-of select="$heading"/></title>
                <style type="text/css">
                    table {
                        border-collapse:collapse;
                    }
                    td, th {
                        border:1px solid black; padding:2px;
                    }
                    #metadata th{
                        text-align:right;
                    }
                  </style>
            </head>
            <body>
                <h1><xsl:value-of select="$heading"/></h1>
                <xsl:call-template name="metadata-table"/>
                <br/>
                <table>
                    <xsl:apply-templates select="VansAggregates/item"/>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="VansAggregates/item">
        <xsl:if test="position()=1">
            <xsl:call-template name="header"/>
        </xsl:if>
        <xsl:variable name="vehicleRow" select="."/>
        <tr>
            <xsl:for-each select="$elements/element">
                <xsl:variable name="elemName" select="@name"/>
                <xsl:variable name="elemValue" select="$vehicleRow/*[local-name() = $elemName]"/>
                <td>
                    <xsl:if test="$elemValue = ''"> </xsl:if>
                    <xsl:value-of select="$elemValue"/>
                </td>
            </xsl:for-each>
        </tr>
    </xsl:template>
    <xsl:template name="header">
        <tr>
            <xsl:for-each select="$elements/element">
                <th style="background-color:#87cefa">
                    <xsl:value-of select="@heading"/>
                </th>
            </xsl:for-each>
        </tr>
    </xsl:template>

    <xsl:template name="metadata-table">
        <table id="metadata">
            <tr>
                <th>Year</th>
                <td><xsl:value-of select="/VansAggregates/@Y" /></td>
            </tr>
            <tr>
                <th>Member State</th>
                <td><xsl:value-of select="/VansAggregates/@MS" /></td>
            </tr>
            <tr>
                <th>Data source</th>
                <td><xsl:value-of select="/VansAggregates/@DS" /></td>
            </tr>
            <tr>
                <th>Multistage vehicles included</th>
                <td><xsl:value-of select="/VansAggregates/@MSV" /></td>
            </tr>
        </table>
    </xsl:template>

    <xsl:variable name="elements">
            <element name="ID" heading="ID" />
            <element name="Mh" heading="EU Manufacturer Name"/>
            <element name="Man" heading="Manufacturer" />
            <element name="MMS" heading="Manufacturer National" />
            <element name="Rt" heading="Registrations" />
            <element name="Re" heading="# CO2 emission value" />
            <element name="Rm" heading="# mass value" />
            <element name="Rw" heading="# wheelbase" />
            <element name="Rat1" heading="# axle value" />
            <element name="Rat2" heading="# having an axle (other) value" />
            <element name="Eav" heading="Average CO2 Emissions" />
            <element name="Mav" heading="Average Mass" />
            <element name="Fav" heading="Average Footprint" />
    </xsl:variable>
</xsl:stylesheet>