asp取动态表单中数据并写入xml文件,用xsl显示

2018-09-06 13:05

阅读:398

  <html>
<head>
<title>无标题文档</title>
<metahttp-equiv=Content-Typecontent=text/html;charset=gb2312>
<scriptlanguage=javascript>
varcurRow=null;
vary=1;

functionselectRow(){
vare=window.event;
vartr1=e.srcElement;
if(curRow)
curRow.bgColor=#FFFFFF;
tr1.bgColor=e7e7e7;
curRow=tr1;
}
functionaddRow(src){
//alert(src);
newrow.attachEvent(onclick,selectRow);
newrow.height=20;
vari=4;

while(i--){
varnewcell=newrow.insertCell();

switch(i){
case0:newcell.innerHTML=<inputtype=buttononClick=javascript:delRow(this.parentElement.parentElement)value=删除此行>+(y++);
break;
case1:newcell.innerHTML=div2.innerHTML;break;
case2:newcell.innerHTML=div3.innerHTML;break;
case3:newcell.innerHTML=div4.innerHTML;break;
default:newcell.innerHTML=div1.innerHTML;break;

}
}
//alert(newrow.outerHTML);
}

functiondelRow(src){

vartab=src.parentElement;
vari=tab.rows.length;
varj=tab.rows.length;
while(i--){
if(src==tab.rows[i]){
//alert(就是这行----+i);
document.all.count.value=j-3;
tab.deleteRow(i);

}

}
}
</script>
</head>

<body>
<formname=form1action=2.aspmethod=postonsubmit=return(checkv())>
<h3>请输入经销商的通讯信息:</h3>
姓名:<inputtype=textname=jxname><br>
地址:<inputtype=textname=jxadd><br>
电话:<inputtype=textname=jxtel><br>
请输入库存信息<br>
<tableid=tbwidth=100%border=1align=centercellpadding=1cellspacing=1style=border-collapse:collapsebordercolor=#111111>
<tr>
<thscope=colwidth=25%>品名</th>
<thscope=colwidth=25%>规格</th>
<thscope=colwidth=25%>库存量</th>
<thscope=colwidth=25%>操作</th>
</tr>
<trid=blankRowonClick=addRow(this.parentElement)>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<inputtype=hiddenname=countvalue=count>
<inputtype=submitid=btnSubname=btnSubvalue=提交><br>
</form>
<divid=div1style=display:none><inputid=txttype=textname=idstyle=width:97%;background-color:#FFFFEF></div>

<divid=div2style=display:none><inputid=txttype=textname=id1style=width:97%;background-color:#FFFFEFvalue=11></div>
</body>
<divid=div3style=display:none><selectname=id2style=width:97%;background-color:#FFFFEF>
<optionvalue=箱>箱</option>
<optionvalue=件>件</option>

</select></div>
<divid=div4style=display:none><inputid=txttype=textname=id3style=width:97%;background-color:#FFFFEFvalue=33></div>
<scriptlanguage=javascript>
functioncheckv()
{

if(form1.jxname.value.length==0)
{
alert(请填写姓名和地址!);
form1.jxname.focus();
returnfalse;
}

elseif(!(check_number(form1.id1.value)))
{
alert(数量只能为数字)
form1.id1.focus();
returnfalse;
}
else
return(true);
}
functioncheck_number(myint)
{

varcheckOK=0123456789;
varcheckStr=myint;
varallValid=true;
vardecPoints=0;
varallNum=;
for(i=0;i<checkStr.length;i++)
{
ch=checkStr.charAt(i);
for(j=0;j<checkOK.length;j++)
if(ch==checkOK.charAt(j))
break;
if(j==checkOK.length)
{
allValid=false;
break;
}
allNum+=ch;
}
if(!allValid)
{
return(false);
}
return(true);
}

</script>
</html>

2.2.asp文件

