[94] | 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" |
---|
[107] | 21 | xmlns:h="http://www.w3.org/1999/xhtml" |
---|
[94] | 22 | xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro" |
---|
| 23 | xmlns:j="java:cz.frantovo.xmlWebGenerator.makra.Skriptování" |
---|
[96] | 24 | xmlns:k="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/konfigurace" |
---|
[94] | 25 | xmlns:s="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana" |
---|
| 26 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
---|
[96] | 27 | exclude-result-prefixes="m j k s"> |
---|
[94] | 28 | |
---|
| 29 | <!-- |
---|
| 30 | Skriptování |
---|
| 31 | *********** |
---|
[103] | 32 | Provedeme skript zadaný v těle elementu nebo v souboru a jeho výstup vložíme do stránky. |
---|
[94] | 33 | * |
---|
[103] | 34 | @jazyk programovací jazyk, např. bash, perl, php (nepovinné, pokud je vyplněn atribut src) |
---|
[108] | 35 | @výstup formát výstupu skriptu: |
---|
| 36 | text – libovolný text, escapujeme (výchozí) |
---|
| 37 | xhtml – platný XML fragment, přidáme mu výchozí jmenný prostor XHTML a jmenný prostor pro makra |
---|
| 38 | xml – platný XML dokument – vhodné pro další zpracování v jiných makrech |
---|
[103] | 39 | @src soubor se skriptem/programem (volitelný parametr – buď zadáme skript do těla elementu, nebo nastavíme tento atribut) |
---|
[94] | 40 | --> |
---|
| 41 | <xsl:template match="m:skript"> |
---|
[95] | 42 | |
---|
[96] | 43 | <xsl:variable name="režim" select="$konfigurace/k:web/k:skriptování/k:režim/text()"/> |
---|
| 44 | |
---|
[95] | 45 | <xsl:choose> |
---|
[96] | 46 | <xsl:when test="$režim = 'povolit'"> |
---|
[113] | 47 | <xsl:variable name="zadáníSkriptu"> |
---|
| 48 | <xsl:apply-templates select="*|text()"/> |
---|
| 49 | </xsl:variable> |
---|
[96] | 50 | <xsl:variable name="výstupSkriptu" select="j:interpretuj( |
---|
[113] | 51 | $zadáníSkriptu, |
---|
[103] | 52 | @src, |
---|
[96] | 53 | @jazyk, |
---|
| 54 | @výstup, |
---|
[106] | 55 | (document-uri(/), resolve-uri('.'))[1], |
---|
[96] | 56 | //s:stránka/s:nadpis/text(), |
---|
| 57 | //s:stránka/s:perex/text() |
---|
| 58 | )"/> |
---|
[108] | 59 | <xsl:choose> |
---|
| 60 | <xsl:when test="@výstup = 'xml'"> |
---|
| 61 | <!-- XML výstup zpracujeme, jak je: --> |
---|
| 62 | <xsl:apply-templates select="$výstupSkriptu/*"/> |
---|
| 63 | </xsl:when> |
---|
| 64 | <xsl:otherwise> |
---|
| 65 | <!-- Prostý text a XHTML fragmenty dostáváme zabalené v html/body --> |
---|
| 66 | <xsl:apply-templates select="$výstupSkriptu/h:html/h:body/node()"/> |
---|
| 67 | </xsl:otherwise> |
---|
| 68 | </xsl:choose> |
---|
[95] | 69 | </xsl:when> |
---|
[96] | 70 | |
---|
| 71 | <xsl:when test="$režim = 'zakázat'"> |
---|
| 72 | <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> |
---|
| 73 | </xsl:when> |
---|
| 74 | <xsl:when test="$režim = 'ignorovat'"> |
---|
| 75 | <xsl:message>Stránka obsahuje skripty, ale skripty jsou ignorovány – změnu lze provést ve web.conf.</xsl:message> |
---|
| 76 | </xsl:when> |
---|
[108] | 77 | <xsl:when test="$režim = 'vložit' and (@výstup = 'xml' or @výstup = 'xhtml')"> |
---|
[96] | 78 | <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> |
---|
| 79 | </xsl:when> |
---|
| 80 | <xsl:when test="$režim = 'vložit'"> |
---|
| 81 | <span class="vloženýNeinterpretovanýSkript jazyk-{@jazyk}"> |
---|
| 82 | <xsl:value-of select="text()"/> |
---|
| 83 | </span> |
---|
| 84 | </xsl:when> |
---|
| 85 | <xsl:otherwise><!-- varovat = výchozí možnost --> |
---|
| 86 | <xsl:choose> |
---|
[108] | 87 | <xsl:when test="@výstup = 'xml' or @výstup = 'xhtml'"> |
---|
[96] | 88 | <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> |
---|
| 89 | </xsl:when> |
---|
| 90 | <xsl:otherwise> |
---|
| 91 | <xsl:text>[VAROVÁNÍ (</xsl:text> |
---|
| 92 | <xsl:value-of select="@jazyk"/> |
---|
| 93 | <xsl:text>): skripty jsou vypnuté – lze je zapnout ve web.conf]</xsl:text> |
---|
| 94 | <xsl:message>Skript se neinterpretuje a vkládáme varování do stránky – změnu lze provést ve web.conf</xsl:message> |
---|
| 95 | </xsl:otherwise> |
---|
| 96 | </xsl:choose> |
---|
[95] | 97 | </xsl:otherwise> |
---|
| 98 | </xsl:choose> |
---|
[94] | 99 | </xsl:template> |
---|
| 100 | |
---|
| 101 | </xsl:stylesheet> |
---|
| 102 | |
---|