<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:inet="http://www.inetsoftware.de">

	<xsl:output method="xml" version="1.0" encoding="UTF-8"
		indent="yes"
		cdata-section-elements="parameterDescription defaultValueExpression queryString variableExpression text textFieldExpression imageExpression subreportParameterExpression connectionExpression subreportExpression" />
	<!-- position rate from crystal to jasper -->
	<xsl:variable name="positionRate">15</xsl:variable>

	<xsl:template match="inet:Report">
		<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">
			<!-- uuid="" -->
			<!-- variables -->
			<xsl:variable name="pageWidth"
				select="round(ReportProperties/PageWidth/@value div $positionRate)" />
			<xsl:variable name="pageHeight"
				select="round(ReportProperties/PageHeight/@value div $positionRate)" />
			<xsl:variable name="leftMargin"
				select="round(ReportProperties/PageMarginLeft/@value div $positionRate)" />
			<xsl:variable name="rightMargin"
				select="round(ReportProperties/PageMarginRight/@value div $positionRate)" />
			<xsl:variable name="topMargin"
				select="round(ReportProperties/PageMarginTop/@value div $positionRate)" />
			<xsl:variable name="bottomMargin"
				select="round(ReportProperties/PageMarginBottom/@value div $positionRate)" />
			<xsl:attribute name="name"><xsl:value-of select="@id" /></xsl:attribute>
			<xsl:attribute name="pageWidth"><xsl:value-of select="$pageWidth" /></xsl:attribute>
			<xsl:attribute name="pageHeight"><xsl:value-of select="$pageHeight" /></xsl:attribute>
			<xsl:attribute name="columnWidth"><xsl:value-of
				select="round($pageWidth - $leftMargin - $rightMargin)" /></xsl:attribute>
			<xsl:attribute name="leftMargin"><xsl:value-of select="$leftMargin" /></xsl:attribute>
			<xsl:attribute name="rightMargin"><xsl:value-of select="$rightMargin" /></xsl:attribute>
			<xsl:attribute name="topMargin"><xsl:value-of select="$topMargin" /></xsl:attribute>
			<xsl:attribute name="bottomMargin"><xsl:value-of select="$bottomMargin" /></xsl:attribute>

			<!-- parameters -->
			<parameter name="WHERE_CONDITION" class="java.lang.String">
				<parameterDescription>where子句</parameterDescription>
				<defaultValueExpression>"where rownum&lt;=1"
				</defaultValueExpression>
			</parameter>
			<parameter name="REPORT_DIR" class="java.lang.String">
				<parameterDescription>报表的路径</parameterDescription>
				<defaultValueExpression>"/mnt/data/reports"</defaultValueExpression>
			</parameter>

			<!-- subreport parameters -->
			<xsl:for-each select="PromptFields/Field[@type='PromptVarField']">
				<xsl:variable name="name" select="substring-after(Name/@value,'Pm-')" />
				<xsl:if test="$name">
					<parameter>
						<!-- name -->
						<xsl:attribute name="name"><xsl:value-of
							select="$name" /></xsl:attribute>
						<!-- class -->
						<xsl:attribute name="class">
							<xsl:call-template name="typeToClass">
								<xsl:with-param name="type">
									<xsl:value-of select="@valueType" />
								</xsl:with-param>
							</xsl:call-template>
						</xsl:attribute>
						<!-- default value -->
						<defaultValueExpression>
							<xsl:value-of select="concat('$P{',$name,'}')" />
						</defaultValueExpression>
					</parameter>
				</xsl:if>
			</xsl:for-each>

			<queryString>
				select * from dual;
			</queryString>

			<!-- fields -->
			<xsl:for-each select="Datasource/Tablesource/Column">
				<xsl:variable name="tableNameAlias" select="../@alias" />
				<field>
					<xsl:attribute name="name">
						<xsl:value-of select="@name" />
					</xsl:attribute>
					<xsl:attribute name="class">
						<xsl:call-template name="typeToClass">
							<xsl:with-param name="type">
								<xsl:value-of select="@type" />
							</xsl:with-param>
						</xsl:call-template>
					</xsl:attribute>
				</field>
			</xsl:for-each>

			<!-- variables -->
			<!-- FormulaFields to variable -->
			<xsl:for-each select="FormulaFields/Field[@type='FormulaField']">
				<variable>
					<xsl:attribute name="name">
						<xsl:value-of select="Name/@value" /> 
					</xsl:attribute>
					<variableExpression>
						<xsl:value-of select="TextData" />
					</variableExpression>
				</variable>
			</xsl:for-each>
			<!-- PromptFields(don't start with 'Pm-') to variable -->
			<xsl:for-each select="PromptFields/Field[@type='PromptVarField']">
				<xsl:variable name="name" select="Name/@value" />
				<xsl:choose>
					<xsl:when test="substring-after($name,'Pm-')" />
					<xsl:otherwise>
						<variable>
							<xsl:attribute name="name">
								<xsl:value-of select="$name" />
							</xsl:attribute>
							<variableExpression>
								<xsl:value-of select="DefaultPromptValues/DefaultValue/@value" />
							</variableExpression>
						</variable>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
			<!-- SpecialVarField to variable -->
			<xsl:for-each select="//Reference[@type='SpecialVarField']">
				<variable>
					<xsl:attribute name="name">
						<xsl:value-of select="@value" /> 
					</xsl:attribute>
				</variable>
			</xsl:for-each>

			<!-- group -->
			<xsl:for-each select="AreaPair[@type='GroupAreaPair']">
				<xsl:variable name="field"
					select="AreaPairProperties/Reference/@value" />
				<group>
					<xsl:attribute name="name">
						<xsl:choose>
							<xsl:when test="substring-after($field,'.')">
								<xsl:value-of select="substring-after($field,'.')" />
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="$field" />
							</xsl:otherwise>
						</xsl:choose>
					</xsl:attribute>
					<groupExpression>
						<xsl:call-template name="removeTableName">
							<xsl:with-param name="field" select="$field" />
						</xsl:call-template>
					</groupExpression>
					<groupHeader>
						<band>
							<xsl:attribute name="height"><xsl:value-of
								select="round(sum(Area[@type='GroupHeader']/Section/@height) div $positionRate)" /></xsl:attribute>
							<xsl:for-each select="Area[@type='GroupHeader']/Section">
								<xsl:variable name="sectionPosition" select="position()" />
								<xsl:call-template name="sections">
									<xsl:with-param name="sectionPosition" select="$sectionPosition" />
									<xsl:with-param name="previousSectionsHeight" >0</xsl:with-param>
								</xsl:call-template>
							</xsl:for-each>
						</band>
					</groupHeader>
					<groupFooter>
						<band>
							<xsl:attribute name="height"><xsl:value-of
								select="round(sum(Area[@type='GroupFooter']/Section/@height) div $positionRate)" /></xsl:attribute>
							<xsl:for-each select="Area[@type='GroupFooter']/Section">
								<xsl:variable name="sectionPosition" select="position()" />
								<xsl:call-template name="sections">
									<xsl:with-param name="sectionPosition" select="$sectionPosition" />
									<xsl:with-param name="previousSectionsHeight" >0</xsl:with-param>
								</xsl:call-template>
							</xsl:for-each>
						</band>
					</groupFooter>
				</group>
			</xsl:for-each>

			<!-- title -->
			<xsl:if test="AreaPair[@type='ReportAreaPair']/Area[@type='ReportHeader']">
				<title>
					<band splitType="Stretch">
						<xsl:attribute name="height"><xsl:value-of
							select="round(sum(AreaPair[@type='ReportAreaPair']/Area[@type='ReportHeader']/Section/@height) div $positionRate)" /></xsl:attribute>
						<xsl:for-each select="AreaPair[@type='ReportAreaPair']/Area[@type='ReportHeader']/Section">
							<xsl:variable name="sectionPosition" select="position()" />
							<xsl:call-template name="sections">
								<xsl:with-param name="sectionPosition" select="$sectionPosition" />
								<xsl:with-param name="previousSectionsHeight" >0</xsl:with-param>
							</xsl:call-template>
						</xsl:for-each>
					</band>
				</title>
			</xsl:if>
			<!-- pageHeader -->
			<xsl:if test="AreaPair[@type='PageAreaPair']/Area[@type='PageHeader']">
				<pageHeader>
					<band splitType="Stretch">
						<xsl:attribute name="height"><xsl:value-of
							select="round(sum(AreaPair[@type='PageAreaPair']/Area[@type='PageHeader']/Section/@height) div $positionRate)" /></xsl:attribute>
						<xsl:for-each select="AreaPair[@type='PageAreaPair']/Area[@type='PageHeader']/Section">
							<xsl:variable name="sectionPosition" select="position()" />
							<xsl:call-template name="sections">
								<xsl:with-param name="sectionPosition" select="$sectionPosition" />
								<xsl:with-param name="previousSectionsHeight" >0</xsl:with-param>
							</xsl:call-template>
						</xsl:for-each>
					</band>
				</pageHeader>
			</xsl:if>
			<!-- detail -->
			<xsl:if test="AreaPair[@type='DetailArea']/Area[@type='Detail']">
				<detail>
					<band splitType="Prevent">
						<xsl:attribute name="height"><xsl:value-of
							select="round(sum(AreaPair[@type='DetailArea']/Area[@type='Detail']/Section/@height) div $positionRate)" /></xsl:attribute>
						<xsl:for-each select="AreaPair[@type='DetailArea']/Area[@type='Detail']/Section">
							<xsl:variable name="sectionPosition" select="position()" />
							<xsl:call-template name="sections">
								<xsl:with-param name="sectionPosition" select="$sectionPosition" />
								<xsl:with-param name="previousSectionsHeight" >0</xsl:with-param>
							</xsl:call-template>
						</xsl:for-each>
					</band>
				</detail>
			</xsl:if>

			<!-- pageFooter -->
			<xsl:if test="AreaPair[@type='PageAreaPair']/Area[@type='PageFooter']">
				<pageFooter>
					<band splitType="Prevent">
						<xsl:attribute name="height"><xsl:value-of
							select="round(sum(AreaPair[@type='PageAreaPair']/Area[@type='PageFooter']/Section/@height) div $positionRate)" /></xsl:attribute>
						<xsl:for-each select="AreaPair[@type='PageAreaPair']/Area[@type='PageFooter']/Section">
							<xsl:variable name="sectionPosition" select="position()" />
							<xsl:call-template name="sections">
								<xsl:with-param name="sectionPosition" select="$sectionPosition" />
								<xsl:with-param name="previousSectionsHeight" >0</xsl:with-param>
							</xsl:call-template>
						</xsl:for-each>
					</band>
				</pageFooter>
			</xsl:if>

			<!-- lastPageFooter -->
			<xsl:if test="AreaPair[@type='ReportAreaPair']/Area[@type='ReportFooter']">
				<lastPageFooter>
					<band splitType="Prevent">
						<xsl:attribute name="height"><xsl:value-of
							select="round(sum(AreaPair[@type='ReportAreaPair']/Area[@type='ReportFooter']/Section/@height) div $positionRate)" /></xsl:attribute>
						<xsl:for-each select="AreaPair[@type='ReportAreaPair']/Area[@type='ReportFooter']/Section">
							<xsl:variable name="sectionPosition" select="position()" />
							<xsl:call-template name="sections">
								<xsl:with-param name="sectionPosition" select="$sectionPosition" />
								<xsl:with-param name="previousSectionsHeight" >0</xsl:with-param>
							</xsl:call-template>
						</xsl:for-each>
					</band>
				</lastPageFooter>
			</xsl:if>
		</jasperReport>
	</xsl:template>

	<!-- multi sections -->
	<xsl:template name="sections">
		<xsl:param name="sectionPosition" />
		<xsl:param name="previousSectionsHeight" />
		<xsl:choose>
			<!-- if contains more than one section, then calculate the height of previous sections recursively -->
			<xsl:when test="$sectionPosition > 1">
				<xsl:call-template name="sections">
					<xsl:with-param name="sectionPosition" select="$sectionPosition - 1" />
					<xsl:with-param name="previousSectionsHeight" select="$previousSectionsHeight + ../Section[$sectionPosition - 1]/@height" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:for-each select="Element">
					<xsl:call-template name="element">
						<xsl:with-param name="previousSectionsHeight" select="$previousSectionsHeight" />
					</xsl:call-template>
				</xsl:for-each>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- process element -->
	<xsl:template name="element">
		<!-- height of previous sections -->
		<xsl:param name="previousSectionsHeight" />
		<xsl:variable name="type" select="@type" />
		<xsl:choose>
			<xsl:when test="$type='Box'" />
			<xsl:when test="$type='Line'" />
			<!-- staticText -->
			<xsl:when test="$type='Text'">
				<staticText>
					<reportElement mode="Opaque">
						<!-- position -->
						<xsl:call-template name="position" >
							<xsl:with-param name="heightFactor">1.25</xsl:with-param>
							<xsl:with-param name="previousSectionsHeight" select="$previousSectionsHeight" />
						</xsl:call-template>
						<!-- color -->
						<xsl:variable name="foreColor"
							select="Element/Element/FontProperties/FontColor/@value" />
						<xsl:variable name="backColor"
							select="BorderProperties/BackgroundColor/@value" />
						<xsl:if test="$foreColor">
							<xsl:attribute name="forecolor">
								<xsl:value-of
								select="$foreColor mod 256 * 256 * 256 + floor($foreColor div 256) mod 256 * 256 + floor($foreColor div (256 * 256))" />
							</xsl:attribute>
						</xsl:if>
						<xsl:if test="$backColor">
							<xsl:attribute name="backcolor">
								<xsl:value-of
								select="$backColor mod 256 * 256 * 256 + floor($backColor div 256) mod 256 * 256 + floor($backColor div (256 * 256))" />
							</xsl:attribute>
						</xsl:if>
					</reportElement>
					<!-- border -->
					<xsl:call-template name="border" />
					<!-- align -->
					<textElement verticalAlignment="Middle">
						<xsl:variable name="textAlignment"
							select="Element/CommonProperties/HorizontalAlign/@value" />
						<!-- horizontal align -->
						<xsl:if test="$textAlignment">
							<xsl:attribute name="textAlignment">
								<xsl:choose>
									<xsl:when test="$textAlignment='1'">Left</xsl:when>
									<xsl:when test="$textAlignment='2'">Center</xsl:when>
									<xsl:when test="$textAlignment='3'">Right</xsl:when>
								</xsl:choose>
							</xsl:attribute>
						</xsl:if>
						<!-- font -->
						<font fontName="Microsoft YaHei UI">
							<!-- font size -->
							<xsl:if test="Element/Element/FontProperties/FontSize/@value">
								<xsl:attribute name="size"><xsl:value-of
									select="round(Element/Element/FontProperties/FontSize/@value div $positionRate * 0.75)" /></xsl:attribute>
							</xsl:if>
							<!-- font style -->
							<xsl:variable name="fontStyle"
								select="Element/Element/FontProperties/FontStyle/@value" />
							<xsl:choose>
								<xsl:when test="$fontStyle mod 4 ='1'">
									<xsl:attribute name="isBold">true</xsl:attribute>
								</xsl:when>
								<xsl:when test="$fontStyle mod 4 ='2'">
									<xsl:attribute name="isItalic">true</xsl:attribute>
								</xsl:when>
								<xsl:when test="$fontStyle mod 4 ='3'">
									<xsl:attribute name="isBold">true</xsl:attribute>
									<xsl:attribute name="isItalic">true</xsl:attribute>
								</xsl:when>
							</xsl:choose>
							<!-- font underline -->
							<xsl:if test="Element/Element/FontProperties/Underline/@value">
								<xsl:attribute name="isUnderline">true</xsl:attribute>
							</xsl:if>
							<!-- font strikethrough -->
							<xsl:if test="Element/Element/FontProperties/Strikeout/@value">
								<xsl:attribute name="isStrikeThrough">true</xsl:attribute>
							</xsl:if>
						</font>
					</textElement>
					<text>
						<xsl:value-of select="Element/Element/TextData" />
					</text>
				</staticText>
			</xsl:when>
			<!-- textField -->
			<xsl:when test="$type='FieldElement'">
				<textField isStretchWithOverflow="true" isBlankWhenNull="true">
					<reportElement stretchType="RelativeToTallestObject"
						mode="Opaque">
						<!-- position -->
						<xsl:call-template name="position" >
							<xsl:with-param name="heightFactor">1.25</xsl:with-param>
							<xsl:with-param name="previousSectionsHeight" select="$previousSectionsHeight" />
						</xsl:call-template>
						<!-- color -->
						<xsl:variable name="foreColor"
							select="FontProperties/FontColor/@value" />
						<xsl:variable name="backColor"
							select="BorderProperties/BackgroundColor/@value" />
						<xsl:if test="$foreColor">
							<xsl:attribute name="forecolor">
								<xsl:value-of
								select="$foreColor mod 256 * 256 * 256 + floor($foreColor div 256) mod 256 * 256 + floor($foreColor div (256 * 256))" />
							</xsl:attribute>
						</xsl:if>
						<xsl:if test="$backColor">
							<xsl:attribute name="backcolor">
								<xsl:value-of
								select="$backColor mod 256 * 256 * 256 + floor($backColor div 256) mod 256 * 256 + floor($backColor div (256 * 256))" />
							</xsl:attribute>
						</xsl:if>
					</reportElement>
					<!-- border -->
					<xsl:call-template name="border" />
					<!-- align -->
					<textElement verticalAlignment="Middle">
						<xsl:variable name="textAlignment"
							select="CommonProperties/HorizontalAlign/@value" />
						<!-- horizontal align -->
						<xsl:if test="$textAlignment">
							<xsl:attribute name="textAlignment">
								<xsl:choose>
									<xsl:when test="$textAlignment='1'">Left</xsl:when>
									<xsl:when test="$textAlignment='2'">Center</xsl:when>
									<xsl:when test="$textAlignment='3'">Right</xsl:when>
								</xsl:choose>
							</xsl:attribute>
						</xsl:if>
						<!-- font -->
						<font fontName="Microsoft YaHei UI">
							<!-- font size -->
							<xsl:if test="FontProperties/FontSize">
								<xsl:attribute name="size"><xsl:value-of
									select="round(FontProperties/FontSize/@value div $positionRate * 0.75)" /></xsl:attribute>
							</xsl:if>
							<!-- font style -->
							<xsl:variable name="fontStyle" select="FontProperties/FontStyle/@value" />
							<xsl:choose>
								<xsl:when test="$fontStyle mod 4 ='1'">
									<xsl:attribute name="isBold">true</xsl:attribute>
								</xsl:when>
								<xsl:when test="$fontStyle mod 4 ='2'">
									<xsl:attribute name="isItalic">true</xsl:attribute>
								</xsl:when>
								<xsl:when test="$fontStyle mod 4 ='3'">
									<xsl:attribute name="isBold">true</xsl:attribute>
									<xsl:attribute name="isItalic">true</xsl:attribute>
								</xsl:when>
							</xsl:choose>
							<!-- font underline -->
							<xsl:if test="FontProperties/Underline/@value">
								<xsl:attribute name="isUnderline">true</xsl:attribute>
							</xsl:if>
							<!-- font strikethrough -->
							<xsl:if test="FontProperties/Strikeout/@value">
								<xsl:attribute name="isStrikeThrough">true</xsl:attribute>
							</xsl:if>
						</font>
					</textElement>
					<!-- textFieldExpression -->
					<xsl:if test="Reference">
						<xsl:variable name="type" select="Reference/@type" />
						<xsl:variable name="value" select="Reference/@value" />
						<textFieldExpression>
							<xsl:choose>
								<xsl:when test="$type='DatabaseField'">
									<xsl:call-template name="removeTableName">
										<xsl:with-param name="field" select="$value" />
									</xsl:call-template>
								</xsl:when>
								<xsl:when test="$type='FormulaField'">
									<xsl:value-of select="concat('$V{',substring($value,2),'}')" />
								</xsl:when>
								<xsl:when test="$type='PromptVarField'">
									<xsl:value-of select="concat('$V{',substring($value,2),'}')" />
								</xsl:when>
								<xsl:when test="$type='SpecialVarField'">
									<xsl:value-of select="concat('$V{',$value,'}')" />
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="concat('@Unknown ',$value)" />
								</xsl:otherwise>
							</xsl:choose>
						</textFieldExpression>
					</xsl:if>
				</textField>
			</xsl:when>
			<!-- picture -->
			<xsl:when test="$type='Picture'">
				<image>
					<reportElement mode="Opaque">
						<!-- position -->
						<xsl:call-template name="position">
							<xsl:with-param name="heightFactor">1</xsl:with-param>
							<xsl:with-param name="previousSectionsHeight" select="$previousSectionsHeight" />
						</xsl:call-template>
					</reportElement>
					<imageExpression>
						<xsl:variable name="quot">&quot;</xsl:variable>
						<xsl:value-of
							select="concat('$P{REPORT_DIR}',' + ',$quot,'/Picture/',PictureProperties/Reference/@value,$quot)" />
					</imageExpression>
				</image>
			</xsl:when>
			<!-- subreport -->
			<xsl:when test="$type='Subreport'">
				<subreport>
					<reportElement mode="Opaque">
						<!-- position -->
						<xsl:call-template name="position">
							<xsl:with-param name="heightFactor">1</xsl:with-param>
							<xsl:with-param name="previousSectionsHeight" select="$previousSectionsHeight" />
						</xsl:call-template>
					</reportElement>
					<!-- subreportParameter -->
					<xsl:for-each select="SubreportLinks/SubreportLink">
						<subreportParameter>
							<xsl:variable name="type" select="Reference/@type" />
							<xsl:variable name="value" select="Reference/@value" />
							<xsl:choose>
								<xsl:when test="$type='DatabaseField'">
									<xsl:attribute name="name">
										<xsl:value-of select="$value" />
									</xsl:attribute>
									<subreportParameterExpression>
										<xsl:call-template name="removeTableName">
											<xsl:with-param name="field" select="$value" />
										</xsl:call-template>
									</subreportParameterExpression>
								</xsl:when>
								<xsl:otherwise>
									<xsl:attribute name="name">
										<xsl:value-of select="$value" />
									</xsl:attribute>
									<subreportParameterExpression>
										<xsl:value-of select="concat('@Unknown ',$value)" />
									</subreportParameterExpression>
								</xsl:otherwise>
							</xsl:choose>
						</subreportParameter>
					</xsl:for-each>
					<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
					<!-- sub id <= replace with report name -->
					<id>
						<xsl:value-of select="SubreportProperties/Id/@value" />
					</id>
					<subreportExpression></subreportExpression>
				</subreport>
			</xsl:when>
		</xsl:choose>
	</xsl:template>

	<!-- position -->
	<xsl:template name="position">
		<xsl:param name="heightFactor" />
		<xsl:param name="previousSectionsHeight" />
		<xsl:attribute name="x">
			<xsl:value-of select="round(@x_position div $positionRate)" />
		</xsl:attribute>
		<xsl:attribute name="y">
			<xsl:value-of select="round((@y_position + $previousSectionsHeight) div $positionRate)" />
		</xsl:attribute>
		<xsl:attribute name="width">
			<xsl:value-of select="round(@width div $positionRate)" />
		</xsl:attribute>
		<xsl:attribute name="height">
			<xsl:value-of select="round(@height div $positionRate * $heightFactor)" />
		</xsl:attribute>
	</xsl:template>
	
	<!-- border -->
	<xsl:template name="border">
		<box topPadding="2" leftPadding="2" bottomPadding="2"
			rightPadding="2">
			<pen lineWidth="0.2" />
			<topPen lineWidth="0.2" />
			<leftPen lineWidth="0.2" />
			<bottomPen lineWidth="0.2" />
			<rightPen lineWidth="0.2" />
		</box>
	</xsl:template>
	
	<!-- type of crystal to class of jasper -->
	<xsl:template name="typeToClass">
		<xsl:param name="type" />
		<xsl:choose>
			<xsl:when test="$type='6'">java.math.BigDecimal</xsl:when>
			<xsl:when test="$type='9'">java.sql.Timestamp</xsl:when>
			<xsl:when test="$type='11'">java.lang.String</xsl:when>
			<xsl:when test="$type='15'">java.sql.Timestamp</xsl:when>
		</xsl:choose>
	</xsl:template>
	
	<!-- remove table's name in field -->
	<xsl:template name="removeTableName">
		<xsl:param name="field" />
		<xsl:choose>
			<xsl:when test="substring-after($field,'.')">
				<xsl:value-of select="concat('$F{',substring-after($field,'.'),'}')" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat('$F{',$field,'}')" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>