<%
////////////////////取表单数据
response.write(共+request.form(count)+记录)
i=request.form(count)
jxname=request.form(jxname)
jxadd=request.form(jxadd)
jxtel=request.form(jxtel)
response.write(request.form(jxname))
response.write(<br>)
response.write(request.form(jxadd))
response.write(<br>)
response.write(request.form(jxtel))
response.write(<br>)
str1=trim(request.form(id1))
str2=trim(request.form(id2))
str3=trim(request.form(id3))
arrayA=Split(str1,,)
arrayb=Split(str2,,)
arrayc=Split(str3,,)

Fori=0toUBound(arrayA)
Response.Write<LI>&arrayc(i)&--&arrayb(i)&--&arrayA(i)
Next
///////////////////写入xml文件
DimobjDom
DimobjRoot
DimobjChild1
DimobjChild2
DimobjChild3
dimobjChild4
DimobjPI
DimPINode
SetobjDom=Server.CreateObject(Microsoft.XMLDOM)
/////写入样式
SetPINode=objDom.CreateProcessingInstruction(xml-stylesheet,type=text/xsl

href=list.xsl)
objDom.appendchildPINode
/////创建根接点
SetobjRoot=objDom.createElement(kucunbiao)

objDom.appendChildobjRoot
SetobjChild1=objDom.createElement(jxname)
objChild1.text=jxname

objRoot.appendChildobjChild1


SetobjChild2=objDom.createElement(jxadd)
objchild2.text=jxadd

objRoot.appendChildobjChild2
setobjChild3=objDom.createElement(jxtel)
objChild3.text=jxtel
objRoot.appendChildobjChild3
setobjChild4=objDom.createElement(kucun)
objRoot.appendChildobjChild4
Fori=0toUBound(arrayA)
SetobjField=objDom.createElement(field)

创建属性taborder。
SetobjattTabOrder=objDom.createAttribute(taborder)

设定taborder的属性值
objattTabOrder.Text=i

把taborder的属性值追加到field元素中去。
objField.setAttributeNodeobjattTabOrder

创建一个新的元素field_value.
SetobjFieldValue2=objDom.createElement(name)
objFieldValue2.Text=arrayc(i)
SetobjFieldValue=objDom.createElement(guige)

objFieldValue.Text=arrayb(i)
setobjFieldValue1=objDom.createElement(shuliang)
objFieldValue1.Text=arrayA(i)
追加field元素为根元素的子元素。
objChild4.appendChildobjField

追加field_value做为子元素的内容
objField.appendChildobjFieldValue
objField.appendChildobjFieldValue1
objField.appendChildobjFieldValue2
next
SetobjPI=objDom.createProcessingInstruction(xml,version=1.0)

objDom.insertBeforeobjPI,objDom.childNodes(0)

objDom.Savef:\xml\&jxname&.xml
//////////释放资源
SetobjDom=Nothing
SetobjRoot=Nothing
SetobjField=Nothing
SetobjFieldValue=Nothing
SetobjattID=Nothing
SetobjattTabOrder=Nothing
SetobjPI=Nothing
SetPINode=Nothing
%>
3.用xsl显示提交的xml,list.xsl

<?xmlversion=1.0encoding=gb2312?>
<xsl:stylesheetversion=1.0xmlns:xsl=

<xsl:templatematch=/>
<html>
<bodystyle=background:#DFEEBB><left>
<h3>姓名:<xsl:value-ofselect=kucunbiao/jxname/></h3>
<h3>地址:<xsl:value-ofselect=kucunbiao/jxadd/></h3>

<h3>电话:<xsl:value-ofselect=kucunbiao/jxtel/></h3>
<tableborder=1width=600>

<xsl:apply-templatesselect=kucunbiao/kucun>

</xsl:apply-templates>

</table></left>
</body>
</html>
</xsl:template>
<xsl:templatematch=kucun>

<tr>
<tdwidth=60%><divalign=center>名称</div></td>
<tdwidth=20%><divalign=center>规格</div></td>
<tdwidth=20%><divalign=center>数量</div></td>
</tr>
<xsl:for-eachselect=field>
<tr>
<td><xsl:value-ofselect=name/></td>
<td><xsl:value-ofselect=guige/></td>
<td><xsl:value-ofselect=shuliang/></td>
</tr>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet>


评论


亲,登录后才可以留言!