<?xml version='1.0' encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" />
<xsl:template match="root">
<html>
<head>
<title><xsl:value-of select="param[@id='HTMLTITLE']" disable-output-escaping="yes" /></title>
<link rel="stylesheet" href="css.rhtml" type="text/css" media="screen" />
<xsl:apply-templates select="reload" />
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
   
   <xsl:attribute name="lang">zh</xsl:attribute>

   <center>
   <table border="0" cellspacing="0" cellpadding="0">
      <xsl:if test="param[@id='HTML.WIDTH']">   
      	<xsl:attribute name="width"><xsl:value-of select="param[@id='HTML.WIDTH']" /></xsl:attribute>
      </xsl:if>
      <tr>
         <td colspan="2">
	      	<xsl:if test="lefturls">   
      			<xsl:attribute name="colspan">2</xsl:attribute>
	      	</xsl:if>
		<h2><xsl:value-of select="param[@id='HTML.TITLE']" disable-output-escaping="yes" /></h2>
		<xsl:apply-templates select="topurls" />
         </td>
      </tr>
      <tr>
         <xsl:if test="lefturls"> 
	 <td width="80" valign="top">
		<xsl:apply-templates select="lefturls" />
	 </td>
         </xsl:if>
         <td align="center" valign="top" width="96%" >
	 <div>
	    <xsl:apply-templates select="inputs" />
	    <xsl:apply-templates select="urls" />
            <xsl:choose>
	        <xsl:when test="layout">   
                    <xsl:apply-templates select="layout" />
                </xsl:when>
                <xsl:otherwise>
   	            <xsl:apply-templates select="webchart" />
                </xsl:otherwise>
            </xsl:choose>
	 </div>
	 </td>
      </tr>
   </table>   
   </center>

</body>
</html>
</xsl:template>

<xsl:template match="reload" >
    <script language="JavaScript">
        window.timer=window.setTimeout('window.location.href="<xsl:value-of select="." />";',<xsl:value-of select="@time" /> * 1000);
    </script>
</xsl:template>

<xsl:template match="layout" >
    <table border="0" width="100%">
    <tr>
    <xsl:for-each select="column">
        <xsl:variable name="rowid"><xsl:value-of select="@id" /></xsl:variable>
	<td valign="top">
    	    <xsl:attribute name="width"><xsl:value-of select="." /></xsl:attribute>
            <xsl:apply-templates select="//webchart[@layout = $rowid]" />
	</td>
    </xsl:for-each>
    </tr>
    </table>
</xsl:template>

<xsl:template match="urls" >
    <div>
    <xsl:for-each select="url">
	<xsl:choose>
	    <xsl:when test="@id = '-' or @sep">   
	    	<xsl:value-of select="." disable-output-escaping="yes" />
	    </xsl:when>
	    <xsl:otherwise>   
	    	<a>
	    		<xsl:attribute name="href"><xsl:value-of select="." /></xsl:attribute>
	    		<xsl:value-of select="@id" />
	    	</a>
	    </xsl:otherwise>
	</xsl:choose>
    </xsl:for-each>
    </div>
</xsl:template>

<xsl:template match="topurls" >
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr height="30">
    <xsl:for-each select="url">
        <td width="80">
	<xsl:choose>
	    <xsl:when test="@id = '-' or @sep">   
	    	<xsl:value-of select="." disable-output-escaping="yes" />
	    </xsl:when>
	    <xsl:otherwise>   
	    	<a>
	    		<xsl:attribute name="href"><xsl:value-of select="." /></xsl:attribute>
	    		<xsl:value-of select="@id" />
	    	</a>
	    </xsl:otherwise>
	</xsl:choose>
        </td>
    </xsl:for-each>
    <td><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td>
    </tr>
    </table>
</xsl:template>

<xsl:template match="lefturls" >
    <p>
    <xsl:for-each select="url">
        <div>
	<xsl:choose>
	    <xsl:when test="@id = '-' or @sep">   
	    	<xsl:value-of select="." disable-output-escaping="yes" />
	    </xsl:when>
	    <xsl:otherwise>   
	    	<a>
	    		<xsl:attribute name="href"><xsl:value-of select="." /></xsl:attribute>
	    		<xsl:value-of select="@id" />
	    	</a>
	    </xsl:otherwise>
	</xsl:choose>
        </div>
    </xsl:for-each>
    </p>
</xsl:template>

