šablona/makra/skriptování.xsl
author František Kučera <franta-hg@frantovo.cz>
Sat, 23 Jun 2012 19:22:21 +0200
changeset 95 eea9c4713045
parent 94 4b3ba32f613c
child 96 8de228c9ac10
permissions -rw-r--r--
#20 Skriptování: podpora výstupu ve formátu XML (musí být validní)

<?xml version="1.0" encoding="UTF-8"?>
<!--
XML Web generátor – program na generování webových stránek
Copyright © 2012 František Kučera (frantovo.cz)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
<xsl:stylesheet version="2.0"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
	xmlns:j="java:cz.frantovo.xmlWebGenerator.makra.Skriptování"
	xmlns:s="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	exclude-result-prefixes="m j s">

	<!--
		Skriptování
		***********
		Provedeme skript zadaný v těle elementu a jeho výstup vložíme do stránky.
		*
		@jazyk programovací jazyk, např. bash, perl, php
		@výstup formát výstupu skriptu: text (výchozí) | xml (musí být validním fragmentem XML)
		@src skript uložený v souboru místo v těle elementu
	-->
	<xsl:template match="m:skript">
		<!--
		TODO:
			- ošetření chyb
			- nastavení z web.conf (zákaz nebo ignorace skriptů)
			- podpora vkládání fragmentů XML, ne jen prostého textu
		-->
		
		<xsl:variable name="výstupSkriptu" select="j:interpretuj(
															text(),
															@jazyk,
															@výstup,
															document-uri(/),
															//s:stránka/s:nadpis/text(),
															//s:stránka/s:perex/text()
														)"/>
		<xsl:choose>
			<xsl:when test="$výstupSkriptu">
				<xsl:choose>
					<xsl:when test="@výstup = 'xml'"><xsl:value-of select="$výstupSkriptu" disable-output-escaping="yes"/></xsl:when>
					<xsl:otherwise><xsl:value-of select="$výstupSkriptu"/></xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:message terminate="yes">Při interpretaci skriptu došlo k chybě.</xsl:message>
			</xsl:otherwise>
		</xsl:choose>

		
	</xsl:template>

</xsl:stylesheet>