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