首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XForms重复问题

XForms重复问题
EN

Stack Overflow用户
提问于 2011-02-08 16:34:16
回答 1查看 281关注 0票数 2

我在用XForms呈现我的XML文件的内容时遇到了一些问题。我没有那么多的经验,所以如果有人能给我一个提示,那就太好了。

我的XML看起来像这样:

代码语言:javascript
复制
<schedule>
  <day>
    <course> 
    </course>
    <course>
    </course>
     ..
  </day>
  <day>
    <course>
    </course>
    ..
  </day>
  ..
</schedule>

如果我说

代码语言:javascript
复制
<xforms:repeat nodeset="day/course" id="whatever">
   <!-- here handling of nodes -->
  </xforms:repeat>

我只得到了每个day...How的第一个课程,我应该改变它,这样我就可以得到一天中所有课程的节点了吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-09 02:29:22

您在那里的重复应该遍历所有<day>的所有<course>。例如,下面显示:数学、物理、英语、历史。

代码语言:javascript
复制
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
            xmlns:xforms="http://www.w3.org/2002/xforms"
            xmlns:ev="http://www.w3.org/2001/xml-events"
            xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xhtml:head>
        <xhtml:title>Repeat</xhtml:title>
        <xforms:model>
            <xforms:instance>
                <schedule>
                    <day label="Monday">
                        <course label="Math"/>
                        <course label="Physics"/>
                    </day>
                    <day>
                        <course label="English"/>
                        <course label="History"/>
                    </day>
                </schedule>
            </xforms:instance>
        </xforms:model>
    </xhtml:head>
    <xhtml:body>
        <xforms:repeat nodeset="day/course">
            <xhtml:div>
                <xforms:output value="@label"/>
            </xhtml:div>
        </xforms:repeat>
    </xhtml:body>
</xhtml:html>

但通常情况下,您要做的是首先迭代几天,然后遍历课程,如下所示:

代码语言:javascript
复制
<xforms:repeat nodeset="day">
    <xhtml:div>
        Day: <xforms:output value="@label"/>
        <xforms:repeat nodeset="course">
            <xhtml:div>Course: <xforms:output value="@label"/></xhtml:div>
        </xforms:repeat>
    </xhtml:div>
</xforms:repeat>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4930975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档