šablona/stránka.xsl
author František Kučera <franta-hg@frantovo.cz>
Sat Apr 30 19:34:55 2011 +0200 (2011-04-30)
changeset 18 45e41566f8a6
parent 17 02bad17b4590
child 19 b81b96475fe0
permissions -rw-r--r--
Nové jmenné prostory: „s“ a „k“ místo „g“.
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <xsl:stylesheet version="2.0"
     3 	xmlns="http://www.w3.org/1999/xhtml"
     4 	xmlns:h="http://www.w3.org/1999/xhtml"
     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"
     7 	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
     8 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     9 	xmlns:fn="http://www.w3.org/2005/xpath-functions"
    10 	xmlns:svg="http://www.w3.org/2000/svg"
    11 	xmlns:xs="http://www.w3.org/2001/XMLSchema"
    12 	exclude-result-prefixes="fn h s k xs m">
    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 	
    20 	<!-- Vstupní adresář: -->
    21 	<xsl:param name="vstup" select="'../vstup/'"/>
    22 	<xsl:param name="vstupníPřípona" select="'.xml'"/>
    23 	<xsl:param name="výstupníPřípona" select="'.xhtml'"/>
    24 	<xsl:param name="vsuvkováPřípona" select="'.inc'"/>
    25 	<xsl:param name="podporaZaostalýchProhlížečů" select="false()" as="xs:boolean"/>
    26 	
    27 	<!-- Celý dokument: -->
    28 	<xsl:template match="/">
    29 		<xsl:variable name="konfigurace" select="document(concat($vstup, 'web.conf'))"/>
    30 		<html>
    31 			<head>
    32 				<xsl:if test="$podporaZaostalýchProhlížečů">
    33 					<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
    34 				</xsl:if>
    35 				<title><xsl:value-of select="s:stránka/s:nadpis"/></title>
    36 				<link title="Novinky (Atom)" href="atom.xml" type="application/atom+xml" rel="alternate"/>
    37 				<link title="Novinky (RSS)"  href="rss.xml"  type="application/rss+xml"  rel="alternate"/>
    38 				<xsl:apply-templates select="$konfigurace/k:web/k:js"/>
    39 				<xsl:apply-templates select="$konfigurace/k:web/k:css"/>				
    40 			</head>
    41 			<body>
    42 				<div id="tělo">
    43 					<div id="záhlaví">
    44 						<xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'záhlaví', $vsuvkováPřípona)))/s:stránka/h:text/node()"/>
    45 					</div>
    46 					<div id="vnitřek">
    47 						<h1><xsl:value-of select="s:stránka/s:nadpis"/></h1>
    48 						<ul id="nabídka">
    49 							<xsl:for-each select="collection(concat('../vstup/?select=*', $vstupníPřípona))[s:stránka/s:pořadí]">
    50 								<xsl:sort select="empty(./s:stránka/s:pořadí)"/>
    51 								<xsl:sort select="./s:stránka/s:pořadí"/>
    52 								<li>
    53 									<xsl:variable name="xmlSoubor" select="tokenize(document-uri(.), '/')[last()]"/>
    54 									<xsl:variable name="xhtmlSoubor" select="replace($xmlSoubor, $vstupníPřípona, $výstupníPřípona)"/>
    55 									<a href="{fn:encode-for-uri($xhtmlSoubor)}"><xsl:value-of select="./s:stránka/s:nadpis"/></a>
    56 								</li>
    57 							</xsl:for-each>
    58 						</ul>
    59 						<div id="text">
    60 							<xsl:apply-templates select="s:stránka/h:text/node()"/>
    61 						</div>
    62 					</div>
    63 					<div id="zápatí">
    64 						<xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'zápatí', $vsuvkováPřípona)))/s:stránka/h:text/node()"/>
    65 					</div>
    66 				</div>
    67 			</body>
    68 		</html>
    69 	</xsl:template>
    70 	
    71 	<!-- Kopírujeme elementy, ale vynecháme nepoužité xmlns deklarace: -->
    72 	<xsl:template match="*">
    73 		<xsl:element name="{name()}">
    74 			<xsl:copy-of select="@*"/>
    75 			<xsl:apply-templates/>
    76 		</xsl:element>
    77     </xsl:template>
    78     
    79     <!-- Varování pro případ, že jsme v režimu podpory pro zaostalé prohlížeče -->
    80     <xsl:template name="varováníRetardace">
    81     	<xsl:if test="$podporaZaostalýchProhlížečů">
    82 			<xsl:comment>
    83 				Generátor byl spuštěn v režimu podpory zaostalých prohlížečů.
    84 				Uživatelům doporučujeme upgrade na skutečný WWW prohlížeč,
    85 				jako je např. Firefox nebo Chromium (případně Opera či Safari).
    86 			</xsl:comment>
    87     	</xsl:if>
    88     </xsl:template>
    89 
    90     <!-- Odkazy na JavaScript a kaskádové styly -->    
    91     <xsl:template match="k:web/k:js">    	
    92     	<script src="{text()}" type="text/javascript">
    93     		<xsl:call-template name="varováníRetardace"/>
    94     	</script>
    95     </xsl:template>
    96     <xsl:template match="k:web/k:css">
    97     	<link href="{text()}" type="text/css" rel="StyleSheet" />
    98     </xsl:template>
    99    
   100     <!--
   101     	Makro pro převod interních odkazů:
   102     		- doplnění správné přípony
   103     		- URL kódování znaků
   104     -->
   105     <xsl:template match="m:a">
   106     	<a>
   107     		<xsl:copy-of select="@*"/>
   108     		<xsl:attribute name="href">
   109     			<xsl:value-of select="fn:encode-for-uri(concat(@href, $výstupníPřípona))"/>
   110     		</xsl:attribute>
   111     		<xsl:apply-templates/>
   112     	</a>
   113     </xsl:template>
   114     
   115     <!-- Ukázka vlastního „makra“: -->
   116     <xsl:template match="m:měřák">
   117     	<xsl:variable name="hodnota" select="number(@hodnota)"/>
   118     	<xsl:variable name="šířkaGrafu" select="128"/>
   119 		<xsl:choose>			
   120 			<xsl:when test="$hodnota &gt;= 0 and $hodnota &lt;= 100">				
   121 				<div style="border: 1px solid black; width: {$šířkaGrafu}px; height: 16px; padding: 0px; text-align: center; background-color: #cfc;">			
   122 					<div style="margin: 0px; background-color: #A4E666; width: {@hodnota*$šířkaGrafu div 100}px; height: 16px;"><xsl:call-template name="varováníRetardace"/></div>
   123 					<p style="margin: 0px; font-size: 12px; position: relative; top: -15px;">
   124 						<xsl:value-of select="@hodnota"/>/100
   125 					</p>	
   126 				</div>
   127 			</xsl:when>
   128 			<xsl:otherwise>
   129 				<xsl:message terminate="yes">Hodnota měřáku musí být nejméně 0 a nejvíce 100 (udává procenta).</xsl:message>
   130 			</xsl:otherwise>
   131 		</xsl:choose>
   132 	</xsl:template>
   133 
   134 </xsl:stylesheet>