非常感谢您的帮助。
我有一个大型的xml文件,需要合并/汇总行。我花了很多时间去研究我的XSLT For Dummies书中的内容,并尝试了许多论坛上的方案,但是我离目标还很远。如果您能提供任何指导,我将非常感激。
<Report>
<Report_Entry>
<POSTING-DATE>02292016</POSTING-DATE>
<pmtdt>2016-02-29-08:00</pmtdt>
<emp>10025</emp>
<cc>020107450</cc>
<union>N10025</union>
<fac>000002010</fac>
<job>8062</job>
<pay>RGR</pay>
<hours>2</hours>
</Report_Entry>
<Report_Entry>
<POSTING-DATE>02292016</POSTING-DATE>
<pmtdt>2016-02-29-08:00</pmtdt>
<emp>10025</emp>
<cc>020107450</cc>
<union>N10025</union>
<fac>000002010</fac>
<job>8062</job>
<pay>RGR</pay>
<hours>110.27</hours>
</Report_Entry>
<Report_Entry>
<POSTING-DATE>02292016</POSTING-DATE>
<pmtdt>2016-02-29-08:00</pmtdt>
<emp>10025</emp>
<cc>020107450</cc>
<union>N10025</union>
<fac>000002010</fac>
<job>8062</job>
<pay>RGR</pay>
<hours>61.07</hours>
</Report_Entry>
<Report_Entry>
<POSTING-DATE>02292016</POSTING-DATE>
<pmtdt>2016-02-29-08:00</pmtdt>
<emp>10025</emp>
<cc>020107450</cc>
<union>N10025</union>
<fac>000002010</fac>
<job>8062</job>
<pay>SAL</pay>
<hours>2.01</hours>
</Report_Entry>
<Report_Entry>
<POSTING-DATE>02292016</POSTING-DATE>
<pmtdt>2016-02-29-08:00</pmtdt>
<emp>10058</emp>
<cc>020107375</cc>
<union>N10058</union>
<fac>000002010</fac>
<job>8085</job>
<pay>SAL</pay>
<hours>130</hours>
</Report_Entry>
<Report_Entry>
<POSTING-DATE>02292016</POSTING-DATE>
<pmtdt>2016-02-29-08:00</pmtdt>
<emp>10102</emp>
<cc>020267515</cc>
<union>N10102</union>
<fac>000002026</fac>
<job>8066</job>
<pay>BLV</pay>
<hours>31</hours>
</Report_Entry>
<Report_Entry>
<POSTING-DATE>02292016</POSTING-DATE>
<pmtdt>2016-02-29-08:00</pmtdt>
<emp>10102</emp>
<cc>020267515</cc>
<union>N10102</union>
<fac>000002026</fac>
<job>8066</job>
<pay>SAL</pay>
<hours>125</hours>
</Report_Entry>
<Report_Entry>
<POSTING-DATE>02292016</POSTING-DATE>
<pmtdt>2016-02-29-08:00</pmtdt>
<emp>10102</emp>
<cc>020267515</cc>
<union>N10102</union>
<fac>000002026</fac>
<job>8066</job>
<pay>SAL</pay>
<hours>125</hours>
</Report_Entry>
<Report_Entry>
<POSTING-DATE>02292016</POSTING-DATE>
<pmtdt>2016-02-29-08:00</pmtdt>
<emp>10102</emp>
<cc>020267515</cc>
<union>N10102</union>
<fac>000002026</fac>
<job>8066</job>
<pay>VOL</pay>
<hours>15</hours>
</Report_Entry>
</Report_Data>
我的预期输出是每个员工/薪资组合的一行数据,并将相关的小时数总计:
N10025 000002010 8062 RGR 173.34
N10025 000002010 8062 SAL 2.01
N10058 000002010 8085 SAL 130
N10102 000002026 8066 BLV 31
N10102 000002026 8066 SAL 250
N10102 000002026 8066 VOL 15
我本来考虑不发布我的XSL文件,但那样做很不礼貌。请不要笑得太厉害...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:rd="urn:com.abcd.report/Report"
version="3.0">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="emp" match="/Report_Data/Report_Entry/emp" use="text()"/>
<xsl:key name="pay" match="/Report_Data/Report_Entry/pay" use="text()"/>
<xsl:variable name="newline" select="'
'"/>
<xsl:variable name="sep" select="'|'"/>
<xsl:template match="Report_Data/Report_Entry">
<file>
<line>
<xsl:for-each select = "emp[generate-id(.)=generate-id(key('emp',text())]">
<xsl:for-each select="key('emp',"'wd:pay')">
<xsl:if test="./text()=*/text()">
<!-- This is embarrassing -->
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</line>
</file>
</xsl:template>
</xsl:stylesheet>