2011-02-08 50 views
2

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

我的XML看起来是这样的:

<schedule> 
    <day> 
    <course> 
    </course> 
    <course> 
    </course> 
    .. 
    </day> 
    <day> 
    <course> 
    </course> 
    .. 
    </day> 
    .. 
</schedule> 

如果我说

<xforms:repeat nodeset="day/course" id="whatever"> 
    <!-- here handling of nodes --> 
    </xforms:repeat> 

我只得到每一天的第一道菜...我应该如何改变它,所以我得到了所有每天节点的课程?

感谢

回答

1

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

<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> 

但往往,你想要做的是在第一天的迭代,然后通过课程,如:

<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> 
+0

非常感谢!工作像一个魅力:) – AndaP 2011-02-08 19:30:12