XML的XSLT转换为文本,从而得到一个空文件。

时间:2018-10-16 17:32:41

标签: xml xslt

我正在为我的xslt转换寻找以下输出。当我运行转换时,它不生成任何数据,也不会引发任何错误。任何帮助将不胜感激。我想打印H current_eefectivedate和090618 CREDIT UNION SSA DEPOST。然后,对于每个记录D 06 current_efectivedate 091 deduction_amount,然后是拖车。

H 090618 CREDIT UNION SSA DEPOST
D 06 1083231 091 0001200            
D 06 1142308 091 0001200            
D 06 1174967 091 0002000            
D 06 1251417 091 0002000            
T 00004 000006400

预告片打印记录计数并扣除总和(最后7个字符)。


XML文件是:

<?xml version="1.0" encoding="UTF-8"?>

<wd:Report_Data xmlns:wd="urn:com.workday.report/INT063_RPT_SSA_Deductions_Outbound">
<wd:Report_Entry>
        <wd:Worker wd:Descriptor="******">
            <wd:ID wd:type="WID">265c773ade2d0177442bf7738d366e62</wd:ID>
            <wd:ID wd:type="Employee_ID">*****</wd:ID>
        </wd:Worker>
        <wd:Team_Member_ID>1190969</wd:Team_Member_ID>
        <wd:CFI_TC_INT006_Global_H>H</wd:CFI_TC_INT006_Global_H>
        <wd:Current_Effective_Date>240918</wd:Current_Effective_Date>
        <wd:CFI_TC_Global_T>T</wd:CFI_TC_Global_T>
        <wd:Related_Calculations>
            <wd:CFI_INT036_Bank_Acc_Number_Extract>25</wd:CFI_INT036_Bank_Acc_Number_Extract>
        </wd:Related_Calculations>
        <wd:Worker>
            <wd:CF_TC_Credit_Union_Pay_Deduct>CREDIT UNION SSA DEPOST</wd:CF_TC_Credit_Union_Pay_Deduct>
            <wd:CFI_TC_INT006_Global_D>D</wd:CFI_TC_INT006_Global_D>
            <wd:TC_06_INT063>06</wd:TC_06_INT063>
            <wd:TC_009_INT063>009</wd:TC_009_INT063>
            <wd:CF_Text_Constant_0>0</wd:CF_Text_Constant_0>
            <wd:CF_Text_Constant_CCD>CCD</wd:CF_Text_Constant_CCD>
        </wd:Worker>
        <wd:Deduction_Amount>25</wd:Deduction_Amount>
        <wd:CFI_EE_INT010_Payroll_Result_Line_Source_type>181011</wd:CFI_EE_INT010_Payroll_Result_Line_Source_type>
    </wd:Report_Entry>
</wd:Report_Data>


------------------------

我的XSLT:

<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:etv="urn:com.workday/etv" 
    xmlns:functx="http://www.functx.com"
    xmlns:wd="urn:com.workday.report/INT063_RPT_SSA_Deductions_Outbound" xmlns:xtt="urn:com.workday/xtt">

    <xsl:output method="text" indent="yes"/>
    <xsl:variable name="linefeed" select="'&#xD;&#xA;'"></xsl:variable>
    <xsl:decimal-format decimal-separator="," grouping-separator="."/>
    <xsl:template match="wd:Report_Data">

                <xsl:value-of select="wd:Report_Entry[1]/wd:CFI_TC_INT006_Global_H"/>

                <xsl:value-of select="wd:Report_Entry[1]/wd:Current_Effective_Date"/>

                <xsl:value-of select="wd:Report_Entry[1]/wd:Worker/wd:CF_TC_Credit_Union_Pay_Deduct"/>

            <xsl:value-of select="$linefeed"/>

        <xsl:for-each-group select="wd:Report_Entry" group-by="wd:Worker/wd:ID[@wd:type='Employee_ID']">       

              <xsl:for-each select="current-grouping-key()">
                <Record1 etv:incrementNumber="rNumber">
                <xsl:variable name="VAR1" select="sum(current-group()/wd:Deduction_Amount)"/>
                <xsl:if test="$VAR1 &gt;0">
                    <ConstantD>
                        <xsl:value-of select="current-group()[1]/wd:Worker/wd:CFI_TC_INT006_Global_D"/>
                    </ConstantD>
                   <Current_Effective_Date>                   
                        <xsl:value-of select="current-group()[1]/wd:Current_Effective_Date"/>           
                    </Current_Effective_Date>
                    <Constant06>
                        <xsl:value-of select="current-group()[1]/wd:Worker/wd:TC_06_INT063"/>
                    </Constant06>
                    <Constant009>
                        <xsl:value-of select="current-group()[1]/wd:Worker/wd:TC_009_INT063"/>
                    </Constant009>

                    <Constant0>
                        <xsl:value-of select="current-group()[1]/wd:Worker/wd:CF_Text_Constant_0"/>
                    </Constant0>
                    <AccountNumber>                   
                        <xsl:value-of select="format-number(current-group()[1]/wd:Related_Calculations/wd:CFI_INT036_Bank_Acc_Number_Extract,'00000000')"> </xsl:value-of>          
                    </AccountNumber>
                    <CheckingCode>                   
                        <xsl:value-of select="current-group()[1]/wd:Worker/CF_Text_Constant_CCD"> </xsl:value-of>          
                    </CheckingCode>
                    <Amount etv:addNumber="amountSum" xtt:fixedLength="7" xtt:paddingCharacter="0">
                        <xsl:value-of select="format-number(current-group()[1]/wd:Deduction_Amount*100,'0000000')"/>
                    </Amount>

                    <xsl:value-of select="'          '"/>

                    <xsl:value-of select="$linefeed"/>
                </xsl:if>
                </Record1>
            </xsl:for-each>
        </xsl:for-each-group>

                <xsl:value-of select="wd:Report_Entry[1]/wd:CFI_TC_Global_T"/>
                <count etv:number="rNumber"/>     
                <xsl:value-of select="format-number(count(wd:Report_Entry),'00000')"/>
                <xsl:value-of select="format-number((sum(wd:Report_Entry/wd:Deduction_Amount)*100),'000000000')"/>
                <xsl:value-of select="'               '"/>   
                <xsl:value-of select="$linefeed"/>
    </xsl:template>
