šablona/makra/skriptování.xsl
author František Kučera <franta-hg@frantovo.cz>
Thu, 05 Jul 2012 19:10:42 +0200
changeset 107 379a2a893fd1
parent 106 ae484a54d7fb
child 108 8d9cab64c335
permissions -rw-r--r--
#20 Skriptování: Makra ve skriptech a Skripty v makrech + výpis verzí z Mercurialu.
     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:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
    23 	xmlns:j="java:cz.frantovo.xmlWebGenerator.makra.Skriptování"
    24 	xmlns:k="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/konfigurace"
    25 	xmlns:s="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
    26 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    27 	exclude-result-prefixes="m j k s">
    28 
    29 	<!--
    30 		Skriptování
    31 		***********
    32 		Provedeme skript zadaný v těle elementu nebo v souboru a jeho výstup vložíme do stránky.
    33 		*
    34 		@jazyk programovací jazyk, např. bash, perl, php (nepovinné, pokud je vyplněn atribut src)
    35 		@výstup formát výstupu skriptu: text (výchozí) | xml (musí být validním fragmentem XML)
    36 		@src soubor se skriptem/programem (volitelný parametr – buď zadáme skript do těla elementu, nebo nastavíme tento atribut)
    37 	-->
    38 	<xsl:template match="m:skript">
    39 		
    40 		<xsl:variable name="režim" select="$konfigurace/k:web/k:skriptování/k:režim/text()"/>
    41 		
    42 		<xsl:choose>
    43 			<xsl:when test="$režim = 'povolit'">
    44 				<xsl:variable name="výstupSkriptu" select="j:interpretuj(
    45 																	text(),
    46 																	@src,
    47 																	@jazyk,
    48 																	@výstup,
    49 																	(document-uri(/), resolve-uri('.'))[1],
    50 																	//s:stránka/s:nadpis/text(),
    51 																	//s:stránka/s:perex/text()
    52 																)"/>
    53 				<xsl:apply-templates select="$výstupSkriptu/h:html/h:body/node()"/>
    54 			</xsl:when>
    55 
    56 			<xsl:when test="$režim = 'zakázat'">
    57 				<xsl:message terminate="yes">Stránka obsahuje skripty, ale skripty jsou zakázané → je potřeba je odstranit nebo upravit nastavení ve web.conf.</xsl:message>
    58 			</xsl:when>
    59 			<xsl:when test="$režim = 'ignorovat'">
    60 				<xsl:message>Stránka obsahuje skripty, ale skripty jsou ignorovány – změnu lze provést ve web.conf.</xsl:message>
    61 			</xsl:when>
    62 			<xsl:when test="$režim = 'vložit' and @výstup = 'xml'">
    63 				<xsl:message>Není možné jen tak vložit text, který měl mít výstup ve formátu XML – změnu lze provést ve web.conf</xsl:message>
    64 			</xsl:when>
    65 			<xsl:when test="$režim = 'vložit'">
    66 				<span class="vloženýNeinterpretovanýSkript jazyk-{@jazyk}">
    67 					<xsl:value-of select="text()"/>
    68 				</span>
    69 			</xsl:when>
    70 			<xsl:otherwise><!-- varovat = výchozí možnost -->
    71 				<xsl:choose>
    72 					<xsl:when test="@výstup = 'xml'">
    73 						<xsl:message>Není možné možné vložit varování na místo, kde měl být skript generující XML – změnu lze provést ve web.conf</xsl:message>
    74 					</xsl:when>
    75 					<xsl:otherwise>
    76 						<xsl:text>[VAROVÁNÍ (</xsl:text>
    77 						<xsl:value-of select="@jazyk"/>
    78 						<xsl:text>): skripty jsou vypnuté – lze je zapnout ve web.conf]</xsl:text>
    79 						<xsl:message>Skript se neinterpretuje a vkládáme varování do stránky – změnu lze provést ve web.conf</xsl:message>
    80 					</xsl:otherwise>
    81 				</xsl:choose>
    82 			</xsl:otherwise>
    83 		</xsl:choose>
    84 	</xsl:template>
    85 
    86 </xsl:stylesheet>
    87