šablona/stránka-společné.xsl
author František Kučera <franta-hg@frantovo.cz>
Sun, 23 Jun 2013 16:29:22 +0200
changeset 126 be52f52e7d39
parent 87 25dec6931f18
child 127 4b02189672db
permissions -rw-r--r--
XHTML metadata: autor + popis stránky
     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 		Metainformace o autorovi a popisu stránky
    80 	-->
    81 	<xsl:template match="k:web/k:autor/k:jméno">
    82 		<meta content="{text()}" name="author"/>
    83 	</xsl:template>
    84 	<xsl:template match="s:stránka/s:perex">
    85 		<meta content="{text()}" name="description"/>
    86 	</xsl:template>
    87 
    88 	<!--
    89 		Vloží nečíslovaný seznam obsahující hlavní nabídku webu (seznam stránek)
    90 		Pro potřeby CSS stylování má nabídka @id='nabídka'
    91 	-->
    92 	<xsl:template name="vložNabídku">
    93 		<ul id="nabídka">
    94 			<xsl:for-each select="collection(concat('./', $vstup ,'/?select=*', $vstupníPřípona))[s:stránka/s:pořadí]">
    95 				<xsl:sort select="empty(./s:stránka/s:pořadí)"/>
    96 				<xsl:sort select="./s:stránka/s:pořadí"/>
    97 				<li>
    98 					<xsl:variable name="xmlSoubor" select="tokenize(document-uri(.), '/')[last()]"/>
    99 					<xsl:variable name="xhtmlSoubor" select="replace($xmlSoubor, $vstupníPřípona, $výstupníPřípona)"/>
   100 					<a href="{fn:encode-for-uri($xhtmlSoubor)}"><xsl:value-of select="./s:stránka/s:nadpis"/></a>
   101 				</li>
   102 			</xsl:for-each>
   103 		</ul>
   104 	</xsl:template>
   105 
   106 	<!--
   107 		Vloží záhlaví (společné pro všechny stránky)
   108 		Pro potřeby CSS stylování má @id='záhlaví'
   109 	-->
   110 	<xsl:template name="vložZáhlaví">
   111 		<div id="záhlaví">
   112 			<xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'záhlaví', $vsuvkováPřípona)))/s:stránka/h:text/node()"/>
   113 		</div>
   114 	</xsl:template>
   115 
   116 	<!--
   117 		Vloží zápatí (společné pro všechny stránky)
   118 		Pro potřeby CSS stylování má @id='zápatí'
   119 	-->
   120 	<xsl:template name="vložZápatí">
   121 		<div id="zápatí">
   122 			<xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'zápatí', $vsuvkováPřípona)))/s:stránka/h:text/node()"/>
   123 		</div>
   124 	</xsl:template>
   125 
   126 	<!--
   127 		Vrací cestu v URL kódování, ale lomítka nekóduje
   128 	-->
   129 	<xsl:function name="m:escapuj-url-zachovej-lomítka" as="xs:string">
   130 		<xsl:param name="cesta"/>
   131 		<xsl:value-of select="replace(encode-for-uri($cesta), '%2F', '/')"/>
   132 	</xsl:function>
   133 
   134 	<!--
   135 		Vrací obsah textového souboru ve vstupním adresáři.
   136 		Obvykle jako parametr předáváme atribut „src“.
   137 	-->
   138 	<xsl:function name="m:načti-textový-soubor" as="xs:string">
   139 		<xsl:param name="soubor"/>
   140 		<xsl:value-of select="unparsed-text(concat($vstup, $soubor))"/>
   141 	</xsl:function>
   142 
   143 </xsl:stylesheet>
   144