šablona/makra/tabulka.xsl
changeset 70 032c62852ef1
parent 61 9503eb8377f1
child 71 895757141bff
     1.1 --- a/šablona/makra/tabulka.xsl	Sat Jan 07 12:43:30 2012 +0100
     1.2 +++ b/šablona/makra/tabulka.xsl	Sat Jan 07 19:39:28 2012 +0100
     1.3 @@ -17,11 +17,11 @@
     1.4  along with this program.  If not, see <http://www.gnu.org/licenses/>.
     1.5  -->
     1.6  <xsl:stylesheet version="2.0"
     1.7 -	xmlns="http://www.w3.org/1999/xhtml"
     1.8 -	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
     1.9 -	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    1.10 -	exclude-result-prefixes="m">
    1.11 -	    
    1.12 +xmlns="http://www.w3.org/1999/xhtml"
    1.13 +xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
    1.14 +xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    1.15 +exclude-result-prefixes="m">
    1.16 +
    1.17  	<!--
    1.18  		Jednoduché tabulky
    1.19  		******************
    1.20 @@ -29,26 +29,44 @@
    1.21  		Sloupce oddělujeme tabulátorem (může jich být víc, minimálně však jeden, mezery nestačí).
    1.22  		První řádek se považuje za záhlaví (nadpisy sloupců).
    1.23  		*
    1.24 +		@src volitelně můžeme data tabulky načítat ze souboru 
    1.25 +		@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) 
    1.26  	-->
    1.27 -    <xsl:template match="m:tabulka">
    1.28 -    	<table>
    1.29 -    		<xsl:variable name="data" select="replace(replace(text(), '^\s+', ''),'\s+$','')"/>
    1.30 -    		<xsl:variable name="hlavička" select="substring-before($data, '&#10;')"/>
    1.31 -    		<xsl:variable name="tělo" select="substring-after($data, '&#10;')"/>
    1.32 -    		<thead>
    1.33 -    			<tr>
    1.34 -    				<xsl:for-each select="tokenize($hlavička, '\t+')">
    1.35 -    					<xsl:if test="normalize-space(.)">
    1.36 +	<xsl:template match="m:tabulka">
    1.37 +		<xsl:call-template name="vykresliTabulku">
    1.38 +			<xsl:with-param name="zadání" select="text()"/>
    1.39 +			<xsl:with-param name="oddělovač" select="(@oddělovač, '\t+')[1]"/>
    1.40 +		</xsl:call-template>
    1.41 +	</xsl:template>
    1.42 +	
    1.43 +	<xsl:template match="m:tabulka[@src]">
    1.44 +		<xsl:call-template name="vykresliTabulku">
    1.45 +			<xsl:with-param name="zadání" select="unparsed-text(concat('../', $vstup, @src))"/>
    1.46 +			<xsl:with-param name="oddělovač" select="(@oddělovač, ';')[1]"/>
    1.47 +		</xsl:call-template>
    1.48 +	</xsl:template>
    1.49 +	
    1.50 +	<xsl:template name="vykresliTabulku">
    1.51 +		<xsl:param name="zadání"/>
    1.52 +		<xsl:param name="oddělovač"/>
    1.53 +		<table>
    1.54 +			<xsl:variable name="data" select="replace(replace($zadání, '^\s+', ''),'\s+$','')"/>
    1.55 +			<xsl:variable name="hlavička" select="substring-before($data, '&#10;')"/>
    1.56 +			<xsl:variable name="tělo" select="substring-after($data, '&#10;')"/>
    1.57 +			<thead>
    1.58 +				<tr>
    1.59 +					<xsl:for-each select="tokenize($hlavička, $oddělovač)">
    1.60 +						<xsl:if test="normalize-space(.)">
    1.61  							<td><xsl:value-of select="normalize-space(.)"/></td>
    1.62  						</xsl:if>
    1.63  					</xsl:for-each>
    1.64 -    			</tr>
    1.65 -    		</thead>
    1.66 -    		<tbody>
    1.67 +				</tr>
    1.68 +			</thead>
    1.69 +			<tbody>
    1.70  				<xsl:for-each select="tokenize($tělo, '\n')">
    1.71  					<xsl:if test="normalize-space(.)">
    1.72  						<tr>
    1.73 -							<xsl:for-each select="tokenize(., '\t+')">
    1.74 +							<xsl:for-each select="tokenize(., $oddělovač)">
    1.75  								<xsl:if test="normalize-space(.)">
    1.76  									<td><xsl:value-of select="normalize-space(.)"/></td>
    1.77  								</xsl:if>
    1.78 @@ -56,9 +74,9 @@
    1.79  						</tr>
    1.80  					</xsl:if>
    1.81  				</xsl:for-each>
    1.82 -    		</tbody>
    1.83 -    	</table>    
    1.84 -    </xsl:template>
    1.85 +			</tbody>
    1.86 +		</table>
    1.87 +	</xsl:template>
    1.88  
    1.89  </xsl:stylesheet>
    1.90