源代码:
<?xml version="1.0" encoding="UTF-8"?>
<Emp>
<EmpDetail>
<ProjectDetails>
<Code>Project</Code>
<ProjectReference>
<Reference>
<RefCode>PROJ1</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<ProjectDetails>
<Code>Element</Code>
<ProjectReference>
<Reference>
<RefCode>ELEM1</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<Period>
<PeriodNo>1</PeriodNo>
</Period>
<AmountDetails>
<Currency>EUR</Currency>
<Amount>
<Value>100.00</Value>
</Amount>
</AmountDetails>
</EmpDetail>
<EmpDetail>
<ProjectDetails>
<Code>Project</Code>
<ProjectReference>
<Reference>
<RefCode>PROJ1</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<ProjectDetails>
<Code>Element</Code>
<ProjectReference>
<Reference>
<RefCode>ELEM1</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<Period>
<PeriodNo>1</PeriodNo>
</Period>
<AmountDetails>
<Currency>EUR</Currency>
<Amount>
<Value>5000</Value>
</Amount>
</AmountDetails>
</EmpDetail>
<EmpDetail>
<ProjectDetails>
<Code>Project</Code>
<ProjectReference>
<Reference>
<RefCode>PROJ2</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<ProjectDetails>
<Code>Element</Code>
<ProjectReference>
<Reference>
<RefCode>ELEM2</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<Period>
<PeriodNo>2</PeriodNo>
</Period>
<AmountDetails>
<Currency>EUR</Currency>
<Amount>
<Value>200.00</Value>
</Amount>
</AmountDetails>
</EmpDetail>
<EmpDetail>
<ProjectDetails>
<Code>Project</Code>
<ProjectReference>
<Reference>
<RefCode>PROJ2</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<ProjectDetails>
<Code>Element</Code>
<ProjectReference>
<Reference>
<RefCode>ELEM2</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<Period>
<PeriodNo>3</PeriodNo>
</Period>
<AmountDetails>
<Currency>EUR</Currency>
<Amount>
<Value>500</Value>
</Amount>
</AmountDetails>
</EmpDetail>
</Emp>
目标xml:
<?xml version="1.0" encoding="UTF-8"?>
<Emp>
<EmpDetail>
<ProjectDetails>
<Code>Project</Code>
<ProjectReference>
<Reference>
<RefCode>PROJ1</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<ProjectDetails>
<Code>Element</Code>
<ProjectReference>
<Reference>
<RefCode>ELEM1</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<Period>
<PeriodNo>1</PeriodNo>
</Period>
<AmountDetails>
<Currency>EUR</Currency>
<Amount>
<Value>5100.00</Value>
</Amount>
</AmountDetails>
</EmpDetail>
<EmpDetail>
<ProjectDetails>
<Code>Project</Code>
<ProjectReference>
<Reference>
<RefCode>PROJ2</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<ProjectDetails>
<Code>Element</Code>
<ProjectReference>
<Reference>
<RefCode>ELEM2</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<Period>
<PeriodNo>2</PeriodNo>
</Period>
<AmountDetails>
<Currency>EUR</Currency>
<Amount>
<Value>200.00</Value>
</Amount>
</AmountDetails>
</EmpDetail>
<EmpDetail>
<ProjectDetails>
<Code>Project</Code>
<ProjectReference>
<Reference>
<RefCode>PROJ2</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<ProjectDetails>
<Code>Element</Code>
<ProjectReference>
<Reference>
<RefCode>ELEM2</RefCode>
</Reference>
</ProjectReference>
</ProjectDetails>
<Period>
<PeriodNo>3</PeriodNo>
</Period>
<AmountDetails>
<Currency>EUR</Currency>
<Amount>
<Value>500</Value>
</Amount>
</AmountDetails>
</EmpDetail>
</Emp>
查询:如果 PeriodNo、Project 的 RefCode 和 Element 的 RefCode 相同,那么我必须对金额值求和,并且应该只生成一条记录。在我的源文件中,前两个 line item 的 periodno、project 的 refcode 和 element 的 refcode 是相同的,所以想在输出中只获取一条记录,并且金额值应该是 (100+5000) = 5100。
我知道我是否必须检查一个值并计算 lineitem 的总和,但在这种情况下,我必须检查每条记录中的 3 个值并且我已经对其求和。您能否告诉我,如何使用 xslt 进行操作。我有 XSLT 1.0 版本。