View stylesheet

XML schemas http://dd.eionet.europa.eu/schemas/ippc-wi_2014/dir20081ec_schema.xsd
Output type EXCEL
Description MS Excel spreadsheet
XSL file dir20081ec_excel_2014.xsl (Last modified: 18 Sep 2014 11:42 )
<?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" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:output method="xml"/>
    <!--
        $Id$
    -->
    <xsl:variable name="labels" select="document('https://svn.eionet.europa.eu/repositories/Reportnet/Dataflows/IPPC-WI-Directive/xml/dir20081ec_ippc/dir20081ec_labels-en.xml')/labels/labelSet"/>
    <!--<xsl:variable name="labels" select="document('../xml/article17-labels.xml')/labels"/>-->

    <!--<xsl:variable name="codelists" select="document('http://converters.eionet.europa.eu/xmlfile/art17-codelists-en.xml')/Article17Codelists"/>-->
    <xsl:variable name="schema" select="document('https://svn.eionet.europa.eu/repositories/Reportnet/Dataflows/IPPC-WI-Directive/schemas/dir20081ec_schema.xsd')/xs:schema"/>
    <xsl:variable name="heading" select="'Factsheet of IPPC questionnaire delivery'" />

    <xsl:template match="/response">
        <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="row-height" style:family="table-cell">
                    <style:properties  style:row-height="2cm" />
                </style:style>
                <style:style style:name="string-cell" style:family="table-cell">
                    <style:properties fo:text-align="left"
                                      fo:font-size="10pt" style:column-width="5cm" />
                </style:style>
                <style:style style:name="long-string-cell" style:family="table-cell">
                    <style:properties fo:text-align="left"
                                      fo:font-size="10pt" style:column-width="15cm" />
                </style:style>
                <style:style style:name="number-cell" style:family="table-cell">
                    <style:properties fo:text-align="right"
                                      fo:font-size="10pt" style:column-width="5cm" />
                </style:style>
                <style:style style:name="long-number-cell" style:family="table-cell">
                    <style:properties fo:text-align="right"
                                      fo:font-size="10pt" style:column-width="10cm" />
                </style:style>
                <style:style style:name="total-number-cell" style:family="table-cell">
                    <style:properties fo:text-align="right" fo:font-weight="bold"
                                      fo:font-size="10pt" style:column-width="5cm" />
                </style:style>
                <style:style style:name="string-heading" style:family="table-cell">
                    <style:properties fo:text-align="left"
                                      fo:font-size="10pt" style:column-width="5cm" fo:font-weight="bold" style:row-height="2cm" />
                </style:style>
                <style:style style:name="long-string-heading" style:family="table-cell">
                    <style:properties fo:text-align="left"
                                      fo:font-size="10pt" style:column-width="10cm" fo:font-weight="bold" />
                </style:style>
                <style:style style:name="cell1" style:family="table-cell">
                    <style:properties fo:text-align="right"
                                      fo:font-size="10pt" style:column-width="5cm" />
                </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:column-width="5cm" />
                </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:column-width="5cm" style:row-height="2cm"/>
                </style:style>
                <style:style style:name="long-Heading2" style:family="table-cell">
                    <style:properties fo:text-align="left"
                                      fo:font-size="10pt" fo:font-weight="bold" style:column-width="10cm" style:row-height="2cm"/>
                </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>
                <style:style style:name="Heading4" style:family="table-cell">
                    <style:properties fo:text-align="right"
                                      fo:font-size="10pt" fo:font-weight="bold" style:column-width="10cm" />
                </style:style>
            </office:automatic-styles>

            <office:body>

                <table:table>
                    <xsl:attribute name="table:name"><xsl:value-of select="'q-1 - q-11'" /></xsl:attribute>

                <xsl:for-each select="./*[local-name(.)= 'q-1' or local-name(.)= 'q-2' or local-name(.)= 'q-3' or local-name(.)= 'q-4'
             or local-name(.)= 'q-5' or local-name(.)= 'q-8' or local-name(.)= 'q-9' or local-name(.)= 'q-10'
              or local-name(.)= 'q-11' or local-name(.)= 'q-13' or local-name(.)= 'q-15']">


                    <table:table-columns>
                    <xsl:choose>


                        <xsl:when test="local-name(.)= 'q-1' ">
                            <table:table-column
                                    table:default-cell-value-type="string"
                                    table:default-cell-style-name="long-string-heading">
                            </table:table-column>
                            <table:table-column
                                    table:default-cell-value-type="string"
                                    table:default-cell-style-name="long-string-heading">
                            </table:table-column>
                            <table:table-column
                                    table:default-cell-value-type="string"
                                    table:default-cell-style-name="long-string-heading">
                            </table:table-column>
                        </xsl:when>
                        <xsl:otherwise>
                            <table:table-column
                                    table:default-cell-value-type="number"
                                    table:default-cell-style-name="string-heading">


                            </table:table-column>
                        </xsl:otherwise>
                    </xsl:choose>
                    </table:table-columns>
                       <table:table-rows>
                              <xsl:apply-templates select="." />
                       </table:table-rows>
                </xsl:for-each>
                </table:table>
                <table:table>
                <xsl:attribute name="table:name"><xsl:value-of select="'q-6-1-1'" /></xsl:attribute>

                    <xsl:for-each select="./q-8/q-8-1-1-table/*">
                        <table:table-columns>

                            <table:table-column
                                    table:default-cell-value-type="string"
                                    table:default-cell-style-name="long-string-heading">
                            </table:table-column>
                            <table:table-column
                                    table:default-cell-value-type="string"
                                    table:default-cell-style-name="long-string-heading">
                            </table:table-column>
                            <table:table-column
                                    table:default-cell-value-type="string"
                                    table:default-cell-style-name="long-string-heading">
                            </table:table-column>
                        </table:table-columns>
                        <table:table-rows>
                            <xsl:call-template name="Q-6-1-1-table"/>
                        </table:table-rows>
                    </xsl:for-each>
                </table:table>
            </office:body>
        </office:document-content>
    </xsl:template>

    <xsl:template match="response/*[local-name(.) != 'q-8-1-1-table' or local-name(.) != 'q-8-1-1-row' or local-name(.) != 'q-8-1-1-1' or local-name(.) != 'q-8-1-1-2' or local-name(.) != 'q-8-1-1-3']">
        <xsl:if test="(position()=1 and local-name(.) ='q-1')">
            <xsl:call-template name="header" />
        </xsl:if>
        <xsl:choose>
            <xsl:when test="local-name(.)='q-8'">
                <table:table-rows>
                    <xsl:for-each select="./*[local-name(.) = 'q-8-1' or local-name(.) = 'q-8-1-r']">
                        <table:table-row>
                            <table:table-cell table:style-name="long-string-cell">
                                <text:p>
                                    <xsl:call-template name="getLabel">
                                        <xsl:with-param name="labelName" select="local-name(.)"/>
                                    </xsl:call-template>
                                </text:p>
                            </table:table-cell>
                            <table:table-cell table:style-name="cell1" table:number-columns-spanned="2">
                                <text:p>
                                    <xsl:value-of select="." />
                                </text:p>
                            </table:table-cell>
                        </table:table-row>
                    </xsl:for-each>
                </table:table-rows>

            </xsl:when>
            <xsl:otherwise>
                <table:table-rows>
                    <xsl:for-each select="./*[local-name(.) != 'q-8-1-1-table' or local-name(.) != 'q-8-1-1-row' or local-name(.) != 'q-8-1-1-1' or local-name(.) != 'q-8-1-1-2' or local-name(.) != 'q-8-1-1-3']">
                        <xsl:choose>
                            <xsl:when test="./*[local-name(.) = 'q-4-3-1' or local-name(.) = 'q-4-3-1-1' or local-name(.) = 'q-4-3-1-2']">
                                <xsl:for-each select="./*">
                                    <table:table-row>
                                        <table:table-cell table:style-name="long-string-cell">
                                            <text:p>
                                                <xsl:call-template name="getLabel">
                                                    <xsl:with-param name="labelName" select="local-name(.)"/>
                                                </xsl:call-template>
                                            </text:p>
                                        </table:table-cell>
                                        <table:table-cell table:style-name="cell1" table:number-columns-spanned="2">
                                            <text:p>
                                                <xsl:call-template name="getValue">
                                                    <xsl:with-param name="value" select="."/>
                                                </xsl:call-template>
                                            </text:p>
                                        </table:table-cell>
                                    </table:table-row>
                                </xsl:for-each>
                            </xsl:when>
                            <xsl:when test="./*[local-name(.) = 'q-5-1' or local-name(.) = 'q-5-1-1' or local-name(.) = 'q-5-1-2'  or local-name(.) = 'q-5-1-3']">
                                <xsl:for-each select="./*">
                                    <table:table-row>
                                        <table:table-cell table:style-name="long-string-cell">
                                            <text:p>
                                                <xsl:call-template name="getLabel">
                                                    <xsl:with-param name="labelName" select="local-name(.)"/>
                                                </xsl:call-template>
                                            </text:p>
                                        </table:table-cell>
                                        <table:table-cell table:style-name="cell1" table:number-columns-spanned="2">
                                            <text:p>
                                                <xsl:value-of select="." />
                                            </text:p>
                                        </table:table-cell>
                                    </table:table-row>
                                </xsl:for-each>
                            </xsl:when>
                            <xsl:when test="./*[local-name(.) = 'q-5-2' or local-name(.) = 'q-5-2-1' or local-name(.) = 'q-5-2-2']">
                                <xsl:for-each select="./*">
                                    <table:table-row>
                                        <table:table-cell table:style-name="long-string-cell">
                                            <text:p>
                                                <xsl:call-template name="getLabel">
                                                    <xsl:with-param name="labelName" select="local-name(.)"/>
                                                </xsl:call-template>
                                            </text:p>
                                        </table:table-cell>
                                        <table:table-cell table:style-name="cell1" table:number-columns-spanned="2">
                                            <text:p>
                                                <xsl:value-of select="." />
                                            </text:p>
                                        </table:table-cell>
                                    </table:table-row>
                                </xsl:for-each>
                            </xsl:when>
                            <xsl:when test="./*[local-name(.) = 'q-5-3' or local-name(.) = 'q-5-3-1' or local-name(.) = 'q-5-3-1-1'  or local-name(.) = 'q-5-3-2' or local-name(.) = 'q-5-3-3' or local-name(.) = 'q-5-3-4' or local-name(.) = 'q-5-3-4-r' ]">
                                <xsl:for-each select="./*">
                                    <table:table-row>
                                        <table:table-cell table:style-name="long-string-cell">
                                            <text:p>
                                                <xsl:choose>
                                                    <xsl:when test="local-name(.) = 'q-5-3-4-r'">
                                                        <xsl:call-template name="getLabel">
                                                            <xsl:with-param name="labelName" select="'q-5-3-1-1'"/>
                                                        </xsl:call-template>
                                                    </xsl:when>
                                                    <xsl:otherwise>
                                                        <xsl:call-template name="getLabel">
                                                            <xsl:with-param name="labelName" select="local-name(.)"/>
                                                        </xsl:call-template>
                                                    </xsl:otherwise>
                                                </xsl:choose>
                                            </text:p>
                                        </table:table-cell>
                                        <table:table-cell table:style-name="cell1" table:number-columns-spanned="2">
                                            <text:p>
                                                <xsl:value-of select="." />
                                            </text:p>
                                        </table:table-cell>
                                    </table:table-row>
                                </xsl:for-each>
                            </xsl:when>
                            <xsl:when test="local-name(.) = 'q-11-1'">
                                <table:table-row>
                                    <table:table-cell table:style-name="long-string-cell">
                                        <text:p>
                                            <xsl:call-template name="getLabel">
                                                <xsl:with-param name="labelName" select="local-name(.)"/>
                                            </xsl:call-template>
                                        </text:p>
                                    </table:table-cell>
                                    <table:table-cell table:style-name="cell1" table:number-columns-spanned="2">
                                        <text:p>
                                        </text:p>
                                    </table:table-cell>
                                </table:table-row>
                                <xsl:for-each select="./*[local-name(.) = 'q-11-1-a' or local-name(.) = 'q-11-1-b' or local-name(.) = 'q-11-1-c' or local-name(.) = 'q-11-1-d']">
                                    <table:table-row>
                                        <table:table-cell table:style-name="long-string-cell">
                                            <text:p>
                                                <xsl:call-template name="getLabel">
                                                    <xsl:with-param name="labelName" select="local-name(.)"/>
                                                </xsl:call-template>
                                            </text:p>
                                        </table:table-cell>
                                        <table:table-cell table:style-name="cell1" table:number-columns-spanned="2">
                                            <text:p>
                                                <xsl:call-template name="getValue">
                                                    <xsl:with-param name="value" select="."/>
                                                </xsl:call-template>
                                            </text:p>
                                        </table:table-cell>
                                    </table:table-row>
                                </xsl:for-each>
                            </xsl:when>
                            <xsl:when test="local-name(.) = 'q-11-2-1'">
                                <table:table-row>
                                    <table:table-cell table:style-name="long-string-cell">
                                        <text:p>
                                            <xsl:call-template name="getLabel">
                                                <xsl:with-param name="labelName" select="local-name(.)"/>
                                            </xsl:call-template>
                                        </text:p>
                                    </table:table-cell>
                                    <table:table-cell table:style-name="cell1" table:number-columns-spanned="2">
                                        <text:p>
                                        </text:p>
                                    </table:table-cell>
                                </table:table-row>
                                <xsl:for-each select="./*[local-name(.) = 'q-11-2-1-a' or local-name(.) = 'q-11-2-1-b' or local-name(.) = 'q-11-2-1-c' or local-name(.) = 'q-11-2-1-d'or local-name(.) = 'q-11-2-1-e']">
                                    <table:table-row>
                                        <table:table-cell table:style-name="long-string-cell">
                                            <text:p>
                                                <xsl:call-template name="getLabel">
                                                    <xsl:with-param name="labelName" select="local-name(.)"/>
                                                </xsl:call-template>
                                            </text:p>
                                        </table:table-cell>
                                        <table:table-cell table:style-name="cell1" table:number-columns-spanned="2">
                                            <text:p>
                                                <xsl:call-template name="getValue">
                                                    <xsl:with-param name="value" select="."/>
                                                </xsl:call-template>
                                            </text:p>
                                        </table:table-cell>
                                    </table:table-row>
                                </xsl:for-each>
                            </xsl:when>
                            <xsl:when test="./*[local-name(.) = 'q-11-3' or local-name(.) = 'q-11-3-1' or local-name(.) = 'q-11-3-2' or local-name(.) = 'q-11-3-3' or local-name(.) = 'q-11-3-4'or local-name(.) = 'q-11-3-5']">
                                <xsl:for-each select="./*">
                                    <table:table-row>
                                        <table:table-cell table:style-name="long-string-cell">
                                            <text:p>
                                                <xsl:call-template name="getLabel">
                                                    <xsl:with-param name="labelName" select="local-name(.)"/>
                                                </xsl:call-template>
                                            </text:p>
                                        </table:table-cell>
                                        <table:table-cell table:style-name="cell1" table:number-columns-spanned="2">
                                            <text:p>
                                                <xsl:call-template name="getValue">
                                                    <xsl:with-param name="value" select="."/>
                                                </xsl:call-template>
                                            </text:p>
                                        </table:table-cell>
                                    </table:table-row>
                                </xsl:for-each>
                            </xsl:when>

                            <xsl:otherwise>
                                <table:table-row>
                                    <table:table-cell table:style-name="long-string-cell">
                                        <text:p>
                                            <xsl:choose>
                                                <xsl:when test="local-name(.) = 'q-15-2-1'">
                                                    <xsl:call-template name="getLabel">
                                                        <xsl:with-param name="labelName" select="'q-15-1-1'"/>
                                                    </xsl:call-template>
                                                </xsl:when>
                                                <xsl:otherwise><xsl:call-template name="getLabel">
                                                    <xsl:with-param name="labelName" select="local-name(.)"/>
                                                </xsl:call-template></xsl:otherwise>
                                            </xsl:choose>
                                        </text:p>
                                    </table:table-cell>
                                    <table:table-cell table:style-name="cell1" table:number-columns-spanned="2">
                                        <text:p>
                                            <xsl:value-of select="." />
                                        </text:p>
                                    </table:table-cell>
                                </table:table-row>
                            </xsl:otherwise>
                        </xsl:choose>


                    </xsl:for-each>
                </table:table-rows>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>
    <xsl:template name="Q-6-1-1-table">
        <table:table-rows>
            <xsl:if test="position()=1">
                <xsl:call-template name="header" />
            </xsl:if>
            <xsl:for-each select=".">

                <table:table-row>
                    <table:table-cell table:style-name="cell1" >
                        <text:p>
                            <xsl:value-of select="./q-8-1-1-1" />
                        </text:p>
                    </table:table-cell>
                    <table:table-cell table:style-name="cell1" >
                        <text:p>
                            <xsl:value-of select="./q-8-1-1-2" />
                        </text:p>
                    </table:table-cell>
                    <table:table-cell table:style-name="cell1" >
                        <text:p>
                            <xsl:value-of select="./q-8-1-1-3" />
                        </text:p>
                    </table:table-cell>
                </table:table-row>
            </xsl:for-each>
        </table:table-rows>
    </xsl:template>

    <!-- a named template, which creates the table header row -->
    <xsl:template name="header">
        <table:table-header-rows>


            <xsl:choose>
                <xsl:when test="local-name(.) = 'q-8-1-1-table' or local-name(.) = 'q-8-1-1-row' or local-name(.) = 'q-8-1-1-1' or local-name(.) = 'q-8-1-1-2' or local-name(.) = 'q-8-1-1-3'">
                    <table:table-row table:default-cell-value-type="string"  >
                        <table:table-cell table:style-name="Heading2">
                            <text:p>
                                Case
                            </text:p>
                        </table:table-cell>
                        <table:table-cell  table:style-name="Heading2">
                            <text:p>
                                Description of the case
                            </text:p>
                        </table:table-cell>
                        <table:table-cell  table:style-name="Heading2">
                            <text:p>
                                Additional measures taken
                            </text:p>
                        </table:table-cell>
                    </table:table-row>
                </xsl:when>
                <xsl:otherwise>
                    <table:table-row table:default-cell-value-type="string"  >
                        <table:table-cell table:style-name="Heading2">
                            <text:p>
                                Question
                            </text:p>
                        </table:table-cell>
                        <table:table-cell table:number-columns-spanned="2" table:style-name="Heading2">
                            <text:p>
                                Answer
                            </text:p>
                        </table:table-cell>
                    </table:table-row>

                </xsl:otherwise>
            </xsl:choose>


        </table:table-header-rows>
    </xsl:template>


    <xsl:template name="getLabel" >
        <xsl:param name="labelName"/>
        <!--<xsl:param name="lang" select="'en'"/>-->
        <xsl:variable name="labelValue" select="$labels/*[local-name() = $labelName]"/>
        <xsl:choose>
            <xsl:when test="string-length($labelValue) &gt; 0">

                   <xsl:value-of select="$labelValue"/>

            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$labelName"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="getValue" >
        <xsl:param name="value"/>
        <!--<xsl:param name="lang" select="'en'"/>-->

        <xsl:choose>
            <xsl:when test="$value = 'true'">

                <xsl:value-of select="'yes'"/>

            </xsl:when>
            <xsl:when test="$value = 'false'">

                <xsl:value-of select="'no'"/>

            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$value"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


</xsl:stylesheet>