View stylesheet

XML schema http://air-climate.eionet.europa.eu/schemas/reg2009443ec/vehicles.xsd
Output type TEXT
Description Comma separated values
XSL file co2_monitoring_txt_2010.xsl (Last modified: 08 Oct 2010 10:27 )
<?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="/">
					<xsl:apply-templates select="vehicles/item"/>
	</xsl:template>
	<xsl:template match="vehicles/item">
		<xsl:if test="position()=1">
			<xsl:call-template name="header"/>
		</xsl:if>
			<xsl:for-each select="*">
				<xsl:if test="count(preceding-sibling::*[local-name() = local-name(current())])=0">
						<xsl:call-template name="getValue"/>
						<xsl:choose>
							<xsl:when test="count(following-sibling::*[local-name() != local-name(current())]) &gt; 0">,</xsl:when>
							<xsl:otherwise><xsl:text>&#xa;</xsl:text></xsl:otherwise>
						</xsl:choose>
				</xsl:if>
			</xsl:for-each>
	</xsl:template>
	<xsl:template name="header">
			<xsl:for-each select="*">
				<xsl:if test="count(preceding-sibling::*[local-name() = local-name(current())])=0">
						<xsl:call-template name="getColumnName">
							<xsl:with-param name="element"><xsl:value-of select="local-name()"/></xsl:with-param>
						</xsl:call-template>						
						<xsl:choose>
							<xsl:when test="count(following-sibling::*[local-name() != local-name(current())]) &gt; 0">,</xsl:when>
							<xsl:otherwise><xsl:text>&#xa;</xsl:text></xsl:otherwise>
						</xsl:choose>
				</xsl:if>
			</xsl:for-each>
	</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>