新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论DOM, SAX, XPath等。
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 DOM/SAX/XPath 』 → [求助]如何在XSL里多次动态查询 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 2888 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [求助]如何在XSL里多次动态查询 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     tianly 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:1
      积分:56
      门派:XML.ORG.CN
      注册:2005/5/25

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给tianly发送一个短消息 把tianly加入好友 查看tianly的个人资料 搜索tianly在『 DOM/SAX/XPath 』的所有贴子 引用回复这个贴子 回复这个贴子 查看tianly的博客楼主
    发贴心情 [求助]如何在XSL里多次动态查询

    我是第一次接触XML,要做一个从题库里动态选题的网页,用的是XML+XSL。我也看到网上有个动态查询的例子,于是我照着也做了一个,成功了。可是没想到到我多次调用它时,就怎么也选不上了,而且我发现单词选的节点跟多次选的都不一样,请问高手,如何才能完成多次查询。
    我的XML如下:(exam2.xml)
    <?xml version="1.0" encoding="GB2312"?>
    <?xml-stylesheet type='text/xsl' href='exam2.xsl'?>
     <!-- File name: exam2.xml -->

    <examcontent>
     <question type="0" seq="1">
      <text>软件工程是从</text>
      <editbox id="1" mark="1">管理</editbox>
      <text>和</text>
      <editbox id="2" mark="1">技术</editbox>
      <text>两个方面研究如何更好的开发和维护计算机软件的一门学科。</text>
     </question>
     <question type="0" seq="2">
      <text>软件开发技术包括软件开发方法学、</text>
      <editbox id="3" mark="1">软件工具</editbox>
      <text>和</text>
      <editbox id="4" mark="1">软件开发环境</editbox>
      <text>。</text>
     </question>
     <question type="0" seq="3">
      <text>优秀的设计通常是从现有的物理系统出发,导出现有系统的</text>
      <editbox id="5" mark="1">高层逻辑模型</editbox>
      <text>。</text>
      </question>
     <question type="0" seq="4">
      <text>结构化分析方法使用数据流图DFD和</text>
      <editbox id="6" mark="1">数据字典DD</editbox>
      <text>来描述。</text>
     </question>
     <question type="0" seq="5">
      <text>在分层的数据流图中,称上层图为下层图的</text>
      <editbox id="7" mark="1">父图</editbox>
      <text>,下层图为上层图的</text>
      <editbox id="8" mark="1">子图</editbox>
      <text>。</text>
     </question>
     <question type="0" seq="6">
      <text>模块间的耦合程度强烈影响系统的可理解性、</text>
      <editbox id="9" mark="1">可测试性</editbox>
      <text>、可靠性和</text>
      <editbox id="10" mark="1">可维护性</editbox>
      <text>。</text>
     </question>
     <question type="0" seq="7">
      <text>Jackson图既可用表达程序结构,也可用表达</text>
      <editbox id="11" mark="1">数据结构</editbox>
      <text>。</text>
     </question>
     <question type="0" seq="8">
      <text>程序的控制结构一般采用</text>
      <editbox id="12" mark="1">顺序</editbox>
      <text>、</text>
      <editbox id="13" mark="1">选择</editbox>
      <text>、</text>
      <editbox id="14" mark="1">循环</editbox>
      <text>三种构成,这样可确保结构比较简单。</text>
     </question>
     <question type="0" seq="9">
      <text>面向对象的软件工程方法是面向对象方法在软件:工程领域的全面运用。它包括面向对象的分析、</text>
      <editbox id="15" mark="1">面向对象的设计</editbox>
      <text>、</text>
      <editbox id="16" mark="1">面向对象的编程</editbox>
      <text>、面向对象的测试和</text>
      <editbox id="17" mark="1">面向对象的软件维护</editbox>
      <text>等主要内容。</text>
     </question>
     <question type="0" seq="10">
      <text>标准建模语言UML的重要内容可以通过</text>
      <editbox id="18" mark="1">用例图</editbox>
      <text>、</text>
      <editbox id="19" mark="1">静态图</editbox>
      <text>、行为图、</text>
      <editbox id="20" mark="1">交互图</editbox>
      <text>和实现图等图来定义。</text>
     </question>
     <question type="0" seq="11">
      <text>程序的效率是指</text>
      <editbox id="21" mark="1">程序的执行速度</editbox>
      <text>和</text>
      <editbox id="22" mark="1">程序占用的存储空间</editbox>
      <text>。</text>
     </question>
     <question type="0" seq="12">
      <text>实现容错的主要手段是冗余和</text>
      <editbox id="23" mark="1">防错程序设计</editbox>
      <text>。</text>
     </question>
     <question type="0" seq="13">
      <text>为了保证软件的质量,在软件开发过程中经常采取</text>
      <editbox id="24" mark="1">审查</editbox>
      <text>、复查和管理复查</text>
      <editbox id="25" mark="1">测试</editbox>
      <text>等措施。</text>
     </question>
     <question type="1" seq="1001">
      <text>下列关于瀑布模型的描述正确的是(    )。</text>
      <schoice id="1" value="A">利用瀑布模型,如果发现问题修改的代价很低</schoice>
      <schoice id="1" value="B">瀑布模型的核心是按照软件开发的时间顺序将问题简化</schoice>
      <schoice id="1" value="C">瀑布模型具有良好的灵活性</schoice>
      <schoice id="1" value="D">瀑布模型采用结构化的分析与设计方法,将逻辑实现与物理实现分开</schoice>
      <answer id="1" mark="2">D</answer>
     </question>
     <question type="1" seq="1002">
      <text>总体设计的目的是确定整个系统的(    )。</text>
      <schoice id="2" value="A">规模</schoice>
      <schoice id="2" value="B">功能及模块结构</schoice>
      <schoice id="2" value="C">费用</schoice>
      <schoice id="2" value="D">测试方案</schoice>
      <answer id="2" mark="2">B</answer>
     </question>
     <question type="1" seq="1003">
      <text>下列哪个图不是N—S图的构件(    )。</text>
      <schoice id="3" value="A" />
      <img>cloudy.gif</img>
      <schoice id="3" value="B" />
      <img>rain.gif</img>
      <schoice id="3" value="C" />
      <img>snow.gif</img>
      <schoice id="3" value="D" />
      <img>sunny.gif</img>
      <answer id="3" mark="2">C</answer>
     </question>
     <question type="1" seq="1004">
      <text>下列各方法中(    )不是软件测试方法。</text>
      <schoice id="4" value="A">白盒法</schoice>
      <schoice id="4" value="B">黑盒法</schoice>
      <schoice id="4" value="C">动态测试</schoice>
      <schoice id="4" value="D">盒法</schoice>
      <answer id="4" mark="2">D</answer>
     </question>
     <question type="1" seq="1005">
      <text>如果某种内聚要求一个模块中包含的任务必须在同一段时间内执行,则这种内聚为(    )。</text>
      <schoice id="5" value="A">时间内聚</schoice>
      <schoice id="5" value="B">逻辑内聚</schoice>
      <schoice id="5" value="C">通信内聚</schoice>
      <schoice id="5" value="D">信息内聚</schoice>
      <answer id="5" mark="2">A</answer>
     </question>
     <question type="2" seq="2001">
      <text mark="2">(    )可以作为模块。</text>
      <mchoice id="1" value="A" answer="1">过程</mchoice>
      <mchoice id="1" value="B" answer="1">子程序</mchoice>
      <mchoice id="1" value="C" answer="1">函数</mchoice>
      <mchoice id="1" value="D" answer="1">宏</mchoice>
     </question>
     <question type="2" seq="2002">
      <text mark="2">关于软件测试,正确的描述包括(    )。</text>
      <mchoice id="2" value="A" answer="1">测试前要认定被测试的软件有错</mchoice>
      <mchoice id="2" value="B" answer="1">要尽量避免测试自己编写的程序</mchoice>
      <mchoice id="2" value="C" answer="1">测试要兼顾合理输人与不合理输人数据</mchoice>
      <mchoice id="2" value="D" answer="1">测试是相对的,不能穷尽所有的测试,要据人力物力安排测试,选择好测试用例与 测试方法。</mchoice>
     </question>
     <question type="2" seq="2003">
      <text mark="2">下列(    )属于主动式防错程序设计。</text>
      <mchoice id="3" value="A" answer="1">栈的深度是否合适</mchoice>
      <mchoice id="3" value="B" answer="0">内存检查</mchoice>
      <mchoice id="3" value="C" answer="1">数组界限是否正确</mchoice>
      <mchoice id="3" value="D" answer="0">时间检查</mchoice>
     </question>
     <question type="2" seq="2004">
      <text mark="2">下列(    )属于判定覆盖。</text>
      <mchoice id="4" value="A" answer="0">每个语句都被执行</mchoice>
      <mchoice id="4" value="B" answer="1">选择的测试数据必须足够多</mchoice>
      <mchoice id="4" value="C" answer="0">每个判定的每种可能的结果都被执行</mchoice>
      <mchoice id="4" value="D" answer="1">判定表达式中的每个条件都取到可能的值</mchoice>
     </question>
     <question type="2" seq="2005">
      <text mark="2">软件管理工作涉及到的直接对象包括(    )。</text>
      <mchoice id="5" value="A" answer="1">软件开发人员</mchoice>
      <mchoice id="5" value="B" answer="0">硬件设备</mchoice>
      <mchoice id="5" value="C" answer="1">项目经费</mchoice>
      <mchoice id="5" value="D" answer="1">软件项目</mchoice>
     </question>
     <question type="3" seq="3001">
      <text>对于软件项目,投资回收期越长,越快获得利润。</text>
      <yesno id="1" mark="2">0</yesno>
     </question>
     <question type="3" seq="3002">
      <text>一个实时系统必须在严格的时间范围内响应。如果响应时间被过分延迟,将带来灾难性的后果。</text>
      <yesno id="2" mark="2">1</yesno>
     </question>
     <question type="3" seq="3003">
      <text>模块接口简单是软件发生错误的一个主要原因。</text>
      <yesno id="3" mark="2">0</yesno>
     </question>
     <question type="3" seq="3004">
      <text>软件的质量保证工作一般在编码工作结束后才开始。</text>
      <yesno id="4" mark="2">0</yesno>
     </question>
     <question type="3" seq="3005">
      <text>现在人们普遍认为优秀的程序除了功能正确,性能优良之外,还应该容易看懂、容易使用、容易修改和扩充。</text>
      <yesno id="5" mark="2">1</yesno>
     </question>
     <question type="4" seq="4001">
      <text>软件产品具有哪些特性?</text>
      <requirement>本题10分</requirement>
      <qtextarea id="1" mark="10">①软件是一种逻辑实体,而不是具体的物理实体,因而它具有抽象性。②软件是通过人们的智力活动,把知识与技术转化成信息的一种产品,是在研制、开发中被创造出来的。③在软件的运行和使用期间,没有硬件那样的机械磨损、老化问题。④软件的开发和运行经常受到计算机系统的限制,对计算机系统有着不同程度的依赖性。⑤软件的开发至今尚未完全摆脱手工的开发方式。⑥软件的开发费用越来越高,成本相当昂贵。</qtextarea>
     </question>
     <question type="4" seq="4002">
      <text>什么是耦合?什么是内聚?</text>
      <requirement>本题4分</requirement>
      <qtextarea id="2" mark="4">内聚标志一个模块内各个元素彼此结合的紧密程度,它是信息隐蔽和局部化概念的自然扩展。</qtextarea>
     </question>
     <question type="4" seq="4003">
      <text>为什么软件测试不应该由程序的编写人员来做?</text>
      <requirement>本题7分</requirement>
      <qtextarea id="3" mark="7">正确认识测试的目标是十分重要的,测试目标决定了测试力案的设计。如果为了表明程序是正确的而进行测试,就会设计一些不易暴露错误的测试方案;相反,如果测试是为了发现程序中的错误,就会力求设计出最能暴露错误的测试方案。由于测试的目标是暴露程序中的错误,从心理学角度看,由程序的编写者自己进行测试是不恰当的。</qtextarea>
     </question>
     <question type="4" seq="4004">
      <text>什么是编码风格?为什么要强调编码风格?</text>
      <requirement>本题7分</requirement>
      <qtextarea id="4" mark="7">编码的目标从强调效率转变为强调清晰。良好的编码风格能在一定程度上弥补语言存在的缺陷,而如果不注意风格就很难写出高质量的程序。尤其当多个程序员合作编写一个很大的程序时,需要强凋良好而一致的编码风格,以便相互通讯,减少因不协调而引起的问题。总之,良好的编码风格有助于编写出可靠而又容易维护的程序,编码的风格在很大程度上决定着程序的质量。</qtextarea>
     </question>
     <question type="5" seq="5001">
      <text>根据下列N—S图,写出其对应的伪码。</text>
      <requirement>本题10分</requirement>
      <img>cloudy.gif</img>
      <atextarea id="5" mark="10">  Start
      a
      b
      Do Until x6
         If xl then
            f
            If x4 then
             Do Until x5
              i
             End Until
          Else
             g
             h
          End if
        Else
           Select Case x2
              Case 1:
               Do While x3
                 c
                End While
           Case 2:
            d
           Case 3:
            e
         End Select
      End if
    End. Until
    Stop</atextarea>
     </question>
     <question type="5" seq="5002">
      <text id="6">根据下列描述,画出教材征订系统的第一层数据流图。学生入学后到教材科订书,教材科根据教材库存情况分析是否需要买书,如需购买,则向书店购买。各种资金往来通过学校的会计科办理。</text>
      <requirement>本题7分</requirement>
      <atextarea id="6" mark="7">
       <img>cloudy.gif</img>
      </atextarea>
     </question>
    </examcontent>
    xsl文件:(exam2.xsl)
    <?xml version="1.0" encoding="gb2312"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" version="1.0">

    <xsl:template match="/">
    <script>
    function getRange(x)
    {
     var objExamContent = new ActiveXObject("Microsoft.XMLDOM");
     objExamContent.load("exam2.xml");
     var objExam = objExamContent.selectNodes("/examcontent/question[@type=" + x + "]");
     var value = objExam.length;
     return value;
    }
    function searchtext(x, value, nbr)
    {
     var myValue = Math.floor((value * Math.random()) + 1);
     var id = myValue+x*1000;
     
    stylesheet=document.XSLDocument;
    source=document.XMLDocument;
    sortField=document.XSLDocument.selectNodes("//@select");
    [color=#FF0000]alert(sortField[1].text);[/color]
    sortField[1].value="question[@seq='"+id+"']";
    [color=#FF0000]alert(sortField[1].text);[/color]

     if (nbr == 0)
      type0.innerHTML=source.documentElement.transformNode(stylesheet);
     if (nbr == 1)
      type1.innerHTML=source.documentElement.transformNode(stylesheet);
    }
    </script>
    <HTML>
    <HEAD><TITLE>试卷</TITLE></HEAD>
     <BODY background="admin.gif" bgproperties="fixed">
    <div align="center">
     <H1>试卷代号:2073 </H1>
     中央广播电视大学2003—2004学年度第二学期“开放专科”期末考试<br/>
     计算机专业  软件工程  试题<br/>
    </div>
    <div align="right">
      <script language="javascript">document.write(document.lastModified)</script><br/>
    </div>
    <form action="url" method="POST">

    <div align="left">
     一.填空题 (在横线上填写正确的答案,每空1分)<br/>
     <script>var value=getRange(0);</script>
     1.
     <div id="type1" name="type1">
      <xsl:apply-templates select="examcontent" />
     </div>
     <script>searchtext(0, value, 1);</script>
     2.
     二.单项选择题 (将一个正确的答案代码填入括号中,每小题2分)<br/>
     <script>var value=getRange(1);</script>
     1.
     <div id="type0" name="type0">
      <xsl:apply-templates select="examcontent" />
     </div>
     <script>searchtext(1, value, 0);</script>
     2.
    </div>
    <table align="center" width="30%" cellspacing="1" cellpadding="2" border="0">
     <tr>
      <td width="50%"><div align="center"><input type="Submit" value="Submit" name="Submit" /></div></td>
      <td width="50%"><div align="center"><input type="Reset" value="Reset" name="Reset" /></div></td>
     </tr>
    </table>
    </form>
    </BODY>
    </HTML>
    </xsl:template>

    <xsl:template match="examcontent">
     <xsl:for-each select="question">
     <xsl:value-of select="@id" />
      <xsl:for-each select="*">
          <xsl:choose>
          <xsl:when test="context()[nodeName()$eq$'text']">
            <xsl:apply-templates select="." />
          </xsl:when>
          <xsl:when test="context()[nodeName()$eq$'requirement']">
            <xsl:apply-templates select="." />
           </xsl:when>
          <xsl:when test="context()[nodeName()$eq$'img']">
           <xsl:apply-templates select="." />
          </xsl:when>
          <xsl:when test="context()[nodeName()$eq$'editbox']">
           <xsl:apply-templates select="." />
           </xsl:when>
          <xsl:when test="context()[nodeName()$eq$'schoice']">
           <xsl:apply-templates select="." />
          </xsl:when>
          <xsl:when test="context()[nodeName()$eq$'mchoice']">
           <xsl:apply-templates select="." />
           </xsl:when>
          <xsl:when test="context()[nodeName()$eq$'yesno']">
           <xsl:apply-templates select="." />
          </xsl:when>
          <xsl:when test="context()[nodeName()$eq$'qtextarea']">
           <xsl:apply-templates select="." />
           </xsl:when>
          <xsl:when test="context()[nodeName()$eq$'atextarea']">
           <xsl:apply-templates select="." />
          </xsl:when>
         </xsl:choose>
        </xsl:for-each>
     </xsl:for-each>
    </xsl:template>

    <xsl:template match="requirement">
     (<xsl:value-of select="." />)
    </xsl:template>

    <xsl:template match="text">
     <xsl:value-of select="." />
    </xsl:template>

    <xsl:template match="img">
     <br/>
     <xsl:element name="img">
       <xsl:attribute name="src"><xsl:value-of select="."/></xsl:attribute>
     </xsl:element>
    </xsl:template>

    <xsl:template match="editbox">
     <xsl:element name="input">
       <xsl:attribute name="type">text</xsl:attribute>
       <xsl:attribute name="name">editbox<xsl:value-of select="@id"/></xsl:attribute>
     </xsl:element>
    </xsl:template>

    <xsl:template match="schoice">
     <br/>
     <xsl:element name="input">
       <xsl:attribute name="type">radio</xsl:attribute>
       <xsl:attribute name="name">schoice<xsl:value-of select="@id"/></xsl:attribute>
       <xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute>
     </xsl:element>
     <xsl:value-of select="@value" />.
     <xsl:value-of select="text()" />
    </xsl:template>

    <xsl:template match="mchoice">
     <br/>
     <xsl:element name="input">
       <xsl:attribute name="type">checkbox</xsl:attribute>
       <xsl:attribute name="name">mchoice<xsl:value-of select="@id"/></xsl:attribute>
       <xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute>
     </xsl:element>
     <xsl:value-of select="@value" />.<xsl:value-of select="." />
    </xsl:template>

    <xsl:template match="yesno">
     <xsl:element name="input">
       <xsl:attribute name="type">checkbox</xsl:attribute>
       <xsl:attribute name="name">yesno<xsl:value-of select="@id"/></xsl:attribute>
     </xsl:element>
     <br/>
    </xsl:template>

    <xsl:template match="qtextarea|atextarea">
     <br/>
      <xsl:element name="textarea">
       <xsl:attribute name="name"><xsl:node-name /><xsl:value-of select="@id"/></xsl:attribute>
       <xsl:attribute name="row">16</xsl:attribute>
       <xsl:attribute name="cols">64</xsl:attribute>
     </xsl:element>
     <xsl:element name='/textarea' />
    </xsl:template>

    </xsl:stylesheet>
    大家可以看到,我调了两次searchtext,同时我在searchtext里用alert显示sortField[1].text。奇怪的是,当我只调用一次searchtext时,我第一次弹出来的值是question,第二次是question[@seq='随机值'],显示结果也是选中的那道题。可是当我需要调用两次searchtext时,第一次弹出来的值是exam,第二次是question[@seq='随机值1'],第三次跟第二次一模一样,第四次是question[@seq='随机值2'],而结果是所有的XML里的内容全部显示出来。
    还有个问题是,我需要家题目的序列号。一般而言,序列号应该跟题目是一行的。可我这里,序列号怎么都是跟题目上下行,也请哪为高手之间一二!

    郁闷之极,期待解惑!
    谢谢,谢谢!


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/6/5 21:37:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 DOM/SAX/XPath 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/4/29 7:56:24

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    93.750ms