root/šablona/stránka.xsl @ 11:78a8dd1eeb2b

Revision 11:78a8dd1eeb2b, 3.6 KB (checked in by František Kučera <franta-hg@…>, 13 years ago)

statický obsah a úloha pro čištění

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"
6        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7        xmlns:fn="http://www.w3.org/2005/xpath-functions"
[5]8        xmlns:svg="http://www.w3.org/2000/svg"
[2]9        exclude-result-prefixes="fn h g">
10        <xsl:output 
11                method="xml" 
12                indent="yes" 
13                encoding="UTF-8"               
14                doctype-public="-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" 
15                doctype-system="http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"/>
[11]16       
17        <!-- Vstupní adresář: -->
18        <xsl:param name="vstup" select="'../vstup/'"/>
[1]19       
[5]20        <!-- Celý dokument: -->
[1]21        <xsl:template match="/">
[11]22                <xsl:variable name="konfigurace" select="document(concat($vstup, 'web.conf'))"/>
[1]23                <html>
24                        <head>
[6]25                                <title><xsl:value-of select="g:stránka/g:nadpis"/></title>
[8]26                                <link title="Novinky (Atom)" href="atom.xml" type="application/atom+xml" rel="alternate"/>
[10]27                                <link title="Novinky (RSS)"  href="rss.xml"  type="application/rss+xml"  rel="alternate"/>
28                                <xsl:apply-templates select="$konfigurace/g:web/g:js"/>
29                                <xsl:apply-templates select="$konfigurace/g:web/g:css"/>                               
[1]30                        </head>
31                        <body>
[11]32                                <xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'záhlaví.inc')))/g:stránka/h:text/node()"/>                     
[3]33                                <h1><xsl:value-of select="g:stránka/g:nadpis"/></h1>
[2]34                                <xsl:apply-templates select="g:stránka/h:text/node()"/>
[4]35                                <ul id="nabídka">
36                                        <xsl:for-each select="collection('../vstup/?select=*.xml')[g:stránka/g:pořadí]">
37                                                <xsl:sort select="empty(./g:stránka/g:pořadí)"/>
38                                                <xsl:sort select="./g:stránka/g:pořadí"/>
39                                                <li>
40                                                        <xsl:variable name="xmlSoubor" select="tokenize(document-uri(.), '/')[last()]"/>
41                                                        <xsl:variable name="xhtmlSoubor" select="replace($xmlSoubor, '.xml', '.xhtml')"/>
42                                                        <a href="{fn:encode-for-uri($xhtmlSoubor)}"><xsl:value-of select="./g:stránka/g:nadpis"/></a>
43                                                </li>
44                                        </xsl:for-each>
45                                </ul>
[11]46                                <xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'zápatí.inc')))/g:stránka/h:text/node()"/>                               
[1]47                        </body>
48                </html>
49        </xsl:template>
50       
[5]51        <!-- Kopírujeme elementy, ale vynecháme nepoužité xmlns deklarace: -->
52        <xsl:template match="*">
53                <xsl:element name="{name()}">
54                        <xsl:copy-of select="@*"/>
55                        <xsl:apply-templates/>
56                </xsl:element>
57    </xsl:template>
[10]58   
[11]59    <!-- Odkazy na JavaScript a kaskádové styly -->
[10]60    <xsl:template match="g:web/g:js">
61        <script src="{text()}" type="text/javascript" />
62    </xsl:template>
63    <xsl:template match="g:web/g:css">
64        <link href="{text()}" type="text/css" rel="StyleSheet" />
65    </xsl:template>
66   
67    <!-- Ukázka vlastního „makra“: -->
68    <xsl:template match="g:měřák">
69        <xsl:variable name="hodnota" select="number(@hodnota)"/>
70        <xsl:variable name="šířkaGrafu" select="128"/>
71                <xsl:choose>                   
72                        <xsl:when test="$hodnota &gt;= 0 and $hodnota &lt;= 100">                               
73                                <div style="border: 1px solid black; width: {$šířkaGrafu}px; height: 16px; padding: 0px; text-align: center; background-color: #cfc;">                 
74                                        <div style="margin: 0px; background-color: #A4E666; width: {@hodnota*$šířkaGrafu div 100}px; height: 16px;"/>
75                                        <p style="margin: 0px; font-size: 12px; position: relative; top: -15px;">
76                                                <xsl:value-of select="@hodnota"/>/100
77                                        </p>   
78                                </div>
79                        </xsl:when>
80                        <xsl:otherwise>
81                                <xsl:message terminate="yes">Hodnota měřáku musí být nejméně 0 a nejvíce 100 (udává procenta).</xsl:message>
82                        </xsl:otherwise>
83                </xsl:choose>
84        </xsl:template>
[1]85
86</xsl:stylesheet>
Note: See TracBrowser for help on using the browser.