[51] | 1 | <?xml version="1.0" encoding="UTF-8"?> |
---|
[61] | 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. |
---|
[61] | 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 | --> |
---|
[51] | 18 | <xsl:stylesheet version="2.0" |
---|
[71] | 19 | xmlns="http://www.w3.org/1999/xhtml" |
---|
| 20 | xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro" |
---|
| 21 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
---|
| 22 | exclude-result-prefixes="m"> |
---|
[70] | 23 | |
---|
[51] | 24 | <!-- |
---|
| 25 | Jednoduché tabulky |
---|
| 26 | ****************** |
---|
| 27 | Data zadáváme do těla elementu. |
---|
| 28 | Sloupce oddělujeme tabulátorem (může jich být víc, minimálně však jeden, mezery nestačí). |
---|
| 29 | První řádek se považuje za záhlaví (nadpisy sloupců). |
---|
| 30 | * |
---|
[70] | 31 | @src volitelně můžeme data tabulky načítat ze souboru |
---|
| 32 | @oddělovač regulární výraz, který odděluje sloupce – např. „\t+“ pro tabulátory (výchozí pro tabulky vložené přímo do stránky) nebo „;“ pro středník (výchozí pro tabulky načítané ze souboru) |
---|
[51] | 33 | --> |
---|
[70] | 34 | <xsl:template match="m:tabulka"> |
---|
| 35 | <xsl:call-template name="vykresliTabulku"> |
---|
| 36 | <xsl:with-param name="zadání" select="text()"/> |
---|
| 37 | <xsl:with-param name="oddělovač" select="(@oddělovač, '\t+')[1]"/> |
---|
| 38 | </xsl:call-template> |
---|
| 39 | </xsl:template> |
---|
| 40 | |
---|
[111] | 41 | <!-- Skript je potřeba interpretovat ještě před tabulkou – ostatní makra budou interpretovat uvnitř buněk --> |
---|
| 42 | <xsl:template match="m:tabulka[m:skript]"> |
---|
| 43 | <xsl:variable name="zadání"> |
---|
| 44 | <xsl:apply-templates select="*"/> |
---|
| 45 | </xsl:variable> |
---|
| 46 | <xsl:call-template name="vykresliTabulku"> |
---|
| 47 | <xsl:with-param name="zadání" select="$zadání"/> |
---|
| 48 | <xsl:with-param name="oddělovač" select="(@oddělovač, '\t+')[1]"/> |
---|
| 49 | </xsl:call-template> |
---|
| 50 | </xsl:template> |
---|
| 51 | |
---|
| 52 | <!-- Tabulka načítaná ze souboru: --> |
---|
[70] | 53 | <xsl:template match="m:tabulka[@src]"> |
---|
| 54 | <xsl:call-template name="vykresliTabulku"> |
---|
[71] | 55 | <xsl:with-param name="zadání" select="m:načti-textový-soubor(@src)"/> |
---|
[70] | 56 | <xsl:with-param name="oddělovač" select="(@oddělovač, ';')[1]"/> |
---|
| 57 | </xsl:call-template> |
---|
| 58 | </xsl:template> |
---|
| 59 | |
---|
[111] | 60 | <!-- TODO: Umožnit použití maker a značek uvnitř buněk tabulky. --> |
---|
[70] | 61 | <xsl:template name="vykresliTabulku"> |
---|
| 62 | <xsl:param name="zadání"/> |
---|
| 63 | <xsl:param name="oddělovač"/> |
---|
| 64 | <table> |
---|
| 65 | <xsl:variable name="data" select="replace(replace($zadání, '^\s+', ''),'\s+$','')"/> |
---|
| 66 | <xsl:variable name="hlavička" select="substring-before($data, ' ')"/> |
---|
| 67 | <xsl:variable name="tělo" select="substring-after($data, ' ')"/> |
---|
| 68 | <thead> |
---|
| 69 | <tr> |
---|
| 70 | <xsl:for-each select="tokenize($hlavička, $oddělovač)"> |
---|
| 71 | <xsl:if test="normalize-space(.)"> |
---|
[51] | 72 | <td><xsl:value-of select="normalize-space(.)"/></td> |
---|
| 73 | </xsl:if> |
---|
| 74 | </xsl:for-each> |
---|
[70] | 75 | </tr> |
---|
| 76 | </thead> |
---|
| 77 | <tbody> |
---|
[51] | 78 | <xsl:for-each select="tokenize($tělo, '\n')"> |
---|
| 79 | <xsl:if test="normalize-space(.)"> |
---|
| 80 | <tr> |
---|
[70] | 81 | <xsl:for-each select="tokenize(., $oddělovač)"> |
---|
[51] | 82 | <xsl:if test="normalize-space(.)"> |
---|
[90] | 83 | <xsl:element name="td"> |
---|
| 84 | <xsl:if test="number(normalize-space(.))"> |
---|
| 85 | <xsl:attribute name="class">číslo</xsl:attribute> |
---|
| 86 | </xsl:if> |
---|
| 87 | <xsl:value-of select="normalize-space(.)"/> |
---|
| 88 | </xsl:element> |
---|
[51] | 89 | </xsl:if> |
---|
| 90 | </xsl:for-each> |
---|
| 91 | </tr> |
---|
| 92 | </xsl:if> |
---|
| 93 | </xsl:for-each> |
---|
[70] | 94 | </tbody> |
---|
| 95 | </table> |
---|
| 96 | </xsl:template> |
---|
[51] | 97 | |
---|
| 98 | </xsl:stylesheet> |
---|
| 99 | |
---|