ASP to take dynamic form data and write XML file, using XSL Display _ Application techniques

Source: Internet
Author: User
Tags id3 trim xsl
<title> Untitled Document </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<script language= "JavaScript" >
var currow=null;
var Y=1;

function SelectRow () {
var e=window.event;
var tr1=e.srcelement;
if (Currow)
Currow.bgcolor= "#FFFFFF";
Tr1.bgcolor= "E7e7e7";
CURROW=TR1;
}
function AddRow (SRC) {
alert (SRC);
var newrow = Src.insertrow (src.rows.length-1);
Newrow.attachevent ("onclick", SelectRow);
newrow.height=20;
var i=4;

while (i--) {
var Newcell = Newrow.insertcell ();

switch (i) {
Case 0:newcell.innerhtml= ' <input type= ' button "onclick=" Javascript:delrow (this.parentElement.parentElement) " Value= "Delete this row" > ' + (y++);
Document.all.count.value=y-1;
Break
Case 1:newcell.innerhtml=div2.innerhtml;break;
Case 2:newcell.innerhtml=div3.innerhtml;break;
Case 3:newcell.innerhtml=div4.innerhtml;break;
Default:newcell.innerhtml=div1.innerhtml;break;

}
}
alert (newrow.outerhtml);
}

function Delrow (SRC) {

var tab=src.parentelement;
var i=tab.rows.length;
var j=tab.rows.length;
while (i--) {
if (Src==tab.rows[i]) {
Alert ("This is the line----" + i);
document.all.count.value=j-3;
Tab.deleterow (i);

}

}
}
</script>

<body>
<form name= "Form1" action= "2.asp" method= "POST" Onsubmit=return (CHECKV ()) >
Name: <input type= "text" name= "Jxname" ><br>
Address: <input type= "text" name= "Jxadd" ><br>
Tel: <input type= "text" name= "Jxtel" ><br>
Please enter inventory information <br>
<table id= "TB" width= "100%" border= "1" align= "center" cellpadding= "1" cellspacing= "1" style= "Border-collapse: Collapse "bordercolor=" #111111 ">
<tr>
<th scope= "col" width= "25%" > Name </th>
<th scope= "col" width= "25%" > Specifications </th>
<th scope= "col" width= "25%" > Storage </th>
<th scope= "col" width= "25%" > Operations </th>
</tr>
<tr id= "Blankrow" onclick= "AddRow (this.parentelement)" >
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input type= "hidden" name= "Count" value= "Count" >
<input type= "Submit" id= "Btnsub" name= "Btnsub" value= "submitted" ><br>
</form>
<div id= "Div1" style= "Display:none" ><input "TXT" id= "text" type= "id" name= "style=; Background-color: #FFFFEF "></div>

<div id= "Div2" style= "Display:none" ><input "TXT" id= "text" type= "name=" Id1 "style="; Background-color: #FFFFEF "value=" ></div>
</body>
<div id= "Div3" style= "Display:none" ><select name= "Id2" "style=" width:97%; Background-color: #FFFFEF ">
<option value= "box" > Box </option>
<option value= "Pieces" > Parts </option>

</select></div>
<div id= "Div4" style= "Display:none" ><input "TXT" id= "text" type= "name=" ID3 "style="; Background-color: #FFFFEF "value=" ></div>
<script language= "JavaScript" >
function Checkv ()
{

if (form1.jxname.value.length = 0)
{
Alert ("Please fill in your name and address!") ");
Form1.jxname.focus ();
return false;
}

else if (! ( Check_number (Form1.id1.value))
{
Alert ("Quantity can only be a number")
Form1.id1.focus ();
return false;
}
Else
return (true);
}
function Check_number (Myint)
{

var Checkok = "0123456789";
var checkstr = Myint;
var allvalid = true;
var decpoints = 0;
var allnum = "";
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>

2.2.asp file

<%
'////////////////////take form data
Response.Write ("Total" +request.form ("Count") + "record")
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, ",")

For i = 0 to UBound (Arraya)
Response.Write "<LI>" & Arrayc (i) & "--" &arrayb (i) & "--" &arraya (i)
Next
'///////////////////write to XML file
Dim Objdom
Dim Objroot
Dim ObjChild1
Dim ObjChild2
Dim objChild3
Dim objChild4
Dim OBJPI
Dim Pinode
Set objdom = Server.CreateObject ("Microsoft.XMLDOM")
'/////write style
Set pinode=objdom.createprocessinginstruction ("Xml-stylesheet", "type= ' text/xsl ')

href= ' list.xsl ' ")
Objdom.appendchild Pinode
'/////Create root contacts
Set objroot = objdom.createelement ("Kucunbiao")

Objdom.appendchild Objroot
Set objChild1 = objdom.createelement ("Jxname")
Objchild1.text=jxname

Objroot.appendchild ObjChild1


Set objChild2 = objdom.createelement ("Jxadd")
Objchild2.text=jxadd

Objroot.appendchild ObjChild2
Set Objchild3=objdom.createelement ("Jxtel")
Objchild3.text=jxtel
Objroot.appendchild objChild3
Set Objchild4=objdom.createelement ("Kucun")
Objroot.appendchild ObjChild4
For i = 0 to UBound (Arraya)
Set objfield = objdom.createelement ("field")

' Create a property taborder.
Set Objatttaborder = Objdom.createattribute ("TabOrder")

' Set the property value of the TabOrder
Objatttaborder.text = i

' Appends the attribute value of the taborder to the field element.
Objfield.setattributenode Objatttaborder

' Create a new element, Field_value.
Set objfieldvalue2= objdom.createelement ("name")
Objfieldvalue2.text = ARRAYC (i)
Set Objfieldvalue = objdom.createelement ("Guige")

Objfieldvalue.text = Arrayb (i)
Set Objfieldvalue1=objdom.createelement ("Shuliang")
Objfieldvalue1.text = Arraya (i)
' Appends a field element to the child element of the root element.
Objchild4.appendchild Objfield

' Append Field_value as the content of the child element
Objfield.appendchild Objfieldvalue
Objfield.appendchild objFieldValue1
Objfield.appendchild objFieldValue2
Next
Set OBJPI = objdom.createprocessinginstruction ("xml", "version= ' 1.0")

Objdom.insertbefore Objpi, objdom.childnodes (0)

Objdom.save "F:\xml\" &jxname& ". xml"
'//////////release Resources
Set objdom = Nothing
Set Objroot = Nothing
Set Objfield = Nothing
Set Objfieldvalue = Nothing
Set Objattid = Nothing
Set Objatttaborder = Nothing
Set OBJPI = Nothing
Set pinode=nothing
%>
3. Xml,list.xsl submitted with XSL display

<?xml version= "1.0" encoding= "gb2312"?>
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >

<xsl:template match= "/" >
<body style= "background: #DFEEBB" ><left>

<table border= "1" width= ">"

<xsl:apply-templates select= "Kucunbiao/kucun" >

</xsl:apply-templates>

</table></left>
</body>
</xsl:template>
<xsl:template match= "Kucun" >

<tr>
&LT;TD width= "60%" ><div align= "center" > Name </div></td>
&LT;TD width= "20%" ><div align= "Center" > Specifications </div></td>
&LT;TD width= "20%" ><div align= "center" > Quantity </div></td>
</tr>
<xsl:for-each select= "Field" >
<tr>
<td><xsl:value-of select= "Name"/></td>
<td><xsl:value-of select= "Guige"/></td>
<td><xsl:value-of select= "Shuliang"/></td>
</tr>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.