View stylesheet

XML schemas http://air-climate.eionet.europa.eu/schemas/reg2009443ec/vehicles.xsd
Output type HTML
Description HTML table
XSL file co2_monitoring_html_2010.xsl (Last modified: 08 Oct 2010 09:14 )
<?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>
		<tr>
			<xsl:for-each select="*">
				<xsl:if test="count(preceding-sibling::*[local-name() = local-name(current())])=0">
					<td>
						<xsl:if test=".=''">   </xsl:if>
						<xsl:call-template name="getValue"/>
					</td>
				</xsl:if>
			</xsl:for-each>
		</tr>
	</xsl:template>
	<xsl:template name="header">
		<tr>
			<xsl:for-each select="*">
				<xsl:if test="count(preceding-sibling::*[local-name() = local-name(current())])=0">
					<th bgcolor="#87cefa">
						<xsl:call-template name="getColumnName">
							<xsl:with-param name="element"><xsl:value-of select="local-name()"/></xsl:with-param>
						</xsl:call-template>						
					</th>
				</xsl:if>
			</xsl:for-each>
		</tr>
	</xsl:template>
	<xsl:template name="getValue">
		<xsl:choose>
			<xsl:when test="count(following-sibling::*[local-name() = local-name(current())])=0">
				<xsl:value-of select="."/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="joinMultiValue">
					<xsl:with-param name="valueList" select="parent::*/child::*[local-name() = local-name(current())]"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="joinMultiValue">
		<xsl:param name="valueList" select="''"/>
		<xsl:variable name="separator">
			<xsl:call-template name="getSeparator">
				<xsl:with-param name="element" select="local-name()"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:for-each select="$valueList">
			<xsl:choose>
				<xsl:when test="position() = 1">
					<xsl:value-of select="."/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="concat($separator, .)"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>
	<xsl:template name="getSeparator">
		<xsl:param name="element" select="''"/>
		<xsl:value-of select="','"/>
	</xsl:template>

	<xsl:template name="getColumnName">
		<xsl:param name="element" select="''"/>
		
		<xsl:choose>
			<xsl:when test="$element='ID'">ID</xsl:when>
			<xsl:when test="$element='Man'">Manufacturer</xsl:when>
			<xsl:when test="$element='T'">Type</xsl:when>
			<xsl:when test="$element='Va'">Variant</xsl:when>
			<xsl:when test="$element='Ve'">Version</xsl:when>
			<xsl:when test="$element='Mk'">Make</xsl:when>
			<xsl:when test="$element='Cn'">Commercial Name</xsl:when>
			<xsl:when test="$element='Ct'">Category</xsl:when>
			<xsl:when test="$element='R'">Registrations</xsl:when>
			<xsl:when test="$element='Ft'">Fuel type</xsl:when>
			<xsl:when test="$element='Fm'">Fuel mode</xsl:when>
			<xsl:when test="$element='E'">Emissions</xsl:when>
			<xsl:when test="$element='M'">Mass</xsl:when>
			<xsl:when test="$element='Ec'">Engine capacity</xsl:when>
			<xsl:when test="$element='At1'">Axle track of steered axle</xsl:when>
			<xsl:when test="$element='At2'">Axle track of other axle</xsl:when>
			<xsl:when test="$element='W'">Wheelbase</xsl:when>
			<xsl:otherwise><xsl:value-of select="$element"/></xsl:otherwise>
		</xsl:choose>
	</xsl:template>


</xsl:stylesheet>