繁体   English   中英

XSLT 2.0-带汇总的高级分组(WordML)

[英]XSLT 2.0 - High Level Grouping with Sums (WordML)

亲爱的专业人员,

我有一些联合计费XML代码,其中包含考勤卡/计时器汇总。 我可以轻松地按特定事项分组,然后按Timekeeper分组,以获取每个事项的总计。 但是我需要得到计时员所有联合费用的全部小时数和计费金额的总和,而不仅仅是每个问题。

我在下面引用了所有代码,但是从@ Tim-C的注释进行了更新。 XSL转换链接在这里

输入:

<?xml version="1.0" encoding="utf-8"?>
<superbill>
    <invoice type="P" id="562845" number="562845">
        <matters>
            <matter number="014592-000007">
                <timecard-summary-by-timekeeper>
                    <timekeeper-summary timekeeper-id="NC1">
                        <timekeeper>
                            <initials>NC1</initials>
                            <billingname>Nicholas J. Collins</billingname>
                        </timekeeper>
                        <timekeeper-summary-totals>
                            <timekeeper-summary-total type="billed">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="worked">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="standard">
                                <total type="rate">525.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate1">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate2">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                        </timekeeper-summary-totals>
                    </timekeeper-summary>
                    <timekeeper-summary timekeeper-id="BJB">
                        <timekeeper>
                            <initials>BJB</initials>
                            <billingname>Billie J. Bob</billingname>
                        </timekeeper>
                        <timekeeper-summary-totals>
                            <timekeeper-summary-total type="billed">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="worked">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="standard">
                                <total type="rate">575.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate1">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate2">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                        </timekeeper-summary-totals>
                    </timekeeper-summary>
                </timecard-summary-by-timekeeper>
            </matter>
            <matter number="014592-000091">
                <timecard-summary-by-timekeeper>
                    <timekeeper-summary timekeeper-id="NC1">
                        <timekeeper>
                            <initials>NC1</initials>
                            <billingname>Nicholas J. Collins</billingname>
                        </timekeeper>
                        <timekeeper-summary-totals>
                            <timekeeper-summary-total type="billed">
                                <total type="rate">525.00</total>
                                <total type="hours">1.00</total>
                                <total type="amount">525.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="worked">
                                <total type="rate">525.00</total>
                                <total type="hours">1.00</total>
                                <total type="amount">525.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="standard">
                                <total type="rate">525.00</total>
                                <total type="hours">1.00</total>
                                <total type="amount">525.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate1">
                                <total type="rate">525.00</total>
                                <total type="hours">1.00</total>
                                <total type="amount">525.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate2">
                                <total type="rate">0.00</total>
                                <total type="hours">1.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                        </timekeeper-summary-totals>
                    </timekeeper-summary>
                    <timekeeper-summary timekeeper-id="BJB">
                        <timekeeper>
                            <initials>BJB</initials>
                            <billingname>Billie J. Bob</billingname>
                        </timekeeper>
                        <timekeeper-summary-totals>
                            <timekeeper-summary-total type="billed">
                                <total type="rate">575.00</total>
                                <total type="hours">11.00</total>
                                <total type="amount">6325.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="worked">
                                <total type="rate">575.00</total>
                                <total type="hours">11.00</total>
                                <total type="amount">6325.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="standard">
                                <total type="rate">575.00</total>
                                <total type="hours">11.00</total>
                                <total type="amount">6325.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate1">
                                <total type="rate">575.00</total>
                                <total type="hours">11.00</total>
                                <total type="amount">6325.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate2">
                                <total type="rate">0.00</total>
                                <total type="hours">11.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                        </timekeeper-summary-totals>
                    </timekeeper-summary>
                </timecard-summary-by-timekeeper>
            </matter>
            <matter number="014592-000092">
                <timecard-summary-by-timekeeper>
                    <timekeeper-summary timekeeper-id="NC1">
                        <timekeeper>
                            <initials>NC1</initials>
                            <billingname>Nicholas J. Collins</billingname>
                        </timekeeper>
                        <timekeeper-summary-totals>
                            <timekeeper-summary-total type="billed">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="worked">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="standard">
                                <total type="rate">525.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate1">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate2">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                        </timekeeper-summary-totals>
                    </timekeeper-summary>
                    <timekeeper-summary timekeeper-id="BJB">
                        <timekeeper>
                            <initials>BJB</initials>
                            <billingname>Billie J. Bob</billingname>
                        </timekeeper>
                        <timekeeper-summary-totals>
                            <timekeeper-summary-total type="billed">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="worked">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="standard">
                                <total type="rate">575.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate1">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate2">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                        </timekeeper-summary-totals>
                    </timekeeper-summary>
                </timecard-summary-by-timekeeper>
            </matter> 
            <matter number="014592-000095">
                <timecard-summary-by-timekeeper>
                    <timekeeper-summary timekeeper-id="NC1">
                        <timekeeper>
                            <initials>NC1</initials>
                            <billingname>Nicholas J. Collins</billingname>
                        </timekeeper>
                        <timekeeper-summary-totals>
                            <timekeeper-summary-total type="billed">
                                <total type="rate">525.00</total>
                                <total type="hours">4.00</total>
                                <total type="amount">2100.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="worked">
                                <total type="rate">525.00</total>
                                <total type="hours">4.00</total>
                                <total type="amount">2100.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="standard">
                                <total type="rate">525.00</total>
                                <total type="hours">4.00</total>
                                <total type="amount">2100.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate1">
                                <total type="rate">525.00</total>
                                <total type="hours">4.00</total>
                                <total type="amount">2100.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate2">
                                <total type="rate">0.00</total>
                                <total type="hours">4.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                        </timekeeper-summary-totals>
                    </timekeeper-summary>
                    <timekeeper-summary timekeeper-id="BJB">
                        <timekeeper>
                            <initials>BJB</initials>
                            <billingname>Billie J. Bob</billingname>
                        </timekeeper>
                        <timekeeper-summary-totals>
                            <timekeeper-summary-total type="billed">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="worked">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="standard">
                                <total type="rate">575.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate1">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate2">
                                <total type="rate">0.00</total>
                                <total type="hours">0.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                        </timekeeper-summary-totals>
                    </timekeeper-summary>
                </timecard-summary-by-timekeeper>
            </matter>
            <matter number="014592-000096">
                <timecard-summary-by-timekeeper>
                    <timekeeper-summary timekeeper-id="NC1">
                        <timekeeper>
                            <initials>NC1</initials>
                            <billingname>Nicholas J. Collins</billingname>
                        </timekeeper>
                        <timekeeper-summary-totals>
                            <timekeeper-summary-total type="billed">
                                <total type="rate">525.00</total>
                                <total type="hours">20.00</total>
                                <total type="amount">10500.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="worked">
                                <total type="rate">525.00</total>
                                <total type="hours">20.00</total>
                                <total type="amount">10500.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="standard">
                                <total type="rate">525.00</total>
                                <total type="hours">20.00</total>
                                <total type="amount">10500.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate1">
                                <total type="rate">525.00</total>
                                <total type="hours">20.00</total>
                                <total type="amount">10500.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate2">
                                <total type="rate">0.00</total>
                                <total type="hours">20.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                        </timekeeper-summary-totals>
                    </timekeeper-summary>
                    <timekeeper-summary timekeeper-id="BJB">
                        <timekeeper>
                            <initials>BJB</initials>
                            <billingname>Billie J. Bob</billingname>
                        </timekeeper>
                        <timekeeper-summary-totals>
                            <timekeeper-summary-total type="billed">
                                <total type="rate">575.00</total>
                                <total type="hours">4.00</total>
                                <total type="amount">2300.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="worked">
                                <total type="rate">575.00</total>
                                <total type="hours">4.00</total>
                                <total type="amount">2300.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="standard">
                                <total type="rate">575.00</total>
                                <total type="hours">4.00</total>
                                <total type="amount">2300.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate1">
                                <total type="rate">575.00</total>
                                <total type="hours">4.00</total>
                                <total type="amount">2300.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                            <timekeeper-summary-total type="timerate2">
                                <total type="rate">0.00</total>
                                <total type="hours">4.00</total>
                                <total type="amount">0.00</total>
                                <total type="adjustment">0.00</total>
                            </timekeeper-summary-total>
                        </timekeeper-summary-totals>
                    </timekeeper-summary>
                </timecard-summary-by-timekeeper>
            </matter>
        </matters>
    </invoice>
