-- 作者:jiaoyu
-- 发布时间:6/8/2007 11:17:00 AM
-- 表单问题
大家好.那个高手帮我看看这个问题. xml文档: <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href ="form1.xsl"?> <survey> <q-section> <query id="1" index="role" controlType="listbox"> <text>哪个是你最爱吃的水果?</text> <value>2</value> </query> <query id="2" index="uses" controlType="checkbox"> <text>你最想做的事情是什么?</text> <value>1</value> <value>3</value> </query> <query id="3" index="software" controlType="checkbox"> <text>你最喜欢的动物是什么?</text> </query> </q-section> <a-section> <list index="role"> <option id="1" name="苹果" /> <option id="2" name="香蕉" /> <option id="3" name="桔子" /> <option id="4" name="樱桃" /> <option id="5" name="核桃" /> <option id="6" name="其它" /> </list> <list index="uses"> <option id="1" name="环游世界" /> <option id="2" name="登山" /> <option id="3" name="跳水" /> <option id="4" name="其它" /> </list> <list index="software"> <option id="1" name="小狗" /> <option id="2" name="小猫" /> <option id="3" name="兔子" /> <option id="4" name="其它" /> </list> </a-section> </survey> xslt样式表: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:key name="lists" match="//list" use="attribute::index" /> <xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" /> <!-- xsl:output 是最高级元素,所以它具有全局作用域--> <!--xml分析程序被要求来支持2种编码方式,UTF-8,UTF-16,它们都是Unicode格式--> <!--indent是否缩进,值为YES时,就是要缩进--> <!--media-type指定结果树的媒体类型,如果输出方式是HTML,则要指出HTML的格式,如果是XML,则设version="1.0"--> <xsl:template match="/"> <html> <head> <title>Form Controls</title> </head> <body> <form> <xsl:apply-templates select="survey/q-section/query" /> </form> </body> </html> </xsl:template> <xsl:template match="query"> <p> <xsl:value-of select="child::text/text()" /> <!--选择当前节点text的子元素的text文本--> <xsl:apply-templates select="key('lists',@index)"> <xsl:with-param name="selected-values" select="value" /> <xsl:with-param name="controlType" select="@controlType" /> <xsl:with-param name="question_id" select="concat('question_',@id)" /> <!--concat用于返回所有变元的拼接,将把字符串名question_添加到id属性求值所得字符串的起始处--> </xsl:apply-templates> </p> </xsl:template> <xsl:template match="list"> <xsl:param name="selected-values" /> <xsl:param name="controlType">listbox</xsl:param> <xsl:param name="question_id" /> <xsl:if test="$controlType='checkbox'"> <xsl:for-each select="option"> <br /> <input type="checkbox"> <!-- 给选择题前面加上小框--> <xsl:attribute name="name"> <xsl:value-of select="$question_id" /> </xsl:attribute> <xsl:if test="$selected-values/text() = attribute::id"> <xsl:attribute name="check" /> </xsl:if> </input> <xsl:value-of select="@name" /> </xsl:for-each> </xsl:if> <xsl:if test="$controlType='listbox'"> <p> <select> <xsl:attribute name="name"> <xsl:value-of select="$question_id" /> </xsl:attribute> <xsl:for-each select="option"> <option> <xsl:if test="$selected-values/text() = attribute::id"> <xsl:attribute name="selected" /> </xsl:if> <xsl:attribute name="value"> <xsl:value-of select="@id" /> </xsl:attribute> <xsl:value-of select="@name" /> </option> </xsl:for-each> </select> </p> </xsl:if> </xsl:template> </xsl:stylesheet> 这两文件是怎么联系起来的,帮我解释解释了.都快急疯了!!!!!!!!!!!
|