<?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="300mm" page-width="200mm"
                     margin-top="10mm" margin-bottom="10mm"
                     margin-left="10mm" margin-right="10mm">

                     <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">
<fo:block font-family="Times, serif" line-height="20pt" font-size="20pt" font-weight="bolder"  color="rgb(153,0,0)" margin-bottom="20mm" text-align="end">
HRK<!--<fo:external-graphic src="http://localhost:8080/kompass/images/logo.gif" />--></fo:block>
	       <xsl:if test="/ergebnis/Makro/@tid !=''">
<fo:block font-family="Times, 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="Times, 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="Times, serif" line-height="26pt" font-size="14pt">Stand: <xsl:value-of select="stand" /></fo:block>
<xsl:if test="errmsg !=''">
<fo:block font-family="Times, serif" line-height="20pt" font-size="20pt">
<xsl:copy-of select="errmsg" /></fo:block></xsl:if>
 
<fo:table>
<fo:table-column column-width="50mm" column-number="0">
</fo:table-column> 
<fo:table-column column-width="120mm" column-number="0">
</fo:table-column> 

<fo:table-body>

<xsl:for-each select="sqlerg/row">

<xsl:for-each select="col">
<xsl:if test="wert !=''">
<fo:table-row><fo:table-cell 
border-width="0.5mm" 
border-left-style="none" 
border-bottom-style="none" 
border-top-style="none" 
padding-right="2mm"
>
<xsl:choose>
<xsl:when test="f_name !='funktionsbezeichnung' and f_name != 'Person'  and f_name != 'bezeichnung'">
<xsl:attribute name="border-right-style">solid</xsl:attribute>
<fo:block font-size="12pt" text-align="end">
<xsl:value-of select="f_name" />
</fo:block>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="border-right-style">none</xsl:attribute>
<xsl:attribute name="padding-top">4mm</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</fo:table-cell>
<xsl:call-template name="zelle" /> 
</fo:table-row>
</xsl:if>
</xsl:for-each>




<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="zelle">
<fo:table-cell border-width="0.5mm"  padding-left="4mm" border-style="none">
<fo:block>
<xsl:choose>
<xsl:when test="position()=1">
<xsl:attribute name="font-size">14pt</xsl:attribute>
<xsl:attribute name="font-weight">bold</xsl:attribute>
<xsl:attribute name="text-transform">capitalize</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="font-size">12pt</xsl:attribute>
</xsl:otherwise>
</xsl:choose> 
    <xsl:choose>
      
	<xsl:when test="@typ='2' or @typ='8' or @typ='3'"> <!-- DecimalFormat -->
		<!--<xsl:attribute name="class">decimal</xsl:attribute>-->
		
		<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="Times, 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 !='' and wert/@varname !='id'">

		<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="Times, serif" line-height="16pt" font-size="14pt">
	<xsl:value-of select="wert" />
	</fo:block>
	</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>