<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
>
   <xsl:variable name="language">ENGLISH</xsl:variable>
   <xsl:variable name="php_version"><xsl:value-of select="document('../jlex_defaults.xml')//jlex_defaults/php_version"/></xsl:variable>
   <xsl:variable name="jlex_path"><xsl:value-of select="concat('../',$php_version)"/></xsl:variable>
   <xsl:template match="SET">
      <option>
         <xsl:value-of select="ENGLISH"/>
      </option>
   </xsl:template>
   
   <xsl:template match="phrases_and_fields">
      <xsl:param name="count"/>
      <xsl:variable name="name"><xsl:value-of select="concat('db_cols_',$count)"/></xsl:variable>
      <select>
         <xsl:attribute name="name"><xsl:value-of select="$name"/></xsl:attribute>
         <xsl:variable name="file"><xsl:value-of select="."/></xsl:variable>
         <xsl:apply-templates select="document($file)/PHRASES_AND_FIELDS/SET"/>
      </select>
   </xsl:template>
   
   <xsl:template match="reg_exps">
      <xsl:param name="count"/>
      <xsl:variable name="name"><xsl:value-of select="concat('reg_exp_',$count)"/></xsl:variable>
      <select>
         <xsl:attribute name="name"><xsl:value-of select="$name"/></xsl:attribute>
         <xsl:variable name="file"><xsl:value-of select="."/></xsl:variable>
         <xsl:apply-templates select="document($file)/REG_EXPS/SET"/>
      </select>
   </xsl:template>
   
   
   <xsl:template match="connectives">
      <xsl:param name="count"/>
      <xsl:variable name="name"><xsl:value-of select="concat('connective_',$count)"/></xsl:variable>
      <select>
         <xsl:attribute name="name"><xsl:value-of select="$name"/></xsl:attribute>
         <xsl:variable name="file"><xsl:value-of select="."/></xsl:variable>
         <xsl:variable name="nodes" select="document($file)"/>
         <xsl:apply-templates select="$nodes/CONNECTIVES/SET"/>
      </select>
   </xsl:template>
   
   
   <xsl:template name="string">
      <xsl:param name="count"/>
      <xsl:variable name="name"><xsl:value-of select="concat('string_',$count)"/></xsl:variable>
      <input type="text" size="20">
         <xsl:attribute name="name"><xsl:value-of select="$name"/></xsl:attribute>
      </input>
   </xsl:template>
      
   <xsl:template match="xml_char_classes">
      <xsl:variable name="file"><xsl:value-of select="."/></xsl:variable>
      <input type="hidden" name="xml_char_classes">
         <xsl:attribute name="value"><xsl:value-of select="concat('../lex/',.)"/></xsl:attribute>
      </input>
      <tr>
         <td colspan="5"><B>Predefined Character Classes</B><BR/>
            <xsl:if test="$file !=''">
               <xsl:apply-templates select="document($file)//CLASS"/>
            </xsl:if>
            <B>User Defined Character Classes </B><A href=''>[help]</A><BR/>
            <TEXTAREA NAME='user_char_classes' ROWS='5' COLS='55'></TEXTAREA>
         </td>
      </tr>
   </xsl:template>
   
   <xsl:template match="CLASS">
      <xsl:value-of select="ENGLISH"/> : <xsl:value-of select="VALUE"/><br/>
   </xsl:template>
   
   <xsl:template name="condition_set">
      <xsl:param name="count"/>
      <xsl:variable name="max_conditions"><xsl:value-of select="//defaults/max_conditions"/></xsl:variable>
      <tr>
         <td>
            <xsl:apply-templates select="//defaults/phrases_and_fields">
               <xsl:with-param name="count" select="$count"/>
            </xsl:apply-templates>
         </td>
         <td>
            <xsl:apply-templates select="//defaults/reg_exps">
               <xsl:with-param name="count" select="$count"/>
            </xsl:apply-templates>
         </td>
         <td>
            <xsl:call-template name="string">
               <xsl:with-param name="count" select="$count"/>
            </xsl:call-template>
         </td>
      </tr>
      
      <xsl:if test="$count &lt; ($max_conditions - 1)">
         <tr>
            <td colspan="4" align="center">
               <xsl:apply-templates select="//defaults/connectives">
                  <xsl:with-param name="count" select="$count"/>
               </xsl:apply-templates>
            </td>
         </tr>
      </xsl:if>
   </xsl:template>
   
   
   
   <xsl:template name="produce_condition_set">
      <xsl:param name="count"/>
      <xsl:variable name="max_conditions" select="//defaults/max_conditions"/>
      <xsl:if test="$count &lt; $max_conditions">
         <xsl:call-template name="condition_set">
            <xsl:with-param name="count" select="$count"/>
         </xsl:call-template>
         <xsl:call-template name="produce_condition_set">
            <xsl:with-param name="count" select="$count + 1"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>
   
   <xsl:template match="/">
      <xsl:variable name="project"><xsl:value-of select="//defaults/project"/></xsl:variable>
      <HTML>  
         <HEAD>
            <TITLE>Lexicon Search Interface</TITLE>
            <META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=iso-8859-1'></META>
         </HEAD>
         
         <BODY BGCOLOR='#FFFFFF' TEXT='#000000'>
            <CENTER>    
               <HR ALIGN='center' WIDTH='100%' SIZE='2' COLOR='#800000'/>
               <p></p>
               <FORM METHOD='post'>
                  <xsl:attribute name="action"><xsl:value-of select="concat('../',$php_version,'/query_result.',$php_version)"/></xsl:attribute> 
                  <INPUT TYPE='hidden' NAME='project'>
                     <xsl:attribute name="value"><xsl:value-of select="$project"/></xsl:attribute>
                  </INPUT>
                  <INPUT TYPE='hidden' NAME='stylesheet' value=''/>
                  <p></p>
             
                  <TABLE BORDER='1' WIDTH='600'>
                     <TR>
                        <TH>Field</TH>
                        <TH>Logical operator</TH>
                        <TH>String</TH>
                     </TR>
                     <xsl:call-template name="produce_condition_set">
                        <xsl:with-param name="count" select="0"/>
                     </xsl:call-template>
                     <TR>
                        <TD COLSPAN='4' ALIGN='center'>
                           <INPUT TYPE='submit' VALUE='Submit'/>
                           <INPUT TYPE='reset' VALUE='Reset'/>
                        </TD>
                     </TR>
                     <xsl:apply-templates select="//defaults/xml_char_classes"/>
                  </TABLE>
               </FORM>
               <BR/>
               <BR/>
            </CENTER>
         </BODY>
      </HTML>
      
   </xsl:template>
   
   

</xsl:stylesheet>