</xsl:stylesheet>

1 个答案:

答案 0 :(得分:1)

您希望获得text元素指示的<xsl:output method="text"...>结果。因此,我删除了您的一些结果元素,因为它们是多余的。

剩下的是下面的模板,其中包含wd:Report_Data元素的数据介绍和所有wd:Report_Entry元素的迭代。

<xsl:template match="wd:Report_Data">
    <xsl:value-of select="concat(wd:Report_Entry[1]/wd:CFI_TC_INT006_Global_H,' ',
    wd:Report_Entry[1]/wd:Current_Effective_Date,' ',wd:Report_Entry[1]/wd:Worker/wd:CF_TC_Credit_Union_Pay_Deduct,$linefeed)"/>

    <xsl:for-each-group select="wd:Report_Entry" group-by="wd:Worker/wd:ID[@wd:type='Employee_ID']">       
          <xsl:for-each select="current-grouping-key()">
            <xsl:variable name="VAR1" select="sum(current-group()/wd:Deduction_Amount)" />
            <xsl:if test="$VAR1 > 0">
                <xsl:value-of select="current-group()[1]/wd:Worker/wd:CFI_TC_INT006_Global_D" />
                <xsl:text> </xsl:text>
                <xsl:value-of select="current-group()[1]/wd:Worker/wd:TC_06_INT063"/>
                <xsl:text> </xsl:text>
                <xsl:value-of select="current-group()[1]/wd:Current_Effective_Date"/>           
                <xsl:text> </xsl:text>
                <xsl:value-of select="current-group()[1]/wd:Worker/wd:TC_009_INT063"/>
                <xsl:text> </xsl:text>
                <xsl:value-of select="current-group()[1]/wd:Worker/wd:CF_Text_Constant_0"/>
                <xsl:text> </xsl:text>
                <xsl:value-of select="format-number(current-group()[1]/wd:Related_Calculations/wd:CFI_INT036_Bank_Acc_Number_Extract,'00000000')"> </xsl:value-of>          
                <xsl:text> </xsl:text>
                <xsl:value-of select="current-group()[1]/wd:Worker/CF_Text_Constant_CCD"> </xsl:value-of>          
                <xsl:text> </xsl:text>
                <xsl:value-of select="format-number(current-group()[1]/wd:Deduction_Amount*100,'0000000')"/>
                <xsl:text> </xsl:text>
                <xsl:value-of select="'          '"/>
                <xsl:value-of select="$linefeed"/>
            </xsl:if>
        </xsl:for-each>
    </xsl:for-each-group>

    <xsl:value-of select="wd:Report_Entry[1]/wd:CFI_TC_Global_T"/>
    <xsl:text> </xsl:text>
    <count etv:number="rNumber"/>     
    <xsl:value-of select="format-number(count(wd:Report_Entry),'00000')"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="format-number((sum(wd:Report_Entry/wd:Deduction_Amount)*100),'000000000')"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="'               '"/>   
    <xsl:text> </xsl:text>
    <xsl:value-of select="$linefeed"/>
</xsl:template>

其结果类似于以下内容。由于您的XML不完整,因此我添加了另一个具有相似值的wd:Report_Entry。因此,此结果包含两个wd:Report_Entry条目。因此,结果与您给出的示例有所不同,但是格式是您想要的。

H 240918 CREDIT UNION SSA DEPOST
D 06 240918 009 0 00000025  0002500           
D 06 240918 009 0 00000025  0003000           
T 00002 000005500