</superbill>

当前代码:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
               xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" 
                version="2.0">
    <xsl:output method="xml" indent="yes" />

    <xsl:template match="/">
        <xsl:call-template name="XJ_TKSummary_02" />
    </xsl:template>

    <xsl:template name="XJ_TKSummary_02">
       <xsl:variable name="TW" select="1440" />
        <xsl:for-each-group select="//superbill/invoice/matters/matter/timecard-summary-by-timekeeper/timekeeper-summary/timekeeper" group-by="../@timekeeper-id">
            <w:p>
                <w:r>
                    <w:t><xsl:value-of select="initials" /> - <xsl:value-of select="billingname" /></w:t>
                </w:r>
            </w:p>
            <w:p>
                <w:r>
                    <xsl:variable name="groupTotals" select="current-group()/timekeeper-summary-totals/timekeeper-summary-total[@type='billed']/total" />
                    <w:t>
                        Hours: <xsl:value-of select="format-number(sum($groupTotals[@type='hours']), '###,##0.00')" />
                        for $ <xsl:value-of select="format-number(sum($groupTotals[@type='amount']), '###,##0.00')" />
                    </w:t>
                </w:r>
            </w:p>
        </xsl:for-each-group>
    </xsl:template>
</xsl:stylesheet>

输出:

