<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>

<xsl:template match="/">

<html>
<head>
	<title>Address book</title>

<script language="JavaScript">
function AddRemoveBtn(from_lb, to_lb)
{
	formFrom=document.getElementById(from_lb);
	formTo=document.getElementById(to_lb);

	for(i=formFrom.options.length - 1; i &gt;= 0; i--)
	{
		if(formFrom.options[i].selected==true)
		{
			selectID=formFrom.options[i].id;
			selectValue=formFrom.options[i].value;
			selectText=formFrom.options[i].outerText;

			document.getElementById(selectID).removeNode(true);

			count=formTo.options.length;

			formTo.options[count]=new Option(selectText,selectValue);
			formTo.options[count].setAttribute("id",selectID);
			formTo.options[count].setAttribute("value",selectValue);
		}
	}
}

</script>

</head>

<body style="background:silver;">

<p/><table width="70%" align="center" style="background:silver;color:menutext;font:message-box;">
<tr>
	<th align="center" style="color:activecaptiontext;font:caption;">Name</th>
	<th align="center" style="color:activecaptiontext;font:caption;">Surname</th>
	<th align="center" style="color:activecaptiontext;font:caption;">Balance</th>
	<th align="center" style="color:activecaptiontext;font:caption;">Sex</th>
</tr>

<form action="3.xml" method="post" name="form">
<xsl:for-each select="//root/person">

<tr>
	<td>
		<input>
			<xsl:attribute name="name">check</xsl:attribute>
			<xsl:if test="stock_holder > 0">
				<xsl:attribute name="checked">checked</xsl:attribute>
			</xsl:if>
			<xsl:attribute name="type">checkbox</xsl:attribute>
		</input>
	</td>
	<td>
		<xsl:attribute name="align">center</xsl:attribute>
		<xsl:if test="balance &lt; 0">
			<xsl:attribute name="bgcolor">red</xsl:attribute>
		</xsl:if>
		<xsl:value-of select="name"/>
	</td>
	<td align="center"><xsl:value-of select="surname"/></td>
	<td align="center"><xsl:value-of select="balance"/></td>
	<td align="center">
		<select>
			<xsl:attribute name="name">sex</xsl:attribute>

			<xsl:for-each select="sex">
			<option>
				<xsl:if test="@selected=1">
					<xsl:attribute name="selected">selected</xsl:attribute>
				</xsl:if>
				
				<xsl:attribute name="value"><xsl:value-of select="." />
				</xsl:attribute>
				
				<xsl:value-of select="@query_name"/>	
			</option>
			</xsl:for-each>
		</select>
	</td>
</tr>
<tr>
	<td colspan="4" bgcolor="gray">
		<table width="100%">
			<td width="45%">Available</td>
			<td></td>
			<td width="45%">Selected</td>
		</table>
	</td>
</tr>
<tr>
	<td colspan="4">
		<table width="100%" border="1">
			<td width="45%">
				<select size="6" multiple="yes" style="width:100%" name="avail_phones" 
					id="sel_available">
					<xsl:for-each select="phone">
						<option>
							<xsl:if test="@selected=1">
								<xsl:attribute name="selected">selected</xsl:attribute>
							</xsl:if>
							<xsl:attribute name="value">
								<xsl:value-of select="." />
							</xsl:attribute>
							<xsl:attribute name="id">id_<xsl:value-of select="." /></xsl:attribute>
							<xsl:value-of select="@num"/>	
						</option>
					</xsl:for-each>
				</select>
			</td>
			<td width="10%" align="center" valign="middle">
				<input type="button" name="add_btn" value="-&gt;" 
					onClick="AddRemoveBtn('sel_available', 'sel_selected');"></input>
				<p/>
				<input type="button" name="remove_btn" value="&lt;-" 
					onClick="AddRemoveBtn('sel_selected', 'sel_available');"></input>
			</td>
			<td width="45%">
				<select size="6" multiple="yes" style="width:100%" name="sel_phones" id="sel_selected">
					<xsl:for-each select="curr_phone">
						<option>
							<xsl:if test="@selected=1">
								<xsl:attribute name="selected">selected</xsl:attribute>
							</xsl:if>
							<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
							<xsl:attribute name="id">id_<xsl:value-of select="." /></xsl:attribute>
							<xsl:value-of select="@num"/>	
						</option>
					</xsl:for-each>
				</select>
			</td>
		</table>
	</td>
</tr>

</xsl:for-each>
</form>

</table>

</body>
</html>
</xsl:template>
</xsl:stylesheet>
