root/šablona/stránka.xsl @ 19:b81b96475fe0

Revision 19:b81b96475fe0, 4.5 KB (checked in by František Kučera <franta-hg@…>, 13 years ago)

Vyčlenění uživatelských maker do samostatného souboru: #8

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"
[18]5        xmlns:s="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
6        xmlns:k="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/konfigurace"
[17]7        xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
[2]8        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
9        xmlns:fn="http://www.w3.org/2005/xpath-functions"
[5]10        xmlns:svg="http://www.w3.org/2000/svg"
[15]11        xmlns:xs="http://www.w3.org/2001/XMLSchema"
[19]12        exclude-result-prefixes="fn h s k m xs">
[2]13        <xsl:output 
14                method="xml" 
15                indent="yes" 
16                encoding="UTF-8"               
17                doctype-public="-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" 
18                doctype-system="http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"/>
[19]19               
[11]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       
[19]26        <xsl:include href="makra.xsl"/>
27       
[5]28        <!-- Celý dokument: -->
[1]29        <xsl:template match="/">
[11]30                <xsl:variable name="konfigurace" select="document(concat($vstup, 'web.conf'))"/>
[1]31                <html>
32                        <head>
[16]33                                <xsl:if test="$podporaZaostalýchProhlížečů">
34                                        <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
35                                </xsl:if>
[18]36                                <title><xsl:value-of select="s:stránka/s:nadpis"/></title>
[8]37                                <link title="Novinky (Atom)" href="atom.xml" type="application/atom+xml" rel="alternate"/>
[10]38                                <link title="Novinky (RSS)"  href="rss.xml"  type="application/rss+xml"  rel="alternate"/>
[18]39                                <xsl:apply-templates select="$konfigurace/k:web/k:js"/>
40                                <xsl:apply-templates select="$konfigurace/k:web/k:css"/>                               
[1]41                        </head>
42                        <body>
[12]43                                <div id="tělo">
44                                        <div id="záhlaví">
[18]45                                                <xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'záhlaví', $vsuvkováPřípona)))/s:stránka/h:text/node()"/>
[12]46                                        </div>
47                                        <div id="vnitřek">
[18]48                                                <h1><xsl:value-of select="s:stránka/s:nadpis"/></h1>
[12]49                                                <ul id="nabídka">
[18]50                                                        <xsl:for-each select="collection(concat('../vstup/?select=*', $vstupníPřípona))[s:stránka/s:pořadí]">
51                                                                <xsl:sort select="empty(./s:stránka/s:pořadí)"/>
52                                                                <xsl:sort select="./s:stránka/s:pořadí"/>
[12]53                                                                <li>
54                                                                        <xsl:variable name="xmlSoubor" select="tokenize(document-uri(.), '/')[last()]"/>
[15]55                                                                        <xsl:variable name="xhtmlSoubor" select="replace($xmlSoubor, $vstupníPřípona, $výstupníPřípona)"/>
[18]56                                                                        <a href="{fn:encode-for-uri($xhtmlSoubor)}"><xsl:value-of select="./s:stránka/s:nadpis"/></a>
[12]57                                                                </li>
58                                                        </xsl:for-each>
59                                                </ul>
60                                                <div id="text">
[18]61                                                        <xsl:apply-templates select="s:stránka/h:text/node()"/>
[12]62                                                </div>
63                                        </div>
64                                        <div id="zápatí">
[18]65                                                <xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'zápatí', $vsuvkováPřípona)))/s:stránka/h:text/node()"/>
[12]66                                        </div>
67                                </div>
[1]68                        </body>
69                </html>
70        </xsl:template>
71       
[5]72        <!-- Kopírujeme elementy, ale vynecháme nepoužité xmlns deklarace: -->
73        <xsl:template match="*">
74                <xsl:element name="{name()}">
75                        <xsl:copy-of select="@*"/>
76                        <xsl:apply-templates/>
77                </xsl:element>
78    </xsl:template>
[10]79   
[18]80    <!-- Varování pro případ, že jsme v režimu podpory pro zaostalé prohlížeče -->
[15]81    <xsl:template name="varováníRetardace">
82        <xsl:if test="$podporaZaostalýchProhlížečů">
83                        <xsl:comment>
84                                Generátor byl spuštěn v režimu podpory zaostalých prohlížečů.
85                                Uživatelům doporučujeme upgrade na skutečný WWW prohlížeč,
86                                jako je např. Firefox nebo Chromium (případně Opera či Safari).
87                        </xsl:comment>
88        </xsl:if>
[18]89    </xsl:template>
90
91    <!-- Odkazy na JavaScript a kaskádové styly -->   
92    <xsl:template match="k:web/k:js">           
[15]93        <script src="{text()}" type="text/javascript">
94                <xsl:call-template name="varováníRetardace"/>
95        </script>
[10]96    </xsl:template>
[18]97    <xsl:template match="k:web/k:css">
[10]98        <link href="{text()}" type="text/css" rel="StyleSheet" />
99    </xsl:template>
[17]100   
101    <!--
102        Makro pro převod interních odkazů:
103                - doplnění správné přípony
104                - URL kódování znaků
105    -->
106    <xsl:template match="m:a">
107        <a>
108                <xsl:copy-of select="@*"/>
109                <xsl:attribute name="href">
110                        <xsl:value-of select="fn:encode-for-uri(concat(@href, $výstupníPřípona))"/>
111                </xsl:attribute>
112                <xsl:apply-templates/>
113        </a>
114    </xsl:template>
[1]115
116</xsl:stylesheet>
Note: See TracBrowser for help on using the browser.