如何计算以下xml中按empid和日期分组后小时节点值的前3次出现之和,并将其存储在一个变量中
<Records>
<Line>
<EmpId>1</EmpId>
<Date>10/01/2012</Date>
<Hour>4</Hour>
</Line>
<Line>
<EmpId>1</EmpId>
<Date>10/01/2012</Date>
<Hour>4</Hour>
</Line>
<Line>
<EmpId>1</EmpId>
<Date>10/02/2012</Date>
<Hour>8</Hour>
</Line>
<Line>
<EmpId>1</EmpId>
<Date>10/03/2012</Date>
<Hour>8</Hour>
</Line>
<Line>
<EmpId>1</EmpId>
<Date>10/04/2012</Date>
<Hour>8</Hour>
</Line>
</Records>
所以变量的值应该是24
如果我正确阅读了您的要求,我认为这应该可以完成工作:
<xsl:key name="countHours" match="Line" use="concat(EmpId,'-',Date)" />
<xsl:template match="/">
<xsl:value-of select="sum(
Records/Line[
count(
preceding-sibling::*[
generate-id()=generate-id(key('countHours',concat(EmpId,'-',Date))[1])
]
) < 3
]/Hour
)" />
</xsl:template>