šablona/stránka.xsl
author František Kučera <franta-hg@frantovo.cz>
Sun Apr 03 20:39:10 2011 +0200 (2011-04-03)
changeset 11 78a8dd1eeb2b
parent 10 4e70453a027f
child 12 3719b121c3c4
permissions -rw-r--r--
statický obsah a úloha pro čištění
     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: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"
     8 	xmlns:svg="http://www.w3.org/2000/svg"
     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"/>
    16 	
    17 	<!-- Vstupní adresář: -->
    18 	<xsl:param name="vstup" select="'../vstup/'"/>
    19 	
    20 	<!-- Celý dokument: -->
    21 	<xsl:template match="/">
    22 		<xsl:variable name="konfigurace" select="document(concat($vstup, 'web.conf'))"/>
    23 		<html>
    24 			<head>
    25 				<title><xsl:value-of select="g:stránka/g:nadpis"/></title>
    26 				<link title="Novinky (Atom)" href="atom.xml" type="application/atom+xml" rel="alternate"/>
    27 				<link title="Novinky (RSS)"  href="rss.xml"  type="application/rss+xml"  rel="alternate"/>
    28 				<xsl:apply-templates select="$konfigurace/g:web/g:js"/>
    29 				<xsl:apply-templates select="$konfigurace/g:web/g:css"/>				
    30 			</head>
    31 			<body>
    32 				<xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'záhlaví.inc')))/g:stránka/h:text/node()"/>			
    33 				<h1><xsl:value-of select="g:stránka/g:nadpis"/></h1>
    34 				<xsl:apply-templates select="g:stránka/h:text/node()"/>
    35 				<ul id="nabídka">
    36 					<xsl:for-each select="collection('../vstup/?select=*.xml')[g:stránka/g:pořadí]">
    37 						<xsl:sort select="empty(./g:stránka/g:pořadí)"/>
    38 						<xsl:sort select="./g:stránka/g:pořadí"/>
    39 						<li>
    40 							<xsl:variable name="xmlSoubor" select="tokenize(document-uri(.), '/')[last()]"/>
    41 							<xsl:variable name="xhtmlSoubor" select="replace($xmlSoubor, '.xml', '.xhtml')"/>
    42 							<a href="{fn:encode-for-uri($xhtmlSoubor)}"><xsl:value-of select="./g:stránka/g:nadpis"/></a>
    43 						</li>
    44 					</xsl:for-each>
    45 				</ul>
    46 				<xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'zápatí.inc')))/g:stránka/h:text/node()"/>				
    47 			</body>
    48 		</html>
    49 	</xsl:template>
    50 	
    51 	<!-- Kopírujeme elementy, ale vynecháme nepoužité xmlns deklarace: -->
    52 	<xsl:template match="*">
    53 		<xsl:element name="{name()}">
    54 			<xsl:copy-of select="@*"/>
    55 			<xsl:apply-templates/>
    56 		</xsl:element>
    57     </xsl:template>
    58     
    59     <!-- Odkazy na JavaScript a kaskádové styly -->
    60     <xsl:template match="g:web/g:js">
    61     	<script src="{text()}" type="text/javascript" />
    62     </xsl:template>
    63     <xsl:template match="g:web/g:css">
    64     	<link href="{text()}" type="text/css" rel="StyleSheet" />
    65     </xsl:template>
    66     
    67     <!-- Ukázka vlastního „makra“: -->
    68     <xsl:template match="g:měřák">
    69     	<xsl:variable name="hodnota" select="number(@hodnota)"/>
    70     	<xsl:variable name="šířkaGrafu" select="128"/>
    71 		<xsl:choose>			
    72 			<xsl:when test="$hodnota &gt;= 0 and $hodnota &lt;= 100">				
    73 				<div style="border: 1px solid black; width: {$šířkaGrafu}px; height: 16px; padding: 0px; text-align: center; background-color: #cfc;">			
    74 					<div style="margin: 0px; background-color: #A4E666; width: {@hodnota*$šířkaGrafu div 100}px; height: 16px;"/>
    75 					<p style="margin: 0px; font-size: 12px; position: relative; top: -15px;">
    76 						<xsl:value-of select="@hodnota"/>/100
    77 					</p>	
    78 				</div>
    79 			</xsl:when>
    80 			<xsl:otherwise>
    81 				<xsl:message terminate="yes">Hodnota měřáku musí být nejméně 0 a nejvíce 100 (udává procenta).</xsl:message>
    82 			</xsl:otherwise>
    83 		</xsl:choose>
    84 	</xsl:template>
    85 
    86 </xsl:stylesheet>