<xsl:template match="inputs" >
    <div>
    <form method="get">
    <xsl:attribute name="action"><xsl:value-of select="//param[@id='REQUEST.FILE']" /></xsl:attribute>
    <xsl:for-each select="item">
    	<xsl:if test="@label">
    		<xsl:value-of select="@label" />
    	</xsl:if>
        <xsl:choose>
        <xsl:when test="@type = 'custom'">
 		<xsl:value-of select="@value" disable-output-escaping="yes" />
        </xsl:when>
        <xsl:when test="@type = 'option'">
        <select>
 	    <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
  	    <xsl:for-each select="option">
            <option>
                <xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
    		<xsl:if test="@selected">
    			<xsl:attribute name="selected">yes</xsl:attribute>
    		</xsl:if>
                <xsl:value-of select="." />
            </option>
            </xsl:for-each>
        </select>
        </xsl:when>
        <xsl:otherwise>
    	<input>
    		<xsl:attribute name="type"><xsl:value-of select="@type" /></xsl:attribute>
    		<xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
    		<xsl:attribute name="value"><xsl:value-of select="@value" /></xsl:attribute>
    		<xsl:if test="@size">
    			<xsl:attribute name="size"><xsl:value-of select="@size" /></xsl:attribute>
    		</xsl:if>
    	</input>
        </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
    <input type="submit" value="Query" />
    </form>
    </div>
</xsl:template>

<xsl:template match="webchart" >
    <xsl:if test="dataset">
        <table border="0" width="100%" cellspacing="0" cellpadding="2">
            <caption align="center"><font size="5"><xsl:value-of select="title" /></font></caption>
   	    <xsl:apply-templates select="dataset" />
        </table>	
    </xsl:if>
    <xsl:if test="image">
        <xsl:apply-templates select="image" />
    </xsl:if>
    <xsl:if test="memo">
        <p><xsl:value-of select="memo" disable-output-escaping="yes" /></p>
    </xsl:if>
</xsl:template>

<xsl:template name="default-dataset" match="dataset" >
<xsl:choose>
<xsl:when test="page">
   <tr>
   <xsl:for-each select="page">
       <td valign="top">
	<table border="1" width="100%" cellspacing="0" cellpadding="2">
	<tr>
	<xsl:for-each select="../head/col">
	    <th>
        	<xsl:attribute name="width">
			<xsl:value-of select="@size" />
		</xsl:attribute>
		<xsl:value-of select="label" disable-output-escaping="yes" />
	    </th>
	</xsl:for-each>
	</tr>
	<xsl:for-each select="row">
	    <xsl:variable name="rowid"><xsl:value-of select="@id" /></xsl:variable>
            <xsl:if test="@color">
                 <xsl:attribute name="bgcolor"><xsl:value-of select="@color" /></xsl:attribute>
            </xsl:if>
	    <tr>
		<xsl:for-each select="col">
		<xsl:choose>
		    <xsl:when test="@grp">
			<xsl:if test="@grp &gt; 0">
			<td>
			        <xsl:if test="@grp &gt; 1">
				    <xsl:attribute name="rowspan">
					<xsl:value-of select="@grp" />
				    </xsl:attribute>
				</xsl:if>
				<xsl:attribute name="align">
					<xsl:value-of select="@align" />
				</xsl:attribute>
				
				<xsl:choose>
					<xsl:when test="@href">
				    		<a>
							<xsl:attribute name="href">
							    <xsl:value-of select="@href" />
							</xsl:attribute>				    		
				    			<xsl:value-of select="." disable-output-escaping="yes" />
				    		</a>  
		    			</xsl:when>
		    			<xsl:otherwise>				
				    		<xsl:value-of select="." disable-output-escaping="yes" />  
		    			</xsl:otherwise>				
		    		</xsl:choose>
			</td>
			</xsl:if>
		    </xsl:when>
		    <xsl:otherwise>
			<td>
				<xsl:if test="$rowid mod 2 = 1">
					<xsl:attribute name="bgcolor">#eeeeee</xsl:attribute>					
				</xsl:if>
				
				<xsl:attribute name="align">
					<xsl:value-of select="@align" />
				</xsl:attribute>
				
				<xsl:choose>
					<xsl:when test="@href">
				    		<a>
							<xsl:attribute name="href">
								<xsl:value-of select="@href" />
							</xsl:attribute>				    		
				    			<xsl:value-of select="." disable-output-escaping="yes" />
				    		</a>  
		    			</xsl:when>
		    			<xsl:otherwise>				
				    		<xsl:value-of select="." disable-output-escaping="yes" />  
		    			</xsl:otherwise>				
		    		</xsl:choose>
			</td>
		    </xsl:otherwise>
		</xsl:choose>
		</xsl:for-each>
	    </tr>
	</xsl:for-each>
        </table>
       </td>
   </xsl:for-each>
   </tr>
