View stylesheet

XML schema http://air-climate.eionet.europa.eu/schemas/reg2009443ec/aggregations2011.xsd
Output type HTML
Description Show as HTML
XSL file co2_aggregations_html_2011.xsl (Last modified: 21 Apr 2011 12:24 )
<?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"/>
    <xsl:template match="/">
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
                <title>CO2-monitoring aggregations</title>
                <style type="text/css">
                    table {
                        border-collapse:collapse;
                    }
                    td, th {
                        border:1px solid black; padding:2px;
                    }
                  </style>
            </head>
            <body>
                <h1>CO2-monitoring aggregations</h1>
                <table>
                    <xsl:apply-templates select="aggregates/item"/>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="aggregates/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:variable name="elements">
            <element name="ID" heading="ID" />
            <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 Emissions" />
            <element name="Mav" heading="Average Mass" />
            <element name="Fav" heading="Average Footprint" />
    </xsl:variable>
</xsl:stylesheet>