šablona/stránka.xsl
author František Kučera <franta-hg@frantovo.cz>
Wed Jul 06 18:54:11 2011 +0200 (2011-07-06)
changeset 20 29361e026fa3
parent 19 b81b96475fe0
child 27 037a9f20bf3a
permissions -rw-r--r--
Dočasný hack: kompatibilita s Antem verze 1.8.1, Bug 49271
https://issues.apache.org/bugzilla/show_bug.cgi?id=49271

- U XSLT nefunguje „class path“
- collection() má root jinde než ve verzi 1.8.0
     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 m xs">
    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 	<xsl:param name="vstup" select="'../vstup/'"/>
    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"/>
    25 	
    26 	<xsl:include href="makra.xsl"/>
    27 	
    28 	<!-- Celý dokument: -->
    29 	<xsl:template match="/">
    30 		<xsl:variable name="konfigurace" select="document(concat($vstup, 'web.conf'))"/>
    31 		<html>
    32 			<head>
    33 				<xsl:if test="$podporaZaostalýchProhlížečů">
    34 					<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
    35 				</xsl:if>
    36 				<title><xsl:value-of select="s:stránka/s:nadpis"/></title>
    37 				<link title="Novinky (Atom)" href="atom.xml" type="application/atom+xml" rel="alternate"/>
    38 				<link title="Novinky (RSS)"  href="rss.xml"  type="application/rss+xml"  rel="alternate"/>
    39 				<xsl:apply-templates select="$konfigurace/k:web/k:js"/>
    40 				<xsl:apply-templates select="$konfigurace/k:web/k:css"/>				
    41 			</head>
    42 			<body>
    43 				<div id="tělo">
    44 					<div id="záhlaví">
    45 						<xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'záhlaví', $vsuvkováPřípona)))/s:stránka/h:text/node()"/>
    46 					</div>
    47 					<div id="vnitřek">
    48 						<h1><xsl:value-of select="s:stránka/s:nadpis"/></h1>
    49 						<ul id="nabídka">
    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í"/>
    53 								<li>
    54 									<xsl:variable name="xmlSoubor" select="tokenize(document-uri(.), '/')[last()]"/>
    55 									<xsl:variable name="xhtmlSoubor" select="replace($xmlSoubor, $vstupníPřípona, $výstupníPřípona)"/>
    56 									<a href="{fn:encode-for-uri($xhtmlSoubor)}"><xsl:value-of select="./s:stránka/s:nadpis"/></a>
    57 								</li>
    58 							</xsl:for-each>
    59 						</ul>
    60 						<div id="text">
    61 							<xsl:apply-templates select="s:stránka/h:text/node()"/>
    62 						</div>
    63 					</div>
    64 					<div id="zápatí">
    65 						<xsl:apply-templates select="document(fn:encode-for-uri(concat($vstup, 'zápatí', $vsuvkováPřípona)))/s:stránka/h:text/node()"/>
    66 					</div>
    67 				</div>
    68 			</body>
    69 		</html>
    70 	</xsl:template>
    71 	
    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>
    79     
    80     <!-- Varování pro případ, že jsme v režimu podpory pro zaostalé prohlížeče -->
    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>
    89     </xsl:template>
    90 
    91     <!-- Odkazy na JavaScript a kaskádové styly -->    
    92     <xsl:template match="k:web/k:js">    	
    93     	<script src="{text()}" type="text/javascript">
    94     		<xsl:call-template name="varováníRetardace"/>
    95     	</script>
    96     </xsl:template>
    97     <xsl:template match="k:web/k:css">
    98     	<link href="{text()}" type="text/css" rel="StyleSheet" />
    99     </xsl:template>
   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>
   115 
   116 </xsl:stylesheet>