所需的总计应为...

NC1 - Nicholas J. Collins
Hours: 25.00 for $13,125.00

BJB - Billie J. Bob
Hours: 15.00 for $8,625.00

任何帮助都将不胜感激。

看待,

-缺口

您需要做的主要事情是将xsl:for-each-group更改为此...

<xsl:for-each-group select="//invoice/matter/timecard-summary-by-timekeeper/timekeeper-summary/timekeeper" group-by="../@timekeeper-id">

因此,您正在按其父timekeeper-id属性对timekeeper记录进行分组。

您还需要在xpath中包括timekeeper-summary-totals以获得总时数和总金额。

<w:t>
  Hours: 
 <xsl:value-of select="format-number(sum(current-group()/timekeeper-summary-totals/timekeeper-summary-total[@type='billed']/total[@type='hours']), '###,##0.00')" />
 for $
 <xsl:value-of select="format-number(sum(current-group()/timekeeper-summary-totals/timekeeper-summary-total[@type='billed']/total[@type='amount']), '###,##0.00')" />
</w:t>

或者,更好的是,使用变量来减少xpath的代码位置

试试这个简短的XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
               xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" 
                version="2.0">
    <xsl:output method="xml" indent="yes" />

    <xsl:template match="/">
        <xsl:call-template name="XJ_TKSummary_02" />
    </xsl:template>

    <xsl:template name="XJ_TKSummary_02">
       <xsl:variable name="TW" select="1440" />
        <xsl:for-each-group select="//invoice/matter/timecard-summary-by-timekeeper/timekeeper-summary/timekeeper" group-by="../@timekeeper-id">
            <w:p>
                <w:r>
                    <w:t><xsl:value-of select="initials" /> - <xsl:value-of select="billingname" /></w:t>
                </w:r>
            </w:p>
            <w:p>
                <w:r>
                    <xsl:variable name="groupTotals" select="current-group()/timekeeper-summary-totals/timekeeper-summary-total[@type='billed']/total" />
                    <w:t>
                        Hours: <xsl:value-of select="format-number(sum($groupTotals[@type='hours']), '###,##0.00')" />
                        for $ <xsl:value-of select="format-number(sum($groupTotals[@type='amount']), '###,##0.00')" />
                    </w:t>
                </w:r>
            </w:p>
        </xsl:for-each-group>
    </xsl:template>
</xsl:stylesheet>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM