root/šablona/stránka.xsl @ 10:4e70453a027f

Revision 10:4e70453a027f, 3.5 KB (checked in by František Kučera <franta-hg@…>, 13 years ago)

Ukázka uživatelského „makra“ a vkládání odkazů na CSS a JS soubory.

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