šablona/makra/tabulka.xsl
author František Kučera <franta-hg@frantovo.cz>
Sat, 07 Jan 2012 12:43:30 +0100
changeset 61 9503eb8377f1
parent 51 df1f942f7b69
child 70 032c62852ef1
permissions -rw-r--r--
Licence: informace o licenci v každém souboru.

<?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:xsl="http://www.w3.org/1999/XSL/Transform"
	exclude-result-prefixes="m">
	    
	<!--
		Jednoduché tabulky
		******************
		Data zadáváme do těla elementu.
		Sloupce oddělujeme tabulátorem (může jich být víc, minimálně však jeden, mezery nestačí).
		První řádek se považuje za záhlaví (nadpisy sloupců).
		*
	-->
    <xsl:template match="m:tabulka">
    	<table>
    		<xsl:variable name="data" select="replace(replace(text(), '^\s+', ''),'\s+$','')"/>
    		<xsl:variable name="hlavička" select="substring-before($data, '&#10;')"/>
    		<xsl:variable name="tělo" select="substring-after($data, '&#10;')"/>
    		<thead>
    			<tr>
    				<xsl:for-each select="tokenize($hlavička, '\t+')">
    					<xsl:if test="normalize-space(.)">
							<td><xsl:value-of select="normalize-space(.)"/></td>
						</xsl:if>
					</xsl:for-each>
    			</tr>
    		</thead>
    		<tbody>
				<xsl:for-each select="tokenize($tělo, '\n')">
					<xsl:if test="normalize-space(.)">
						<tr>
							<xsl:for-each select="tokenize(., '\t+')">
								<xsl:if test="normalize-space(.)">
									<td><xsl:value-of select="normalize-space(.)"/></td>
								</xsl:if>
							</xsl:for-each>
						</tr>
					</xsl:if>
				</xsl:for-each>
    		</tbody>
    	</table>    
    </xsl:template>

</xsl:stylesheet>