<?xml version="1.0"  encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    version="1.0">
<xsl:decimal-format name="German" grouping-separator="." NaN="" zero-digit ="0" decimal-separator="," />
    <xsl:template match="/ergebnis">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <fo:layout-master-set>
                 <fo:simple-page-master master-name="page"
                     page-height="200mm" page-width="300mm"
                     margin-top="10mm" margin-bottom="10mm"
                     margin-left="20mm" margin-right="20mm">

                     <fo:region-body
                       margin-top="0mm" margin-bottom="10mm"
                       margin-left="0mm" margin-right="0mm"/>

                     <fo:region-after extent="10mm"/>
                 </fo:simple-page-master>
             </fo:layout-master-set>

             <fo:page-sequence master-reference="page">
               <fo:flow flow-name="xsl-region-body">
<xsl:if test="/ergebnis/Makro/@tid !=''">
<fo:block font-family="sans-serif" line-height="20pt" font-size="20pt" font-weight="bolder" margin-bottom="20mm">
<xsl:value-of select="/ergebnis/Makro/@name" />
</fo:block>
</xsl:if>
<xsl:for-each select="tabelle">
<fo:block font-family="sans-serif" line-height="48pt" font-size="20pt" font-weight="bold" color="blue" margin-bottom="20mm">
<xsl:value-of select="maskenname" /></fo:block>
<xsl:call-template name="legende" />

<fo:block font-family="sans-serif" line-height="26pt" font-size="14pt">Stand: <xsl:value-of select="stand" /></fo:block>
<xsl:if test="errmsg !=''">
<fo:block font-family="sans-serif" line-height="20pt" font-size="20pt">
<xsl:copy-of select="errmsg" /></fo:block></xsl:if>
 
<fo:table><xsl:text>
</xsl:text>
<xsl:for-each select="sqlerg/headers/header"><xsl:text>
</xsl:text>
<fo:table-column>
<xsl:attribute name="column-width">
<xsl:choose>
<xsl:when test="@width != ''" >
<!--<xsl:value-of select="concat((@width*2),'mm')" />-->
30mm
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'auto'" />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="column-number">
<xsl:value-of select="@id" />
</xsl:attribute>
</fo:table-column> 
</xsl:for-each>
<fo:table-body>
<fo:table-row>
<xsl:for-each select="sqlerg/headers/header">
<fo:table-cell border-width="0.5mm" border-style="solid"><xsl:text>
</xsl:text>
                                     <fo:block font-size="18pt" 
                                         font-weight="bold">
                                         <xsl:value-of select="wert" /><xsl:text>
</xsl:text>
</fo:block>
</fo:table-cell><xsl:text>
</xsl:text>
</xsl:for-each>
</fo:table-row>
<xsl:for-each select="sqlerg/row">
<fo:table-row><xsl:text>
</xsl:text>
<xsl:for-each select="col">
           <xsl:call-template name="spalte" /><xsl:text>
</xsl:text>
</xsl:for-each>
</fo:table-row><xsl:text>
</xsl:text>
</xsl:for-each>
</fo:table-body>
</fo:table>
</xsl:for-each>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template name="spalte">
<fo:table-cell border-width="0.5mm" border-style="solid">
<fo:block font-size="18pt">
 
    <xsl:choose>
      
	<xsl:when test="@typ='2'"> <!-- DecimalFormat -->
		<!--<xsl:attribute name="class">decimal</xsl:attribute>-->
		
		<xsl:value-of select="format-number(wert,'###.###.###.###.##0,00','German')" />
	</xsl:when>
	<xsl:when test="@typ='3'"> <!-- DecimalFormat -->
		<!--<xsl:attribute name="class">decimal</xsl:attribute>-->
		<!--<xsl:value-of select="wert" />-->
		<xsl:value-of select="format-number(wert,'###.###.###.###.##0,00','German')" />
	</xsl:when>
	<xsl:when test="@typ='4'"> <!-- Integer -->
		<!--<xsl:attribute name="class">integer</xsl:attribute>-->
		<!--<xsl:value-of select="wert" />-->
		<xsl:value-of select="format-number(wert,'###.###.###.###.###','German')" />
	</xsl:when>
	<xsl:otherwise>
	<!--Typ=1 ist string und wird defaultmäßig behandelt -->
	<xsl:choose>
		<xsl:when test="f_name='email'">
		
		<xsl:value-of select="wert" />
		</xsl:when>
		<xsl:when test="f_name='url'">
			<!--<a target="_blank"><xsl:attribute name="href"><xsl:value-of select="wert" /></xsl:attribute>-->
			<xsl:value-of select="wert" /><!--</a>-->
			</xsl:when>
		<xsl:when test="f_name='nextmask'">
	
			
			</xsl:when>
		<xsl:when test="f_name='nexttable'">
			
		</xsl:when>
		<xsl:otherwise>
        		<xsl:value-of select="wert" />
		</xsl:otherwise>
	</xsl:choose>
</xsl:otherwise>
</xsl:choose>


              </fo:block>
          </fo:table-cell><xsl:text>
</xsl:text>
</xsl:template>
<xsl:template name="legende">
<fo:block font-family="sans-serif" line-height="16pt" font-size="14pt" border-width="0.5mm" border-style="solid" border-color="gray" margin-bottom="40mm">
<xsl:for-each select="/ergebnis/felder/feld">
<xsl:if test="wert !=''">

		<fo:inline><xsl:value-of select="wert/@varname" /></fo:inline><fo:inline>:&#160;</fo:inline>
		<fo:inline font-style="italic" font-weight="bold">
		<xsl:if test="string-length(wert/caption) &lt; 50">
			<xsl:value-of select="wert/caption" />
		</xsl:if>
		<xsl:if test="string-length(wert/caption) &gt; 49">
			<xsl:value-of select="substring(wert/caption,0,50)" />...
		</xsl:if>
		;&#160;</fo:inline>
</xsl:if>
</xsl:for-each>
</fo:block>

<xsl:for-each select="/ergebnis/felder/msgs/msg">
	<xsl:if test="wert !=''">
	<fo:block space-after="10mm" font-family="sans-serif" line-height="16pt" font-size="14pt">
	<xsl:value-of select="wert" />
	</fo:block>
	</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>