2017-05-25 61 views
0

最親愛的人,XSLT 2.0 - 高級分組用的款項(WordML中)

我有了時間內卡/計時器總結一些聯合結算XML代碼。我可以很容易地按特定的事項分組,然後由計時員進行分組,每個事情得到總數。但是我需要計算整個聯合賬單的時間和賬單總金額,而不僅僅是每件事。

我有下面引用的所有代碼,但從@ Tim-C的評論更新。 XSL轉換鏈接HERE

輸入:

<?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> 

OUTPUT:

所需的總費用應閱讀...

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

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

任何和所有的援助,將不勝感激。

方面,

-Nick

回答

1

你需要做的是改變xsl:for-each-group這主要的事情...

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

所以,你是分組timekeeper記錄由他們的父母timekeeper-id屬性。

您還需要在xpath中包含​​以獲得您的總小時數和金額。

<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代碼repitition

試試這個刪節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> 
+0

謝謝!我得到每個單獨的計時員,但時間和金額均爲0.00。 – NCollinsTE

+0

只注意到它只考慮第一個問題。剛剛測試過將第4個和第5個計時器添加到XML中的第2個問題中,並且它只列出了3個原始計時器並且沒有添加#。有些東西使它們保持在0.00。 – NCollinsTE

+0

@ NCollinsTE,考慮編輯你的問題,並提供一個最小的byt完整的輸入樣本來演示問題。當我嘗試使用您當前的代碼片段時,http://xsltransform.net/a9GiwC上的Tim代碼似乎輸出了迄今爲止描述的值。 –