How would I get a count of the output records (rows/lines) AFTER going through a Muenchian Group

40 Views Asked by At

Here are two entries in the xml. There are thousands of these.

<Export xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Record>
    <AccountNo>700101030</AccountNo>
    <Amount>9166.67</Amount>
    <PayDate>20230714</PayDate>
    <PPEndDate>07/15/2023</PPEndDate>
    <Description>Regular                                       </Description>
    <Category>Earning</Category>
    <Desc>Regular</Desc>
    <EmpNumber>1800411</EmpNumber>
    <EmpFirstName>Denis</EmpFirstName>
    <EmpLastName>Chevalier</EmpLastName>
    <DeptName>0839865300</DeptName>
    <OnSiteName>0839865300 - New York 1 Columbus Circle - 0839</OnSiteName>
    <LedgerCode>0839865300</LedgerCode>
    <Constant1>ERN</Constant1>
    <Filler1>                         </Filler1>
    <Filler2>                  </Filler2>
</Record>
<Record>
    <AccountNo>283410165</AccountNo>
    <Amount>-6.24</Amount>
    <PayDate>20230714</PayDate>
    <PPEndDate>07/15/2023</PPEndDate>
    <Description>Vision Pretax                                 </Description>
    <Category>Deduction</Category>
    <Desc>Vision Pretax</Desc>
    <EmpNumber>1800411</EmpNumber>
    <EmpFirstName>Denis</EmpFirstName>
    <EmpLastName>Chevalier</EmpLastName>
    <DeptName>0839865300</DeptName>
    <OnSiteName>0839865300 - New York 1 Columbus Circle - 0839</OnSiteName>
    <DeptOverride>6201350008</DeptOverride>
    <LedgerCode>0839865300</LedgerCode>
    <Constant1>DED</Constant1>
    <Filler1>                         </Filler1>
    <Filler2>                  </Filler2>
</Record>       

Here is the body of the xslt:

<xsl:output method="text" indent="no" />
<xsl:key name="kRcdGroup" match="Export/Record" use="concat(generate-id(..), AccountNo, Description, vb:GetOverrideCode(DeptOverride,LedgerCode))"/>

<xsl:template match="node()|@*">
    <xsl:apply-templates select="node()|@*"/>
</xsl:template>

<xsl:template match="Export">

    <!-- Header Record -->
    <xsl:value-of select="'01'"/>
    <xsl:value-of select="vb:GetDate()"/>
    <xsl:value-of select="'BT        '"/>
    <xsl:value-of select="'PayrollNew2    '"/>
    <xsl:text>&#x0D;&#x0A;</xsl:text>

    <!-- Detail Records -->
    <xsl:for-each select="Record[generate-id() = generate-id(key('kRcdGroup',concat(generate-id(..), AccountNo, Description, vb:GetOverrideCode(DeptOverride,LedgerCode)))[1])] ">            

        <xsl:variable name="vkeyGroup" select="key('kRcdGroup', concat(generate-id(..), AccountNo, Description, vb:GetOverrideCode(DeptOverride,LedgerCode))) "/>
        <xsl:variable name="SumPos">
            <xsl:if test="Amount > 0">
                <xsl:value-of select="format-number(sum($vkeyGroup/Amount),'#.00')"/>
            </xsl:if>
        </xsl:variable>
        <xsl:variable name="SumNeg">
            <xsl:if test="Amount &lt; 0">
                <xsl:value-of select="format-number(sum($vkeyGroup/Amount)*-1,'#.00')"/>
            </xsl:if>
        </xsl:variable>
        <xsl:variable name="orc">
            <xsl:value-of select="substring(vb:GetOverrideCode(DeptOverride,LedgerCode),1,4)"/>
        </xsl:variable>

        <!-- Data output -->
        <xsl:value-of select="'02    '"/>
        <xsl:value-of select="'1'"/>
        <xsl:value-of select="$orc"/>
        <xsl:value-of select="PayDate"/>
        <xsl:value-of select="PayDate"/>
        <xsl:value-of select="'IX'"/>
        <xsl:choose>
            <xsl:when test="Amount > 0">
                <xsl:value-of select="'40'"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="'50'"/>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select="vb:PadR(Constant1,' ',4)"/>
        <xsl:value-of select="Description"/>
        <xsl:choose>
            <xsl:when test="Amount > 0">
                <xsl:value-of select="'S'"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="'H'"/>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select="'USD    '"/>
        <xsl:choose>
            <xsl:when test="Amount > 0">
                <xsl:value-of select="vb:PadL($SumPos,' ',14)" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="vb:PadL(translate($SumNeg,'-',''),' ',14)" />
            </xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select="vb:PadR(' ',' ',25)" />
        <xsl:value-of select="vb:PadR(AccountNo,' ',28)" />
        <xsl:value-of select="concat($orc,vb:GetOverrideCode(DeptOverride,LedgerCode))"/>
        <xsl:text>&#x0D;&#x0A;</xsl:text>

    </xsl:for-each>

    <!-- Footer Record -->
    <xsl:value-of select="'99'"/>
    <xsl:value-of select="format-number(count(/Export/Record/Description),'#####')"/>
    <xsl:text>    </xsl:text>
    
</xsl:template>

Everything is working fine except the footer. The count returns the number of description nodes based on the input BUT, I need the count to be AFTER the grouping occurs. Any help would be appreciated.

Thank you, Greg Gregerson

0

There are 0 best solutions below