View stylesheet

XML schema http://air-climate.eionet.europa.eu/schemas/reg2009443ec/vehicles2011.xsd
Output type HTML
Description Show as HTML
XSL file co2_monitoring_html_2011.xsl (Last modified: 21 Apr 2011 11:55 )
<?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</title>
                <style type="text/css">
                    table {
                        border-collapse:collapse;
                    }
                    td, th {
                        border:1px solid black; padding:2px;
                    }
                  </style>
            </head>
            <body>
                <h1>CO2-monitoring</h1>
                <table>
                    <xsl:apply-templates select="vehicles/item"/>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="vehicles/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="T" heading="Type"/>
        <element name="Va" heading="Variant"/>
        <element name="Ve" heading="Version"/>
        <element name="Mk" heading="Make"/>
        <element name="Cn" heading="Commercial Name"/>
        <element name="Ct" heading="Category"/>
        <element name="R" heading="Registrations"/>
        <element name="M" heading="Mass"/>
        <element name="E" heading="Emissions"/>
        <element name="W" heading="Wheelbase"/>
        <element name="At1" heading="Axle track of steered axle"/>
        <element name="At2" heading="Axle track of other axle"/>
        <element name="Ft" heading="Fuel type"/>
        <element name="Fm" heading="Fuel mode"/>
        <element name="Ec" heading="Engine capacity"/>
        <element name="Z" heading="Electric energy consumption"/>
        <element name="IT" heading="Innovative technology"/>
        <element name="Er" heading="Emission reduction"/>
    </xsl:variable>

</xsl:stylesheet>