liuxiaoyi666

  博客园  :: 首页  ::  :: 联系 :: 订阅 订阅  :: 管理

投票的选择的不确定性常常使我们在设计数据库的时候感到无从下手。所以我用的不是数据库保存的投票选项而是用的xml。用xml的设计的好处有很多,其中包括我们可以在其中保留很多的属性,在设计的时候,也可以进行多重选择都是一个很好的办法,用xsl对生成的xml文件进行解析这样的设计模式感觉很爽

我的xml的sample是这样的
<?xml version='1.0' encoding='gb2312' ?>
<?xml-stylesheet type='text/xsl' href='votesample.xsl'?>
<root>
<Questionname><![CDATA[我们的网站好看么?]]></Questionname>
<Choose select='radio' votekindid='1'>
  <ChooseItem value='a'><![CDATA[好看]]></ChooseItem>
  <ChooseItem value='b'><![CDATA[不好看]]></ChooseItem>
  <ChooseItem value='c'><![CDATA[不知道]]></ChooseItem>
  <ChooseItem value='d'><![CDATA[无所谓]]></ChooseItem>
</Choose>
</root>

xsl的sample:
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="GB2312" />
<xsl:template match="/">
  <div>
    <div><xsl:value-of select="//root/Questionname" /></div>
    <table width="95%">
       <xsl:variable name="inputelement" select="//root/Choose/@select" />
       <form action="vote/record.asp" target="observe" method="post">
       <input type="hidden" name="votekindid" value="{//root/Choose/@votekindid}" />
          <xsl:for-each select="//root/Choose/ChooseItem">
      <tr>
         <td align="left"><input type="{$inputelement}" name="choise" value="{@value}"><xsl:if test="position()=1"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if></input><xsl:value-of select="@value" /></td><td align="left" width="80%"><xsl:value-of select="." /></td>
      </tr>  
   </xsl:for-each>
      <tr><td align="center"></td><td align="left"><img src="images/index_left_button3.gif" onclick="javascript:newWin('vote/result.asp?votekindid={//root/Choose/@votekindid}')" style="cursor:hand;" />  <input type="image" src="images/index_left_button4.gif" value="提交" onclick="javascript:newWin()" /></td></tr>
       </form>
    </table>
  </div>
  <script language="javascript">
  <![CDATA[
  function newWin(url){
  if(url==''){
  newWindow=window.open("about:blank","observe","toolbar,resizable,scrollbars,dependent,width=500,height=420,left=150,top=80");
  newWindow.focus();}
  else{
  newWindow=window.open(url,"observe","toolbar,resizable,scrollbars,dependent,width=500,height=420,left=150,top=80");
  newWindow.focus();
  }
  }
  ]]>
  </script>
</xsl:template>
</xsl:stylesheet>

然后用一个vote表,记录一下值
用一个sql语句 select votechoose,count(votechoose) from vote where voteid=值 group by votechoose 进行统计

posted on 2006-05-26 12:42  csdn兔  阅读(2693)  评论(3编辑  收藏  举报