<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">
    <xsl:variable name="php_version">php4</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('../user/reg_exps.xml')/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('../user/connectives.xml')"/>
            <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>
        <tr>
            <td colspan="5"><B>Predefined Character Classes</B><BR/>
                <xsl:apply-templates select="document($file)//CLASS"/>
                <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="get_vals">
        <xsl:variable name="p">http://127.0.0.1/user/<xsl:value-of select="phrases_and_fields"/></xsl:variable>
        <xsl:variable name="p_nodes"><xsl:value-of select="document($p)"/></xsl:variable>
     <xsl:apply-templates select="document($p)"/>   
        <xsl:value-of select="reg_exps"/><br/>   
        <xsl:value-of select="connectives"/><br/>
    </xsl:template>

    <xsl:template name="condition_set">
        <xsl:param name="count"/>
        <xsl:variable name="max_conditions"><xsl:value-of select="max_conditions"/></xsl:variable>        
        <tr>
            <td>
                <xsl:apply-templates select="phrases_and_fields">
                    <xsl:with-param name="count" select="$count"/>
                </xsl:apply-templates>
            </td>
            <td>
                <xsl:apply-templates select="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="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="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="defaults">
        <xsl:variable name="project"><xsl:value-of select="project"/></xsl:variable>
        <HTML>  
            <HEAD>
                <TITLE>NLE User Accounts</TITLE>
                <META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=iso-8859-1'></META>
                <script type="text/javascript">
                </script>
            </HEAD>
            
            <BODY BGCOLOR='#FFFFFF' TEXT='#000000'>
                <CENTER>    
                    <HR ALIGN='center' WIDTH='100%' SIZE='2' COLOR='#800000'/>
                    <p></p>
                    <FORM METHOD='post' name="search_form">
                        <xsl:attribute name="action"><xsl:value-of select="concat('../',$php_version,'/query_result.',$php_version)"/></xsl:attribute> 
                        <input type="hidden" name="function" value=""/>
                        <input type="hidden" name="stylesheet" value="../user/share_user_search.xsl"/>
                        <INPUT TYPE='hidden' NAME='project'>
                            <xsl:attribute name="value"><xsl:value-of select="$project"/></xsl:attribute>
                        </INPUT>
                        <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>
                        </TABLE>
                    </FORM>
                    <BR/>
                    <BR/>
                </CENTER>
            </BODY>
        </HTML>
    </xsl:template>        
    
    <xsl:template match="/">
        <xsl:apply-templates select="defaults"/>
    </xsl:template>
    
</xsl:stylesheet>
