View stylesheet

XML schema http://air-climate.eionet.europa.eu/schemas/reg2009443ec/vehicles2011.xsd
Output type EXCEL
Description Show as Excel
XSL file co2_monitoring_excel_2011.xsl (Last modified: 21 Apr 2011 12:18 )
<?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($elements/element)" /></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>
        <xsl:variable name="vehicleRow" select="."/>
        <table:table-row>
            <xsl:for-each select="$elements/element">
                <xsl:variable name="elemName" select="@name"/>
                <xsl:variable name="elemValue" select="$vehicleRow/*[local-name() = $elemName]"/>
                <table:table-cell>
                    <text:p>
                        <xsl:value-of select="$elemValue"/>
                    </text:p>
                </table:table-cell>
            </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="$elements/element">
                    <table:table-cell>
                        <text:p>
                          <xsl:value-of select="@heading"/>
                        </text:p>
                    </table:table-cell>
                </xsl:for-each>
            </table:table-row>
        </table:table-header-rows>
    </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>