šablona/stránka-společné.xsl
author František Kučera <franta-hg@frantovo.cz>
Sat, 14 Jan 2012 19:10:26 +0100
changeset 87 25dec6931f18
parent 77 2f11f0ba6f13
child 126 be52f52e7d39
permissions -rw-r--r--
Lepší odsazení, tabulátory.
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <!--
     3 XML Web generátor – program na generování webových stránek
     4 Copyright © 2012 František Kučera (frantovo.cz)
     5 
     6 This program is free software: you can redistribute it and/or modify
     7 it under the terms of the GNU General Public License as published by
     8 the Free Software Foundation, either version 3 of the License, or
     9 (at your option) any later version.
    10 
    11 This program is distributed in the hope that it will be useful,
    12 but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14 GNU General Public License for more details.
    15 
    16 You should have received a copy of the GNU General Public License
    17 along with this program.  If not, see <http://www.gnu.org/licenses/>.
    18 -->
    19 <xsl:stylesheet version="2.0"
    20 	xmlns="http://www.w3.org/1999/xhtml"
    21 	xmlns:h="http://www.w3.org/1999/xhtml"
    22 	xmlns:s="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
    23 	xmlns:k="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/konfigurace"
    24 	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
    25 	xmlns:j="java:cz.frantovo.xmlWebGenerator.Funkce"
    26 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    27 	xmlns:fn="http://www.w3.org/2005/xpath-functions"
    28 	xmlns:svg="http://www.w3.org/2000/svg"
    29 	xmlns:xs="http://www.w3.org/2001/XMLSchema"
    30 	exclude-result-prefixes="fn h s k m j xs">
    31 	
    32 	<xsl:param name="vstup" select="'../vstup/'"/>
    33 	<xsl:param name="výstup" select="'../výstup/'"/>
    34 	<xsl:param name="vstupníPřípona" select="'.xml'"/>
    35 	<xsl:param name="výstupníPřípona" select="'.xhtml'"/>
    36 	<xsl:param name="vsuvkováPřípona" select="'.inc'"/>
    37 	<xsl:param name="podporaZaostalýchProhlížečů" select="false()" as="xs:boolean"/>
    38 	
    39 	<xsl:variable name="konfigurace" select="document(concat($vstup, 'web.conf'))"/>
    40 	
    41 	<xsl:include href=".makra-seznam.xsl"/>
    42 	
    43 	<!--
    44 		Kopírujeme elementy, ale vynecháme nepoužité xmlns deklarace:
    45 	-->
    46 	<xsl:template match="*">
    47 		<xsl:element name="{name()}">
    48 			<xsl:copy-of select="@*"/>
    49 			<xsl:apply-templates/>
    50 		</xsl:element>
    51 	</xsl:template>
    52 
    53 	<!--
    54 		Varování pro případ, že jsme v režimu podpory pro zaostalé prohlížeče
    55 	-->
    56 	<xsl:template name="varováníRetardace">
    57 		<xsl:if test="$podporaZaostalýchProhlížečů">
    58 			<xsl:comment>
    59 				Generátor byl spuštěn v režimu podpory zaostalých prohlížečů.
    60 				Uživatelům doporučujeme upgrade na skutečný WWW prohlížeč,
    61 				jako je např. Firefox nebo Chromium (případně Opera či Safari).
    62 			</xsl:comment>
    63 		</xsl:if>
    64 	</xsl:template>
    65 
    66 	<!-- 
    67 		Odkazy na JavaScript a kaskádové styly
    68 	-->    
    69 	<xsl:template match="k:web/k:js">
    70 		<script src="{text()}" type="text/javascript">
    71 			<xsl:call-template name="varováníRetardace"/>
    72 		</script>
    73 	</xsl:template>
    74 	<xsl:template match="k:web/k:css">
    75 		<link href="{text()}" type="text/css" rel="StyleSheet" />
    76 	</xsl:template>
    77 
    78 	<!--
    79 		Vloží nečíslovaný seznam obsahující hlavní nabídku webu (seznam stránek)
    80 		Pro potřeby CSS stylování má nabídka @id='nabídka'
    81 	-->
    82 	<xsl:template name="vložNabídku">
    83 		<ul id="nabídka">
    84 			<xsl:for-each select="collection(concat('./', $vstup ,'/?select=*', $vstupníPřípona))[s:stránka/s:pořadí]">
    85 				<xsl:sort select="empty(./s:stránka/s:pořadí)"/>
    86 				<xsl:sort select="./s:stránka/s:pořadí"/>
    87 				<li>
    88 					<xsl:variable name="xmlSoubor" select="tokenize(document-uri(.), '/')[last()]"/>
    89 					<xsl:variable name="xhtmlSoubor" select="replace($xmlSoubor, $vstupníPřípona, $výstupníPřípona)"/>
    90 					<a href="{fn:encode-for-uri($xhtmlSoubor)}"><xsl:value-of select="./s:stránka/s:nadpis"/></a>
    91 				</li>
    92 			</xsl:for-each>
    93 		</ul>
    94 	</xsl:template>
    95 
    96 	<!--
    97 		Vloží záhlaví (společné pro všechny stránky)
    98 		Pro potřeby CSS stylování má @id='záhlaví'
    99 	-->
   100 	<xsl:template name="vložZáhlaví">
   101 		<div id="záhlaví">
   102 			<xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'záhlaví', $vsuvkováPřípona)))/s:stránka/h:text/node()"/>
   103 		</div>
   104 	</xsl:template>
   105 
   106 	<!--
   107 		Vloží zápatí (společné pro všechny stránky)
   108 		Pro potřeby CSS stylování má @id='zápatí'
   109 	-->
   110 	<xsl:template name="vložZápatí">
   111 		<div id="zápatí">
   112 			<xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'zápatí', $vsuvkováPřípona)))/s:stránka/h:text/node()"/>
   113 		</div>
   114 	</xsl:template>
   115 
   116 	<!--
   117 		Vrací cestu v URL kódování, ale lomítka nekóduje
   118 	-->
   119 	<xsl:function name="m:escapuj-url-zachovej-lomítka" as="xs:string">
   120 		<xsl:param name="cesta"/>
   121 		<xsl:value-of select="replace(encode-for-uri($cesta), '%2F', '/')"/>
   122 	</xsl:function>
   123 
   124 	<!--
   125 		Vrací obsah textového souboru ve vstupním adresáři.
   126 		Obvykle jako parametr předáváme atribut „src“.
   127 	-->
   128 	<xsl:function name="m:načti-textový-soubor" as="xs:string">
   129 		<xsl:param name="soubor"/>
   130 		<xsl:value-of select="unparsed-text(concat($vstup, $soubor))"/>
   131 	</xsl:function>
   132 
   133 </xsl:stylesheet>
   134