šablona/makra/diagramy.xsl
author František Kučera <franta-hg@frantovo.cz>
Thu, 05 Jul 2012 23:31:49 +0200
changeset 111 d59023a42d4b
parent 87 25dec6931f18
child 136 d5feb9d8ebc3
permissions -rw-r--r--
#20 Skriptování: vnořování maker – zadání tabulky nebo diagramu může být generované skriptem.
     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:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
    22 	xmlns:j="java:cz.frantovo.xmlWebGenerator.makra.Diagram"
    23 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    24 	exclude-result-prefixes="m j">
    25 
    26 	<!--
    27 		Diagramy/grafy
    28 		**************
    29 		Můžeme vložit diagram – obrázek.
    30 		Pro jejich vykreslování se používá Graphviz – diagramy zadáváme v jeho syntaxi.
    31 		*
    32 		@orientace „vodorovně“ nebo „svisle“ (výchozí)
    33 		@nadpis můžeme uvést název diagramu
    34 		@kompletní „ano“ → předpokládáme kompletní zdroják v GraphViz syntaxi (pak nemá smysl uvádět orientaci). Výchozí je však „ne“ → uživatel zadává jen „vnitřek“ grafu – např. „A -> B; B -> C;“.  
    35 		@src zadání diagramu načteme ze souboru (potom je výchozí kompletní = 'ne')
    36 	-->
    37 	<xsl:template match="m:diagram">
    38 		<xsl:variable name="zadání">
    39 			<xsl:apply-templates select="*|text()"/>
    40 		</xsl:variable>
    41 		<xsl:call-template name="vložDiagram">
    42 			<xsl:with-param name="zadání" select="$zadání"/>
    43 			<xsl:with-param name="kompletní" select="@kompletní = 'ano'"/>
    44 		</xsl:call-template>
    45 	</xsl:template>
    46 	
    47 	<xsl:template match="m:diagram[@src]">
    48 		<xsl:call-template name="vložDiagram">
    49 			<xsl:with-param name="zadání" select="m:načti-textový-soubor(@src)"/>
    50 			<xsl:with-param name="kompletní" select="not(@kompletní) or @kompletní = 'ano'"/>
    51 		</xsl:call-template>
    52 	</xsl:template>
    53 
    54 	<xsl:template name="vložDiagram">
    55 		<xsl:param name="zadání"/>
    56 		<xsl:param name="kompletní"/>
    57 		<xsl:variable name="souborDiagramu" select="j:vytvořDiagram(
    58 															$zadání, 
    59 															@orientace = 'vodorovně', 
    60 															$kompletní,
    61 															tokenize(base-uri(), '/')[last()],
    62 															@src
    63 															)"/>
    64 		<xsl:choose>
    65 			<xsl:when test="$souborDiagramu">
    66 				<div class="diagram">
    67 					<a href="{encode-for-uri($souborDiagramu)}.svg">
    68 						<img
    69 							src="{encode-for-uri($souborDiagramu)}.svg" 
    70 							alt="Diagram {(@nadpis, $souborDiagramu)[1]} | pokud nevidíte obrázek, váš prohlížeč stojí za starou bačkoru"
    71 							title="{@nadpis} (klikněte pro zobrazení samotného diagramu)"/>
    72 					</a>
    73 					<!-- 
    74 						TODO: SVG+PNG:
    75 						<xsl:variable name="svgDiagramu" select="document(concat($výstup, $souborDiagramu, '.svg'))/svg:svg"/>
    76 						<object
    77 						data="{$souborDiagramu}.svg"
    78 						type="image/svg+xml"
    79 						style="width: {$svgDiagramu/@width}; height: {$svgDiagramu/@height}">
    80 						<img src="{$souborDiagramu}.png" alt="Diagram {$souborDiagramu}"/>
    81 						</object>
    82 					-->
    83 					<xsl:if test="@nadpis">
    84 						<p class="nadpis"><xsl:value-of select="@nadpis"/></p>
    85 					</xsl:if>
    86 				</div>
    87 			</xsl:when>
    88 			<xsl:otherwise>
    89 				<xsl:message terminate="yes">Při vytváření diagramu došlo k chybě.</xsl:message>
    90 			</xsl:otherwise>
    91 		</xsl:choose>
    92 	</xsl:template>
    93 
    94 </xsl:stylesheet>
    95