我有一个时间表列表,可以通过WordML(使用XSLT 2.0)在MS Word中作为输出列出,并且认为我需要进行某种类型的分组,但我不确定如何完成分组(如果可能的话)。
高层人士正在寻找的是按每个日期(按日期排序),所有信息都被汇总到每个计时员的一个区域中。(日期,计时员姓名缩写,该日期的工作时间总和,该计时员该日期所有叙事数据的列表)。
这是我目前所拥有的,这只是每个日期的每个计时员/时间卡,没有分组的地方。
输入:
<xml-sample>
<timecard index="10">
<timekeeper>
<initials>NC1</initials>
</timekeeper>
<date type="timecard">2015-09-01</date>
<card-values>
<card-value type="billed">
<rate>325.00</rate>
<hours>0.20</hours>
<amount>65.0000</amount>
</card-value>
</card-values>
<narrative>
<line id="1">Narrative for 9/1/2015. With some more detail</line>
<line id="2">on the 2nd line ID.</line>
</narrative>
</timecard>
<timecard index="11">
<timekeeper>
<initials>NC1</initials>
</timekeeper>
<date type="timecard">2015-09-01</date>
<card-values>
<card-value type="billed">
<rate>325.00</rate>
<hours>0.40</hours>
<amount>130.0000</amount>
</card-value>
</card-values>
<narrative>
<line id="1">Another narrative for 9/1/2015. With some more</line>
<line id="2">detail on the 2nd line ID.</line>
</narrative>
</timecard>
<timecard index="12">
<timekeeper>
<initials>NC1</initials>
</timekeeper>
<date type="timecard">2015-09-12</date>
<card-values>
<card-value type="billed">
<rate>325.00</rate>
<hours>0.30</hours>
<amount>97.5000</amount>
</card-value>
</card-values>
<narrative>
<line id="1">Narrative for 9/12/2015. With some more detail</line>
<line id="2">detail on the 2nd line ID.</line>
</narrative>
</timecard>
当前代码:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:kmf="http://www.kleinmundo.com/functions"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
xmlns:tlr="http://www.elite.com/functions"
xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template name="Time_Detail_Sample">
<xsl:for-each select="xsm-sample/timecard">
<w:p>
<w:r>
<w:t>Date: <xsl:value-of select="format-date(date, '[M01]/[D01]/[Y01]')" />
</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>Timekeeper: <xsl:value-of select="timekeeper/initials" />
</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>Hours: <xsl:value-of select="format-number(card-values/card-value[@type='billed']/hours, '###,##0.00')" />
</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<xsl:for-each select="narrative/line">
<w:t>
<xsl:value-of select="(.)" />
<xsl:value-of select="' '" />
</w:t>
</xsl:for-each>
</w:r>
</w:p>
<w:p />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
当前输出:
期望的输出:(如您所见,2015年9月1日的数据汇总为小时总和,所有“叙述”详细信息一并列出)。
我肯定会使用xsl:for-each-group
...
<xsl:for-each-group select="timecard"
group-by="string-join((timekeeper/initials,date[@type='timecard']),'|')">
<xsl:sort select="date[@type='timecard']"/>
<w:p>
<w:r>
<w:t>
<xsl:text>Date: </xsl:text>
<xsl:value-of select="format-date(date, '[M01]/[D01]/[Y01]')"/>
</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>
<xsl:text>Timekeeper: </xsl:text>
<xsl:value-of select="timekeeper/initials"/>
</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>
<xsl:text>Hours: </xsl:text>
<xsl:value-of select="format-number(sum(current-group()/card-values/card-value[@type='billed']/hours), '###,##0.00')"/>
</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>
<xsl:value-of select="current-group()/narrative/line" separator=" "/>
</w:t>
</w:r>
</w:p>
<w:p/>
</xsl:for-each-group>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句