root/šablona/stránka.xsl @ 17:02bad17b4590

Revision 17:02bad17b4590, 5.3 KB (checked in by František Kučera <franta-hg@…>, 13 years ago)

Logo v záhlaví → odkaz na titulní stránku (makro pro interní odkazy).

RevLine 
[1]1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet version="2.0"
3        xmlns="http://www.w3.org/1999/xhtml"
[2]4        xmlns:h="http://www.w3.org/1999/xhtml"
5        xmlns:g="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/prostor"
[17]6        xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
[2]7        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
8        xmlns:fn="http://www.w3.org/2005/xpath-functions"
[5]9        xmlns:svg="http://www.w3.org/2000/svg"
[15]10        xmlns:xs="http://www.w3.org/2001/XMLSchema"
[17]11        exclude-result-prefixes="fn h g xs m">
[2]12        <xsl:output 
13                method="xml" 
14                indent="yes" 
15                encoding="UTF-8"               
16                doctype-public="-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" 
17                doctype-system="http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"/>
[11]18       
19        <!-- Vstupní adresář: -->
20        <xsl:param name="vstup" select="'../vstup/'"/>
[15]21        <xsl:param name="vstupníPřípona" select="'.xml'"/>
22        <xsl:param name="výstupníPřípona" select="'.xhtml'"/>
23        <xsl:param name="vsuvkováPřípona" select="'.inc'"/>
24        <xsl:param name="podporaZaostalýchProhlížečů" select="false()" as="xs:boolean"/>
[1]25       
[5]26        <!-- Celý dokument: -->
[1]27        <xsl:template match="/">
[11]28                <xsl:variable name="konfigurace" select="document(concat($vstup, 'web.conf'))"/>
[1]29                <html>
30                        <head>
[16]31                                <xsl:if test="$podporaZaostalýchProhlížečů">
32                                        <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
33                                </xsl:if>
[6]34                                <title><xsl:value-of select="g:stránka/g:nadpis"/></title>
[8]35                                <link title="Novinky (Atom)" href="atom.xml" type="application/atom+xml" rel="alternate"/>
[10]36                                <link title="Novinky (RSS)"  href="rss.xml"  type="application/rss+xml"  rel="alternate"/>
37                                <xsl:apply-templates select="$konfigurace/g:web/g:js"/>
38                                <xsl:apply-templates select="$konfigurace/g:web/g:css"/>                               
[1]39                        </head>
40                        <body>
[12]41                                <div id="tělo">
42                                        <div id="záhlaví">
[15]43                                                <xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'záhlaví', $vsuvkováPřípona)))/g:stránka/h:text/node()"/>
[12]44                                        </div>
45                                        <div id="vnitřek">
46                                                <h1><xsl:value-of select="g:stránka/g:nadpis"/></h1>
47                                                <ul id="nabídka">
[15]48                                                        <xsl:for-each select="collection(concat('../vstup/?select=*', $vstupníPřípona))[g:stránka/g:pořadí]">
[12]49                                                                <xsl:sort select="empty(./g:stránka/g:pořadí)"/>
50                                                                <xsl:sort select="./g:stránka/g:pořadí"/>
51                                                                <li>
52                                                                        <xsl:variable name="xmlSoubor" select="tokenize(document-uri(.), '/')[last()]"/>
[15]53                                                                        <xsl:variable name="xhtmlSoubor" select="replace($xmlSoubor, $vstupníPřípona, $výstupníPřípona)"/>
[12]54                                                                        <a href="{fn:encode-for-uri($xhtmlSoubor)}"><xsl:value-of select="./g:stránka/g:nadpis"/></a>
55                                                                </li>
56                                                        </xsl:for-each>
57                                                </ul>
58                                                <div id="text">
59                                                        <xsl:apply-templates select="g:stránka/h:text/node()"/>
60                                                </div>
61                                        </div>
62                                        <div id="zápatí">
[15]63                                                <xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'zápatí', $vsuvkováPřípona)))/g:stránka/h:text/node()"/>
[12]64                                        </div>
65                                </div>
[1]66                        </body>
67                </html>
68        </xsl:template>
69       
[5]70        <!-- Kopírujeme elementy, ale vynecháme nepoužité xmlns deklarace: -->
71        <xsl:template match="*">
72                <xsl:element name="{name()}">
73                        <xsl:copy-of select="@*"/>
74                        <xsl:apply-templates/>
75                </xsl:element>
76    </xsl:template>
[10]77   
[11]78    <!-- Odkazy na JavaScript a kaskádové styly -->
[15]79    <xsl:template name="varováníRetardace">
80        <xsl:if test="$podporaZaostalýchProhlížečů">
81                        <xsl:comment>
82                                Generátor byl spuštěn v režimu podpory zaostalých prohlížečů.
83                                Uživatelům doporučujeme upgrade na skutečný WWW prohlížeč,
84                                jako je např. Firefox nebo Chromium (případně Opera či Safari).
85                        </xsl:comment>
86        </xsl:if>
87    </xsl:template>   
88    <xsl:template match="g:web/g:js">           
89        <script src="{text()}" type="text/javascript">
90                <xsl:call-template name="varováníRetardace"/>
91        </script>
[10]92    </xsl:template>
93    <xsl:template match="g:web/g:css">
94        <link href="{text()}" type="text/css" rel="StyleSheet" />
95    </xsl:template>
[17]96   
97    <!--
98        Makro pro převod interních odkazů:
99                - doplnění správné přípony
100                - URL kódování znaků
101    -->
102    <xsl:template match="m:a">
103        <a>
104                <xsl:copy-of select="@*"/>
105                <xsl:attribute name="href">
106                        <xsl:value-of select="fn:encode-for-uri(concat(@href, $výstupníPřípona))"/>
107                </xsl:attribute>
108                <xsl:apply-templates/>
109        </a>
110    </xsl:template>
[10]111   
112    <!-- Ukázka vlastního „makra“: -->
113    <xsl:template match="g:měřák">
114        <xsl:variable name="hodnota" select="number(@hodnota)"/>
115        <xsl:variable name="šířkaGrafu" select="128"/>
116                <xsl:choose>                   
117                        <xsl:when test="$hodnota &gt;= 0 and $hodnota &lt;= 100">                               
118                                <div style="border: 1px solid black; width: {$šířkaGrafu}px; height: 16px; padding: 0px; text-align: center; background-color: #cfc;">                 
[16]119                                        <div style="margin: 0px; background-color: #A4E666; width: {@hodnota*$šířkaGrafu div 100}px; height: 16px;"><xsl:call-template name="varováníRetardace"/></div>
[10]120                                        <p style="margin: 0px; font-size: 12px; position: relative; top: -15px;">
121                                                <xsl:value-of select="@hodnota"/>/100
122                                        </p>   
123                                </div>
124                        </xsl:when>
125                        <xsl:otherwise>
126                                <xsl:message terminate="yes">Hodnota měřáku musí být nejméně 0 a nejvíce 100 (udává procenta).</xsl:message>
127                        </xsl:otherwise>
128                </xsl:choose>
129        </xsl:template>
[1]130
131</xsl:stylesheet>
Note: See TracBrowser for help on using the browser.