</xsl:when>
<xsl:otherwise>
<tr>
<td>
 <xsl:choose>
    <xsl:when test="@form">
        <table border="1" width="100%" cellspacing="0" cellpadding="2">
	<xsl:for-each select="row">
	    <xsl:variable name="rowid"><xsl:value-of select="@id" /></xsl:variable>
	    <xsl:variable name="colcount"><xsl:value-of select="count(col)" /></xsl:variable>
	    <xsl:for-each select="col">
		<xsl:variable name="colid"><xsl:value-of select="@id" /></xsl:variable>
		<xsl:variable name="label"><xsl:value-of select="../../head/col[@id=$colid]/label" /></xsl:variable>
		<tr>
	    	   <xsl:if test="@id = 1">
			<td width="10%" align="center">
				<xsl:attribute name="rowspan">
					<xsl:value-of select="$colcount" />
				</xsl:attribute>
				<xsl:value-of select="$rowid"/>
			</td>
	    	   </xsl:if>
		   <td width="20%" align="center"><xsl:value-of select="$label" disable-output-escaping="yes" /></td>
		   <td><xsl:value-of select="." disable-output-escaping="yes" /></td>
	        </tr>
            </xsl:for-each>
	</xsl:for-each>
	</table>
    </xsl:when>
    <xsl:when test="@edit">
        <table border="0" width="100%" cellspacing="0" cellpadding="1">
	<xsl:for-each select="row">
 	    <form method="post">
	    <xsl:attribute name="action"><xsl:value-of select="//param[@id='REQUEST.FILE']" /></xsl:attribute>
	    <xsl:for-each select="col">
		<xsl:variable name="colid"><xsl:value-of select="@id" /></xsl:variable>
		<xsl:variable name="label"><xsl:value-of select="../../head/col[@id=$colid]/label" /></xsl:variable>
		<xsl:variable name="fname"><xsl:value-of select="../../head/col[@id=$colid]/name" /></xsl:variable>
		<xsl:variable name="fsize"><xsl:value-of select="../../head/col[@id=$colid]/@len" /></xsl:variable>
		<xsl:variable name="iskey"><xsl:value-of select="../../head/col[@id=$colid]/@pk" /></xsl:variable>
		<xsl:variable name="formt"><xsl:value-of select="../../head/col[@id=$colid]/@form" /></xsl:variable>
		<tr>
		   <td width="20%" align="center"><xsl:value-of select="$label" disable-output-escaping="yes" /></td>
		   <td>
			<xsl:if test="$formt = 'text'">
			   <input type="text">
				<xsl:attribute name="name"><xsl:value-of select="$fname" /></xsl:attribute>
				<xsl:attribute name="size"><xsl:value-of select="$fsize" /></xsl:attribute>
				<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
				<xsl:if test="$iskey = 'yes'">
					<xsl:attribute name="readonly">yes</xsl:attribute>
				</xsl:if>
			   </input>
			</xsl:if>
			<xsl:if test="$formt = 'textarea'">
			   <textarea rows="10" cols="80">
				<xsl:attribute name="name"><xsl:value-of select="$fname" /></xsl:attribute>
				<xsl:value-of select="." />
			   </textarea>
			</xsl:if>
		   </td>
	        </tr>
            </xsl:for-each>
	    <tr><td colspan="2" align="center"><input type="submit" name="sqleditmode" value="Update" /></td></tr>
	    </form>
	</xsl:for-each>
	<xsl:for-each select="head">
 	    <form method="post">
	    <xsl:attribute name="action"><xsl:value-of select="//param[@id='REQUEST.FILE']" /></xsl:attribute>
	    <xsl:for-each select="col">
		<xsl:variable name="colid"><xsl:value-of select="@id" /></xsl:variable>
		<xsl:variable name="label"><xsl:value-of select="../../head/col[@id=$colid]/label" /></xsl:variable>
		<xsl:variable name="fname"><xsl:value-of select="../../head/col[@id=$colid]/name" /></xsl:variable>
		<xsl:variable name="fsize"><xsl:value-of select="../../head/col[@id=$colid]/@len" /></xsl:variable>
		<tr>
		   <td width="20%" align="center"><xsl:value-of select="$label" disable-output-escaping="yes" /></td>
		   <td>
			<input type="text">
				<xsl:attribute name="name"><xsl:value-of select="$fname" /></xsl:attribute>
				<xsl:attribute name="size"><xsl:value-of select="$fsize" /></xsl:attribute>
			</input>
		   </td>
	        </tr>
            </xsl:for-each>
	    <tr><td colspan="2" align="center"><input type="submit" name="sqleditmode" value="Insert" /></td></tr>
	    </form>
	</xsl:for-each>
        </table>
    </xsl:when>
    <xsl:otherwise>
	<table border="1" width="100%" cellspacing="0" cellpadding="2">
	<tr>
	<xsl:for-each select="head/col">
	    <th>
        	<xsl:attribute name="width">
			<xsl:value-of select="@size" />
		</xsl:attribute>
		<xsl:value-of select="label" disable-output-escaping="yes" />
	    </th>
	</xsl:for-each>
	</tr>
	<xsl:for-each select="row">
	    <xsl:variable name="rowid"><xsl:value-of select="@id" /></xsl:variable>
	    <tr>
                <xsl:if test="@color">
                    <xsl:attribute name="bgcolor"><xsl:value-of select="@color" /></xsl:attribute>
                </xsl:if>
		<xsl:for-each select="col">
		<xsl:choose>
		    <xsl:when test="@grp">
			<xsl:if test="@grp &gt; 0">
			<td>
			        <xsl:if test="@grp &gt; 1">
				    <xsl:attribute name="rowspan">
					<xsl:value-of select="@grp" />
				    </xsl:attribute>
				</xsl:if>
				<xsl:attribute name="align">
					<xsl:value-of select="@align" />
				</xsl:attribute>
				
				<xsl:choose>
					<xsl:when test="@href">
				    		<a>
							<xsl:attribute name="href">
							    <xsl:value-of select="@href" />
							</xsl:attribute>				    		
				    			<xsl:value-of select="." disable-output-escaping="yes" />
				    		</a>  
		    			</xsl:when>
		    			<xsl:otherwise>				
				    		<xsl:value-of select="." disable-output-escaping="yes" />  
		    			</xsl:otherwise>				
		    		</xsl:choose>
			</td>
			</xsl:if>
		    </xsl:when>
		    <xsl:otherwise>
			<td>
                                <!--
				<xsl:if test="$rowid mod 2 = 1">
					<xsl:attribute name="bgcolor">#eeeeee</xsl:attribute>					
				</xsl:if>
				-->

				<xsl:attribute name="align">
					<xsl:value-of select="@align" />
				</xsl:attribute>
				
				<xsl:choose>
					<xsl:when test="@href">
				    		<a>
							<xsl:attribute name="href">
								<xsl:value-of select="@href" />
							</xsl:attribute>				    		
				    			<xsl:value-of select="." disable-output-escaping="yes" />
				    		</a>  
		    			</xsl:when>
		    			<xsl:otherwise>				
				    		<xsl:value-of select="." disable-output-escaping="yes" />  
		    			</xsl:otherwise>				
		    		</xsl:choose>
			</td>
		    </xsl:otherwise>
		</xsl:choose>
		</xsl:for-each>
	    </tr>
	</xsl:for-each>
        </table>
    </xsl:otherwise>
 </xsl:choose>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="image">
   <div style="float:left;">
   <img border="0" align="center" vspace="0">
	<xsl:attribute name="src">
		<xsl:value-of select="file" disable-output-escaping="yes" />
	</xsl:attribute>
	<xsl:attribute name="usemap">#<xsl:value-of select="image_map/@name" /></xsl:attribute> 
   </img>
   <xsl:for-each select="image_map">
      <map>
	<xsl:attribute name="name">
		<xsl:value-of select="@name" />
        </xsl:attribute>
	<xsl:for-each select="mapitem">
	   <area>
	      <xsl:attribute name="title"><xsl:value-of select="title" /></xsl:attribute>
	      <xsl:attribute name="shape"><xsl:value-of select="shape" /></xsl:attribute>
	      <xsl:attribute name="coords"><xsl:value-of select="coords" /></xsl:attribute>
	      <xsl:attribute name="href"><xsl:value-of select="href" /></xsl:attribute>
	  </area>
	</xsl:for-each>
      </map>
    </xsl:for-each>
    </div>
</xsl:template>

</xsl:stylesheet>

