View stylesheet

XML schema http://dd.eionet.europa.eu/schemas/CO2-monitoring-vans_2013/vans-aggregated.xsd
Output type EXCEL
Description MS Excel
XSL file vans_co2_aggregations_excel_2013.xsl (Last modified: 16 Jan 2013 16:15 )
<?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:output method="xml"/>
    <!--
        $Id$
        For http://dd.eionet.europa.eu/schemas/CO2-monitoring-vans_2013/vans-aggregated.xsd
    -->
    <xsl:variable name="heading" select="'CO2-vans-aggregated'" />

    <xsl:template match="/">
        <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>
                <style:style style:name="Heading3" style:family="table-cell">
                    <style:properties fo:text-align="Right"
                        fo:font-size="10pt" fo:font-weight="bold" style:column-width="5cm"/>
                </style:style>
            </office:automatic-styles>
            <office:body>
                <table:table>
                    <xsl:attribute name="table:name"><xsl:value-of
                        select="$heading" /></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="VansAggregates/item" />
                    </table:table-rows>
                </table:table>
                <xsl:call-template name="metadata-table" />
            </office:body>
        </office:document-content>
    </xsl:template>
    <xsl:template match="VansAggregates/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:template name="metadata-table">
        <table:table>
            <xsl:attribute name="table:name">Metadata</xsl:attribute>
            <table:table-columns>
                <table:table-column
                    table:default-cell-value-type="string"
                    table:default-cell-style-name="Heading3" />
                <table:table-column
                    table:default-cell-value-type="string"
                    table:default-cell-style-name="cell1" />
            </table:table-columns>
            <table:table-rows>
                <table:table-row>
                    <table:table-cell table:style-name="Heading3">
                        <text:p>Year</text:p>
                    </table:table-cell>
                    <table:table-cell table:style-name="cell1">
                        <text:p>
                            <xsl:value-of select="/VansAggregates/@Y" />
                        </text:p>
                    </table:table-cell>
                </table:table-row>
                <table:table-row>
                    <table:table-cell>
                        <text:p>Member State</text:p>
                    </table:table-cell>
                    <table:table-cell>
                        <text:p>
                            <xsl:value-of select="/VansAggregates/@MS" />
                        </text:p>
                    </table:table-cell>
                </table:table-row>
                <table:table-row>
                    <table:table-cell>
                        <text:p>Data source</text:p>
                    </table:table-cell>
                    <table:table-cell>
                        <text:p>
                            <xsl:value-of select="/VansAggregates/@DS" />
                        </text:p>
                    </table:table-cell>
                </table:table-row>
                <table:table-row>
                    <table:table-cell>
                        <text:p>Multistage vehicles included</text:p>
                    </table:table-cell>
                    <table:table-cell>
                        <text:p>
                            <xsl:value-of select="/VansAggregates/@MSV" />
                        </text:p>
                    </table:table-cell>
                </table:table-row>
            </table:table-rows>
        </table:table>
    </xsl:template>

    <xsl:variable name="elements">
        <element name="ID" heading="ID" />
        <element name="Mh" heading="EU Manufacturer Name"/>
        <element name="Man" heading="Manufacturer" />
        <element name="MMS" heading="Manufacturer National" />
        <element name="Rt" heading="Registrations" />
        <element name="Re" heading="# CO2 emission value" />
        <element name="Rm" heading="# mass value" />
        <element name="Rw" heading="# wheelbase" />
        <element name="Rat1" heading="# axle value" />
        <element name="Rat2" heading="# having an axle (other) value" />
        <element name="Eav" heading="Average CO2 Emissions" />
        <element name="Mav" heading="Average Mass" />
        <element name="Fav" heading="Average Footprint" />
    </xsl:variable>

</xsl:stylesheet>