Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath xForms汇总表_Xpath_Xforms_Xforms Betterform - Fatal编程技术网

Xpath xForms汇总表

Xpath xForms汇总表,xpath,xforms,xforms-betterform,Xpath,Xforms,Xforms Betterform,我有一个如下所示的xml: <table1> <row> <person>person1</person> <value>10</value> </row> <row> <person>person2</person> <value>20</value> &l

我有一个如下所示的xml:

<table1>
    <row>
        <person>person1</person>
        <value>10</value>
    </row>
    <row>
        <person>person2</person>
        <value>20</value>
    </row>
    <row>
        <person>person1</person>
        <value>5</value>
    </row>
</table1>
<summaryTable>
    <row>
        <person>person1</person>
        <value_total/>
    </row>
    <row>
        <person>person2</person>
        <value_total/>
    </row>
</summaryTable>
对于XForms 1,没有切换到XForms 2的选项,使用framework betterform,我希望通过计算“table1”中具有相同人名的行的总和来计算汇总表中的值。为此,我有以下条件:

<xf:bind id="bind_table1"
    nodeset="table1" repeatableElement="row">
    <xf:bind id="bind_head_table1" nodeset="head" />
    <xf:bind id="bind_row_table1" nodeset="row">
        <xf:bind id="bind_person" nodeset="person"  type="xf:string" />
        <xf:bind id="bind_value" nodeset="value"    type="xf:integer" />
    </xf:bind>
</xf:bind>
<xf:bind id="bind_summaryTable"
    nodeset="summaryTable"
    repeatableElement="row">
    <xf:bind id="bind_head_summaryTable" nodeset="head" />
    <xf:bind id="bind_row_summaryTable" nodeset="row">
        <xf:bind id="bind_person_name" nodeset="person_name" type="xf:string" readonly="true"/>
        <xf:bind id="bind_value_total" nodeset="value_total" type="xf:integer" readonly="true" calculate="SUM(//table1/row[person/text() = ../person_name/text()]/value)"/>
    </xf:bind>
</xf:bind>
最后我想要的是person1=15的值和person2=20的值,但是使用这个‘计算’表达式我得到了‘NaN’。如果我将计算表达式替换为文字字符串进行比较,如:

<xf:bind id="bind_value_total" nodeset="value_total" type="xf:integer" readonly="true" calculate="SUM(//table1/row[person/text() = 'person1']/value)"/>
然后我得到的值是15,总和是正确的。因此,错误似乎出现在比较表达式person/text=../person\u name/text中。有人知道正确的表达方式应该是什么吗

谢谢

尝试calculate属性中的上下文函数来引用当前节点,如下所示:

<xf:bind nodeset="summaryTable/row/value_total" calculate="sum(//table1/row[person/text() = context()/../person/text()]/value)"/>
上下文函数提供当前上下文节点。如果绑定引用具有多个节点的节点集,则将对每个节点计算一次,并且该节点就是上下文返回的节点


它适用于XSLTForms,也许您的betterForm版本支持它。

谢谢您的建议,但使用上下文的结果是相同的。我开始认为这是betterForm中的一个缺陷: