<?xml version="1.0"  encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="xsl_functions.xsl" />
<xml:output method="xml" />
<xsl:template match="/">
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" 
language="groovy"
pageWidth="842" pageHeight="595"
orientation="Landscape"
columnWidth="782"
leftMargin="16" rightMargin="16" topMargin="14" bottomMargin="16">
<xsl:attribute name="name"><xsl:value-of select="/ergebnisse/ergebnis/maskenname"/></xsl:attribute>
<xsl:text>
</xsl:text>
	<property name="ireport.zoom" value="1.0"/><xsl:text>
</xsl:text>
	<property name="ireport.x" value="0"/><xsl:text>
</xsl:text>
	<property name="ireport.y" value="0"/><xsl:text>
</xsl:text>
	<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/><xsl:text>
</xsl:text>
<queryString language="xPath"><xsl:text><![CDATA[/ergebnisse/ergebnis/ergebniselement/sqlerg/row]]></xsl:text>
	</queryString><xsl:text>
</xsl:text>
<!-- nun die Felder: zuerst der Berichtsname-->
<field name="Berichtsname" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription>
		<xsl:choose>
<xsl:when test="/ergebnisse/@isMakro='true'">
<xsl:text><![CDATA[/ergebnisse/makro/name]]></xsl:text></xsl:when>
<xsl:otherwise><xsl:text><![CDATA[/ergebnisse/ergebnis[ @ordnr='0']/maskenname]]></xsl:text></xsl:otherwise>
</xsl:choose>
</fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>
<!-- dann der Erläuterungstext-->
<field name="Erlaeuterung" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[/ergebnisse/ergebnis[ @ordnr='0']/explanation]]></xsl:text></fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>

<field name="REPORT_HEADING_INSTITUTION" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[/ergebnisse/generalinfo/REPORT_HEADING_INSTITUTION]]></xsl:text></fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>

<field name="REPORT_HEADING_URL" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[/ergebnisse/generalinfo/REPORT_HEADING_URL]]></xsl:text></fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>

<field name="REPORT_LOGO_FILE" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[/ergebnisse/generalinfo/REPORT_LOGO_FILE]]></xsl:text></fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>

<field name="REPORT_HEADING_ADRESS" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[/ergebnisse/generalinfo/REPORT_HEADING_ADRESS]]></xsl:text></fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>

<field name="REPORT_EMAIL" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[/ergebnisse/generalinfo/REPORT_EMAIL]]></xsl:text></fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>

<field name="REPORT_DOCUMENTATION_URL" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[/ergebnisse/generalinfo/REPORT_DOCUMENTATION_URL]]></xsl:text></fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>

	<!-- dann die Tabellenspalten -->
