View stylesheet

XML schema http://www.eionet.europa.eu/schemas/ippc-wi/dir200076_schema.xsd
Output type HTML
Description Simple HTML factsheet
XSL file dir200076_html.xsl (Last modified: 10 Aug 2009 17:48 )
<?xml version="1.0" encoding="utf-8"?>
<!-- $Id: dir200076_html.xsl 246 2009-07-23 16:35:36Z sebf $ -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:output method="html" encoding="utf-8"/>
    <xsl:param name="xml_folder_uri"/>
    <xsl:variable name="directiveid">200076</xsl:variable>
    <xsl:variable name="directiveidfull" select="concat('Quest', $directiveid, '-')"/>
    <xsl:variable name="labels" select="document(concat($xml_folder_uri,concat('dir', $directiveid, '_xsl_labels.xml')))/labels/itemset[@xml:lang='en']"/>



    <xsl:template match="text()"/>

    <xsl:template match="Questionnaire">
        <html>
            <head>
                <title>
                    Factsheet of WI delivery
                </title>
                <style type="text/css">
                table { border: 1px solid black; border-collapse: collapse}
                table th, table td { text-align: left; border: 1px solid black; }
                table caption { border: 1px solid black; font-weight: bold; }
                .tophead, .questionid { background-color:#CCCCCC; }
                .newRow { background-color:#FCD5B4; }
                </style>
            </head>
            <body>
                <table class="bluetable">
                    <col style="width:15%"/>
                    <col style="width:30%"/>
                    <col style="width:55%"/>
                    <tr class="tophead">
                        <th>Question ID</th>
                        <th>Question</th>
                        <th>Answer</th>
                    </tr>

                    <xsl:apply-templates/>
                </table>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="*">
        <tr>
            <xsl:choose>
                <xsl:when test="contains(local-name(), '-table')">
                    <td colspan="3">
                        <xsl:call-template name="display_table"/>
                    </td>
                </xsl:when>
                <xsl:otherwise>
                    <th class="questionid"><xsl:value-of select="local-name()"/></th>
                    <th><xsl:call-template name="display_label_or_id"/></th>
                    <td><xsl:value-of select="text()"/></td>
                </xsl:otherwise>
            </xsl:choose>
        </tr>
    </xsl:template>

    <xsl:template name="display_label_or_id">
        <!-- Remove directive id -->
        <xsl:variable name="questionid" select="substring-after(local-name(),$directiveidfull)"/>

        <!-- Get question label or id -->
        <xsl:choose>
            <xsl:when test="$labels/item[@id=$questionid] != ''">
                <xsl:value-of select="$labels/item[@id=$questionid]"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="local-name()"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="display_table">
        <table>
            <caption><xsl:value-of select="local-name()" /></caption>
            <col style="width:15%"/>
            <col style="width:30%"/>
            <col style="width:55%"/>
            <tr class="tophead">
                <th>Question ID</th>
                <th>Question</th>
                <th>Answer</th>
            </tr>

            <xsl:for-each select="*">
                    <tr><th colspan="3" class="newRow"><xsl:value-of select="local-name()" /> <xsl:value-of select="position()" /></th></tr>
                    <xsl:for-each select="*">
                        <tr>
                            <th class="questionid"><xsl:value-of select="local-name()"/></th>
                            <th><xsl:call-template name="display_table_label_or_id"/></th>
                            <td><xsl:value-of select="text()" /></td>
                        </tr>
                    </xsl:for-each>
            </xsl:for-each>
        </table>
    </xsl:template>

    <xsl:template name="display_table_label_or_id">
        <!-- Remove directive id -->
        <xsl:variable name="questionid" select="local-name()"/>

        <!-- Get question label or id -->
        <xsl:choose>
            <xsl:when test="$labels/item[@id=$questionid] != ''">
                <xsl:value-of select="$labels/item[@id=$questionid]"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="local-name()"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>