View stylesheet

XML schema http://air-climate.eionet.europa.eu/schemas/reg2009443ec/vehicles.xsd
Output type EXCEL
Description MS Excel table
XSL file co2_monitoring_excel_2010.xsl (Last modified: 08 Oct 2010 09:17 )
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:office="http://openoffice.org/2000/office" xmlns:table="http://openoffice.org/2000/table" xmlns:text="http://openoffice.org/2000/text">
	<xsl:template match="vehicles">
		<office:document-content xmlns:office="http://openoffice.org/2000/office" xmlns:table="http://openoffice.org/2000/table" office:version="1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:number="http://openoffice.org/2000/datastyle" xmlns:text="http://openoffice.org/2000/text" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:style="http://openoffice.org/2000/style">
			<office:automatic-styles>
				<style:style style:name="cell1" style:family="table-cell">
					<style:properties fo:text-align="left" fo:font-size="10pt"/>
				</style:style>
				<style:style style:name="cell2" style:family="table-cell">
					<style:properties fo:text-align="center" fo:font-size="12pt" fo:font-style="italic"/>
				</style:style>
				<style:style style:name="Heading1" style:family="table-cell">
					<style:properties fo:text-align="left" fo:font-size="10pt" fo:font-style="italic" style:text-align-source="fix" fo:font-weight="bold"/>
				</style:style>
				<style:style style:name="Heading2" style:family="table-cell">
					<style:properties fo:text-align="center" fo:font-size="10pt" fo:font-weight="bold"/>
				</style:style>
			</office:automatic-styles>
			<office:body>
				<table:table>
					<xsl:attribute name="table:name">CO2-monitoring</xsl:attribute>
					<table:table-columns>
						<table:table-column table:default-cell-value-type="number" table:default-cell-style-name="cell1">
							<xsl:attribute name="table:number-columns-repeated"><xsl:value-of select="count(./item[1]/*)"/></xsl:attribute>
						</table:table-column>
					</table:table-columns>
					<!-- create header rows -->
					<table:table-rows>
						<xsl:apply-templates select="item"/>
					</table:table-rows>
				</table:table>
			</office:body>
		</office:document-content>
	</xsl:template>
	<xsl:template match="item">
		<xsl:if test="position()=1">
			<xsl:call-template name="header"/>
		</xsl:if>
		<table:table-row>
			<xsl:for-each select="*">
				<xsl:if test="count(preceding-sibling::*[local-name() = local-name(current())])=0">
					<table:table-cell>
						<text:p>
							<xsl:call-template name="getValue"/>
						</text:p>
					</table:table-cell>
				</xsl:if>
			</xsl:for-each>
		</table:table-row>
	</xsl:template>
	<!--  a named template, which creates the table header row -->
	<xsl:template name="header">
		<table:table-header-rows>
			<table:table-row table:default-cell-value-type="string" table:default-cell-style-name="Heading2">
				<xsl:for-each select="*">
					<xsl:if test="count(preceding-sibling::*[local-name() = local-name(current())])=0">
						<table:table-cell>
							<text:p>
								<xsl:call-template name="getColumnName">
									<xsl:with-param name="element"><xsl:value-of select="local-name()"/></xsl:with-param>
								</xsl:call-template>						
							</text:p>
						</table:table-cell>
					</xsl:if>
				</xsl:for-each>
			</table:table-row>
		</table:table-header-rows>
	</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>