<xsl:for-each select="/ergebnisse/ergebnis/ergebniselement">
<xsl:variable name="ordnr"><xsl:value-of select="@ordnr" /></xsl:variable>
<xsl:for-each select="sqlerg/complete_headers/header">
<xsl:variable name="jasperFieldname">
<xsl:call-template name="createJasperFieldname">
<xsl:with-param name="fieldName_orig" select="wert"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="fldPrefix">
<xsl:choose>
<xsl:when test="/ergebnisse/@isMakro='true'">
<xsl:text>tab_</xsl:text><xsl:value-of select="$ordnr" /></xsl:when>
<xsl:otherwise><xsl:text></xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<field name="{concat($fldPrefix,$jasperFieldname)}">
<xsl:attribute name="class"><xsl:call-template name="getJavaType">
<xsl:with-param name="ordnr"><xsl:value-of select="$ordnr"/></xsl:with-param>
<xsl:with-param name="col_id"><xsl:value-of select="@id"/></xsl:with-param></xsl:call-template></xsl:attribute>
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[col[@id="]]></xsl:text>
		<xsl:value-of select="@id"/><xsl:text><![CDATA[" and wert!=""]]></xsl:text>
		<xsl:if test="/ergebnisse/@isMakro='true'">
		<xsl:text><![CDATA[ and ../../../@ordnr=']]></xsl:text><xsl:value-of select="$ordnr" /><xsl:text>'</xsl:text>
		</xsl:if>
		<xsl:text><![CDATA[]/wert]]></xsl:text>
		</fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:for-each>
	<!-- dann die Legende-->
<xsl:for-each select="distinct-values(//ergebnisse/ergebnis/completefields/feld/@varname)">
<xsl:variable name="jasperFieldname">
<xsl:call-template name="createJasperFieldname">
<xsl:with-param name="fieldName_orig" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="varname">
<xsl:value-of select="." />
</xsl:variable>
<!-- zuerst Label -->
<field name="{concat('legende_',$jasperFieldname,'_label')}" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[/ergebnisse/ergebnis/completefields/feld [@varname="]]></xsl:text><xsl:value-of select="$varname"/><xsl:text><![CDATA["]/@varname]]></xsl:text></fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>
<!--dann Wert-->
<field name="{concat('legende_',$jasperFieldname,'_value')}" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[/ergebnisse/ergebnis/felder/feld [@varname="]]></xsl:text><xsl:value-of select="$varname"/><xsl:text><![CDATA["]/value_caption]]></xsl:text></fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>

</xsl:for-each>
<!--Standatum und User:-->

<field name="standdatum" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[/ergebnisse/ergebnis[ @ordnr='0']/stand]]></xsl:text></fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>
<field name="user" class="java.lang.String">
<xsl:text>
</xsl:text>
		<fieldDescription><xsl:text><![CDATA[/ergebnisse/user]]></xsl:text></fieldDescription><xsl:text>
</xsl:text>
	</field><xsl:text>
</xsl:text>
<background><xsl:text>
</xsl:text>
		<band splitType="Stretch"/><xsl:text>
</xsl:text>
	</background><xsl:text>
</xsl:text>
<!--	<detail><xsl:text>
</xsl:text>
		<band height="290" splitType="Stretch"><xsl:text>
</xsl:text>
		</band><xsl:text>
</xsl:text>
		</detail><xsl:text>
</xsl:text>  -->

	<title>
		<band height="76">
			<textField>
				<reportElement x="0" y="0" width="729" height="20"/>
				<textElement>
					<font fontName="Liberation Sans"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{REPORT_HEADING_INSTITUTION}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="0" y="20" width="729" height="12"/>
				<textElement>
					<font fontName="Liberation Sans"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{REPORT_HEADING_URL}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="0" y="44" width="809" height="18"/>
				<textElement>
					<font fontName="Liberation Sans" size="14" isBold="true"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{Berichtsname}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="24" y="62" width="809" height="10"/>
				<textElement>
					<font fontName="Liberation Sans" size="8"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{standdatum}]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement mode="Transparent" x="0" y="62" width="24" height="10" forecolor="#000000" backcolor="#FFFFFF"/>
				<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single" markup="none">
					<font fontName="Liberation Sans" size="8" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Liberation Sans" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<text><![CDATA[Stand:]]></text>
			</staticText>
			<image>
				<reportElement x="730" y="0" width="80" height="32">
					<printWhenExpression><![CDATA[$F{REPORT_LOGO_FILE}!=null && !$F{REPORT_LOGO_FILE}.equals("") && !$F{REPORT_LOGO_FILE}.equals("@@REPORT_LOGO_FILE@@")]]></printWhenExpression>
				</reportElement>
				<imageExpression class="java.lang.String"><![CDATA["../"+$F{REPORT_LOGO_FILE}]]></imageExpression>
			</image>
		</band>
	</title>
	<detail>
		<band height="323" splitType="Stretch"/>
	</detail>
	<pageFooter>
		<band height="15">
			<staticText>
				<reportElement mode="Transparent" x="0" y="3" width="89" height="12" forecolor="#000000" backcolor="#FFFFFF"/>
				<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single" markup="none">
					<font fontName="Liberation Sans" size="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Liberation Sans" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<text><xsl:text><![CDATA[Erzeugungsdatum:]]></xsl:text></text>
			</staticText>
			<textField pattern="dd.MM.yyyy">
				<reportElement mode="Transparent" x="89" y="3" width="96" height="12" forecolor="#000000" backcolor="#FFFFFF"/>
				<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single" markup="none">
					<font fontName="Liberation Sans" size="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Liberation Sans" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<textFieldExpression class="java.util.Date"><xsl:text><![CDATA[new java.util.Date()]]></xsl:text></textFieldExpression>
			</textField>
			<textField evaluationTime="Report" isBlankWhenNull="false">
				<reportElement key="textField" x="770" y="3" width="39" height="12"/>
				<box>
					<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
				</box>
				<textElement>
					<font fontName="Liberation Sans"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><xsl:text><![CDATA["" + $V{PAGE_NUMBER} + ""]]></xsl:text></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="false">
				<reportElement key="textField" x="676" y="3" width="94" height="12"/>
				<box>
					<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
				</box>
				<textElement textAlignment="Right">
					<font fontName="Liberation Sans"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><xsl:text><![CDATA["Seite " + $V{PAGE_NUMBER} + " von "]]></xsl:text></textFieldExpression>
			</textField>
		</band>
	</pageFooter>


</jasperReport><xsl:text>
</xsl:text>
</xsl:template>
<xsl:template name="getJavaType">
<xsl:param name="ordnr" />
<xsl:param name="col_id" />
<xsl:choose>
<xsl:when test="count(/ergebnisse/ergebnis/ergebniselement[ @ordnr=$ordnr]/sqlerg/row)=0">
<xsl:text>java.lang.String</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="/ergebnisse/ergebnis/ergebniselement[ @ordnr=$ordnr]/sqlerg/row [@no='0']/col [@id=$col_id]">
<!--Transformation:
   3=DecimalFormat
    4=integer
    -7=Boolean
    6=date
    8=timestamp
    9=time
    Default ist
    1=string-->
<xsl:choose>
    
	<xsl:when test="@typ='3'"> <!-- DecimalFormat -->
		<xsl:text>java.lang.Double</xsl:text>
	</xsl:when>
	<xsl:when test="@typ='4'"> <!-- Integer -->
		<xsl:text>java.lang.Integer</xsl:text>
	</xsl:when>
	<xsl:when test="@typ='-7'"> 
		<xsl:text>java.lang.Boolean</xsl:text>
	</xsl:when>
	<xsl:when test="@typ='6'"> 
		<xsl:text>java.util.Date</xsl:text>
	</xsl:when>
	<xsl:when test="@typ='8'"> 
		<xsl:text>java.sql.Timestamp</xsl:text>
	</xsl:when>
	<xsl:when test="@typ='9'"> 
		<xsl:text>java.lang.Time</xsl:text>
	</xsl:when>
	<xsl:otherwise>
	<!--Typ=1 ist string und wird defaultmäßig behandelt -->
		<xsl:text>java.lang.String</xsl:text>
	</xsl:otherwise>
	</xsl:choose>
	</xsl:for-each>
	</xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template name="createJasperFieldname">
<xsl:param name="fieldName_orig" />
<xsl:variable name="feldname_ohne_umbruch">
<xsl:call-template name="remove_linebreaksAndQuot"><xsl:with-param name="volltext"><xsl:value-of select="$fieldName_orig" /></xsl:with-param></xsl:call-template>
</xsl:variable>
<xsl:variable name="feldnameOhneBackslashN">
<xsl:call-template name="search_replace">
<xsl:with-param name="string"><xsl:value-of select="$feldname_ohne_umbruch" /></xsl:with-param>
<xsl:with-param name="search"><xsl:text>\n</xsl:text></xsl:with-param>
<xsl:with-param name="replace"><xsl:text> </xsl:text></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="search_replace">
<xsl:with-param name="string"><xsl:value-of select="$feldnameOhneBackslashN" /></xsl:with-param>
<xsl:with-param name="search"><xsl:text>\000</xsl:text></xsl:with-param>
<xsl:with-param name="replace"><xsl:text> </xsl:text></xsl:with-param>
</xsl:call-template>

<!--
<xsl:call-template name="ohne_umlaut">
<xsl:with-param name="s1"><xsl:value-of select="$feldname_ohne_umbruch" /></xsl:with-param>
</xsl:call-template>-->
</xsl:template>
</xsl:stylesheet>