 Inside Technique : XML-Based Survey Server : Presenting Survey's with XSL
The survey.xsl file contains blocks of XML representing different rendering schemes.
Through a function in survey.inc (explained later), Individual presentations are extracted and
applied to individual surveys.
Each presentation is separated by a render element. The render element
contains a unique identifier. Below outlines how the render element is
defined in the survey.xsl file:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<render id="banner">
<!-- define banner rendering -->
</render>
<render id="vbanner">
<!-- define vbanner rendering -->
</render>
</xsl:stylesheet>
Each render block is applied to an individual survey.
Below is the definition of the 468x60 banner presentation:
<render id="banner">
<TABLE BORDER="1" WIDTH="468" HEIGHT="60" CELLSPACING="0">
<TR><TD ALIGN="CENTER">
<FORM>
<xsl:value-of select="question"/><BR/>
<INPUT TYPE="HIDDEN" NAME="ID">
<xsl:attribute name="VALUE"><xsl:value-of select="id"/></xsl:attribute>
</INPUT>
<xsl:for-each select="answer">
<INPUT TYPE="SUBMIT" NAME="VOTE">
<xsl:attribute name="value"><xsl:value-of/></xsl:attribute>
</INPUT>
</xsl:for-each>
</FORM>
</TD></TR>
<TR><TD ALIGN="right">
<FONT FACE="verdana,geneva,arial">
<SMALL><SMALL>
Managed by Survey Server from
<A HREF="http://www.siteexperts.com">SiteExperts.com</A>
</SMALL></SMALL>
</FONT>
</TD></TR>
</TABLE>
</render>
The XSL is applied to an individual survey element where the survey
element defines the context for the style sheet. This means that the question element is an immediate
child. This is interesting because it demonstrates that you can apply XSL to any node in the
document, not just the root node (in this case the surveylist).
The XSL for the vertical banner works almost identical to the horizontal banner.
The two differences are we adjusted the table width and now list each response on it's own line:
<render id="vbanner">
<TABLE BORDER="1" WIDTH="125" CELLSPACING="0">
<TR><TD ALIGN="CENTER">
<FORM>
<xsl:value-of select="question"/><BR/>
<INPUT TYPE="HIDDEN" NAME="ID">
<xsl:attribute name="VALUE"><xsl:value-of select="id"/></xsl:attribute>
</INPUT>
<xsl:for-each select="answer">
<P STYLE="margin:5px"><INPUT TYPE="SUBMIT" NAME="VOTE">
</INPUT></P>
</xsl:for-each>
</FORM>
</TD></TR>
<TR><TD><FONT FACE="verdana,geneva,arial">
<SMALL><SMALL>
Survey Server from
<A HREF="http://www.siteexperts.com">SiteExperts.com</A>
</SMALL></SMALL>
</FONT></TD></TR>
</TABLE>
</render>
Both presentations are generate as follows:
- The ID is added to the document in a hidden field:
<INPUT TYPE="HIDDEN" NAME="ID">
<xsl:attribute name="VALUE">
<xsl:value-of select="id"/>
</xsl:attribute>
</INPUT>
- Then the question is displayed:
<xsl:value-of select="question"/>
- Finally we iterate and output each answer in a form field:
<xsl:for-each select="answer">
<P STYLE="margin:5px"><INPUT TYPE="SUBMIT" NAME="VOTE">
</INPUT></P>
</xsl:for-each>
You can rearrange the output simply by modifying the XSL sheet. Since XSL
allows you to freely rearrange elements, your possibilities are endless.
Next we introduce the survey.inc file. This file contains the ASP
functions used to manipulate the surveys.
© 1997-2000 InsideDHTML.com, LLC. All rights reserved.
|