 Inside Technique : XML-Based Survey Server : The Survey Manager
The survey manager page allows you to add, edit, and remove surveys. The survey
manager screen reuses some of the techniques presented earlier to display
the survey list. In addition, we generate the editor for individual surveys
by manipulating the XML Document Object Model rather than creating an XSL sheet. We
chose this approach to demonstrate an alternative way to manipulate and generate HTML.
The Survey Manager starts by listing all the available surveys. The list
is generated using the same techniques presented earlier. To get a list of surveys
you call the getSurveyList() function. This function transforms the entire
survey list using the stylesheet identified as "listing":
function getSurveyList()
Dim source, style, outputNode, result
set source = application("survey")
set style = application("style")
set outputNode = style.selectSingleNode("xsl:stylesheet/render[@id=""listing""]")
if not outputNode is nothing then
result = source.transformNode(outputNode)
else
result = "ERROR - Bad Render ID"
end if
getSurveyList = result
end function
The "listing" style sheet is a fairly simple XSL transformation. The style sheet
and its output are shown below:
<render id="listing">
<H1>Survey Editor</H1>
<UL>
<xsl:for-each select="surveylist/survey">
<LI>
<A>
<xsl:attribute name="HREF">?id=<xsl:value-of select="id"/></xsl:attribute>
<xsl:value-of select="question"/> (<xsl:value-of select="@voters"/> votes)
</A>
<UL>
<xsl:for-each select="answer">
<LI><xsl:value-of/>   (<xsl:value-of select="@votes"/> votes) </LI>
</xsl:for-each>
</UL>
</LI>
</xsl:for-each>
</UL>
<FORM>
<INPUT TYPE="SUBMIT" NAME="New" VALUE="Add New..."/>
</FORM>
</render>
When an individual suvey is selected, we create a simple editor. The editor
for the survey is generated using the XML Document Object Model.
function getPoll(sID)
Dim source, findNode
set source = application("survey")
set findNode = source.selectSingleNode("surveylist/survey[id[. = """ & sID & """]]")
set getPoll = findNode
end function
function buildEdit(sID)
Dim source, findNode, question,answer, i, sQuestion, iAnswer
response.write("<H1><A HREF=""?"">Survey Editor</A> :")
if sID<>"" then
response.write(" Edit Survey</H1>")
set findNode = getSurveyFromID(sID)
if findNode is nothing then
response.write("<B>Survey (ID " & sID & ") not found - Adding new Survey!</B><BR>")
sID=""
sQuestion=""
iAnswer=0
else
set question = findNode.selectSingleNode("question")
sQuestion = question.text
set answer = findNode.selectNodes("answer")
iAnswer = answer.length
response.write("<B>Survey ID: " & sID & "</B>")
end if
else
response.write(" New Survey</H1>")
sQuestion = ""
iAnswer = 0
end if
response.write("<FORM METHOD=""POST"" ACTION=""?"">Question: <INPUT NAME=""question"" SIZE=""30"" TYPE=""text"" VALUE=""" + sQuestion + """><P>")
response.write("<TABLE><TR><TH></TH><TH>Answer</TH><TH>Votes</TH></TR>")
for i=0 to numanswers-1
response.write("<TR><TD ALIGN=""RIGHT"">" & (i+1) & ".</TD><TD><INPUT NAME=""answer" & i & """ SIZE=""20"" TYPE=""text"" VALUE=""")
if (i<iAnswer) then
response.write(answer(i).text)
end if
response.write(""">")
response.write("</TD><TD ALIGN=CENTER><INPUT STYLE=""text-align:right"" NAME=""votes" & i & """ SIZE=""3"" TYPE=""text"" VALUE=""")
if (i<iAnswer) then
response.write(answer(i).getAttribute("votes"))
end if
response.write("""></TD></TR>")
next
response.write("<TR><TD COLSPAN=3 ALIGN=CENTER><INPUT TYPE=""HIDDEN"" NAME=""ID"" VALUE=""" & sID & """>")
response.write("<P><INPUT TYPE=""SUBMIT"" NAME=""Save"" VALUE=""Save""> ")
if sID<>"" then
response.write("<INPUT TYPE=""SUBMIT"" NAME=""Delete"" ONCLICK=""return confirm('Are you sure you want to delete this Survey?')"" VALUE=""Delete"">")
end if
response.write("</TD></TR></TABLE></FORM>")
end function
Survey Editor : Edit SurveySurvey ID: 1
|
We chose to create the survey editor using the document object model instead of XSL.
We recommend you compare the above script to the XSL sheets presented earlier. The XSL
sheet would be much easier to manipulate and change if you want to update the layout.
Also, since the XSL sheet requires proper XML, it is much more difficult to generate
bad HTML. Using a script like the one above makes it very easy to generate badly formatted
HTML.
Next we conclude with the scripts used to delete and save surveys.
© 1997-2000 InsideDHTML.com, LLC. All rights reserved.
|