View stylesheet

XML schemas
Output type HTML
Description HTML table
XSL file cars_co2_aggregations_html_2014.xsl (Last modified: 28 Jan 2014 11:20 )
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="" version="1.0">
    <xsl:output method="html"/>
    <xsl:variable name="heading" select="'CO2 Emissions for cars - aggregated data'"/>

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

    <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="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 name="attributes">
        <attr name="Y" heading="Year" />
        <attr name="MS" heading="Member State" />
        <attr name="DS" heading="Data source" />
        <attr name="FSP" heading="Percentage of E85 stations" />
        <attr name="NFS" heading="Total number of fuel filling stations" />
        <attr name="Rt" heading="Registrations" />
        <attr name="Re" heading="Registrations with CO2 emission value" />
        <attr name="Rm" heading="Registrations with mass value" />