1

我需要在 JD Edwards 中为 EDI 转换自定义发票程序的输出。报告中的 XML 数据格式不正确,我正在努力重组数据以满足 EDI 要求。我是 XSL 的新手,所以我一直在反复试验以得出结果。

我面临的挑战之一是报告没有正确构建数据。发票行不是发票标题的正确后代,如下面的 XML 输入所示。我让开发人员将发票编号添加到每个部分,希望我能够根据该发票编号重组数据。

我的问题是,如何更改 XSL 样式表代码以使输出与我想要的结果相匹配,从而创建正确的父/子/兄弟结构?

这是 XML 输入:

<R5942015>
    <Main___F4211_F42119_S1>
        <Header_S2>
            <ShipDate_ID11>2016-04-06</ShipDate_ID11>
            <CustomerNumber_ID92>10779</CustomerNumber_ID92>
            <InvoiceDate_ID107>2016-04-07</InvoiceDate_ID107>
            <DealerNumber_ID6>44014104</DealerNumber_ID6>
            <ShipmentNumber_ID70>169638</ShipmentNumber_ID70>
            <InvoiceNumber_ID62>8729266</InvoiceNumber_ID62>
        </Header_S2>
    </Main___F4211_F42119_S1>
    <Main___F4211_F42119_S1>
        <Line_Info_S4>
            <AckLineNumber_D_ID1>13</AckLineNumber_D_ID1>
            <LineExtendedPrice_D_ID8>1230.00</LineExtendedPrice_D_ID8>
            <_nd_Item_Number_D_ID3>010799</_nd_Item_Number_D_ID3>
            <DisplayInvoiceNumber_ID42>8729266</DisplayInvoiceNumber_ID42>
            <LineQuantityShipped_D_ID35>2</LineQuantityShipped_D_ID35>
            <AckLine_Freight_ID21>54.78</AckLine_Freight_ID21>
        </Line_Info_S4>
        <Summary_Info_S8>
            <AckExtendedPrice_T_ID2>1230.00</AckExtendedPrice_T_ID2>
            <Freight_T_ID6>54.78</Freight_T_ID6>
            <GrandTotal_T_ID17>1284.78</GrandTotal_T_ID17>
            <DisplayInvoiceNumber_ID39>8729266</DisplayInvoiceNumber_ID39>
        </Summary_Info_S8>
        <Remit_To_S11>
            <Invoice_No__ID19>Invoice No:</Invoice_No__ID19>
            <DisplayInvoiceNumber_ID18>8729266</DisplayInvoiceNumber_ID18>
            <Service_Charge_Message_ID14>Service charge message...</Service_Charge_Message_ID14>
        </Remit_To_S11>
        <Header_S2>
            <ShipDate_ID11>2016-04-06</ShipDate_ID11>
            <CustomerNumber_ID92>11005</CustomerNumber_ID92>
            <InvoiceDate_ID107>2016-04-07</InvoiceDate_ID107>
            <DealerNumber_ID6>50857355</DealerNumber_ID6>
            <ShipmentNumber_ID70>169638</ShipmentNumber_ID70>
            <InvoiceNumber_ID62>8729267</InvoiceNumber_ID62>
        </Header_S2>
    </Main___F4211_F42119_S1>
    <Main___F4211_F42119_S1>
        <Line_Info_S4>
            <AckLineNumber_D_ID1>3</AckLineNumber_D_ID1>
            <LineExtendedPrice_D_ID8>665.00</LineExtendedPrice_D_ID8>
            <_nd_Item_Number_D_ID3>010512</_nd_Item_Number_D_ID3>
            <DisplayInvoiceNumber_ID42>8729267</DisplayInvoiceNumber_ID42>
            <LineQuantityShipped_D_ID35>1</LineQuantityShipped_D_ID35>
            <AckLine_Freight_ID21>22.64</AckLine_Freight_ID21>
        </Line_Info_S4>
    </Main___F4211_F42119_S1>
    <Main___F4211_F42119_S1>
        <Line_Info_S4>
            <AckLineNumber_D_ID1>4</AckLineNumber_D_ID1>
            <LineExtendedPrice_D_ID8>665.00</LineExtendedPrice_D_ID8>
            <_nd_Item_Number_D_ID3>010512</_nd_Item_Number_D_ID3>
            <DisplayInvoiceNumber_ID42>8729267</DisplayInvoiceNumber_ID42>
            <LineQuantityShipped_D_ID35>1</LineQuantityShipped_D_ID35>
            <AckLine_Freight_ID21>22.64</AckLine_Freight_ID21>
        </Line_Info_S4>
    </Main___F4211_F42119_S1>
    <Main___F4211_F42119_S1>
        <Line_Info_S4>
            <AckLineNumber_D_ID1>5</AckLineNumber_D_ID1>
            <LineExtendedPrice_D_ID8>715.00</LineExtendedPrice_D_ID8>
            <_nd_Item_Number_D_ID3>010512</_nd_Item_Number_D_ID3>
            <DisplayInvoiceNumber_ID42>8729267</DisplayInvoiceNumber_ID42>
            <LineQuantityShipped_D_ID35>1</LineQuantityShipped_D_ID35>
            <AckLine_Freight_ID21>22.64</AckLine_Freight_ID21>
        </Line_Info_S4>
    </Main___F4211_F42119_S1>
    <Main___F4211_F42119_S1>
        <Line_Info_S4>
            <AckLineNumber_D_ID1>11</AckLineNumber_D_ID1>
            <LineExtendedPrice_D_ID8>665.00</LineExtendedPrice_D_ID8>
            <_nd_Item_Number_D_ID3>010512</_nd_Item_Number_D_ID3>
            <DisplayInvoiceNumber_ID42>8729267</DisplayInvoiceNumber_ID42>
            <LineQuantityShipped_D_ID35>1</LineQuantityShipped_D_ID35>
            <AckLine_Freight_ID21>22.64</AckLine_Freight_ID21>
        </Line_Info_S4>
    </Main___F4211_F42119_S1>
    <Main___F4211_F42119_S1>
        <Line_Info_S4>
            <AckLineNumber_D_ID1>21</AckLineNumber_D_ID1>
            <LineExtendedPrice_D_ID8>630.00</LineExtendedPrice_D_ID8>
            <_nd_Item_Number_D_ID3>016799</_nd_Item_Number_D_ID3>
            <DisplayInvoiceNumber_ID42>8729267</DisplayInvoiceNumber_ID42>
            <LineQuantityShipped_D_ID35>1</LineQuantityShipped_D_ID35>
            <AckLine_Freight_ID21>22.64</AckLine_Freight_ID21>
        </Line_Info_S4>
    </Main___F4211_F42119_S1>
    <Main___F4211_F42119_S1>
        <Line_Info_S4>
            <AckLineNumber_D_ID1>23</AckLineNumber_D_ID1>
            <LineExtendedPrice_D_ID8>600.00</LineExtendedPrice_D_ID8>
            <_nd_Item_Number_D_ID3>010765</_nd_Item_Number_D_ID3>
            <DisplayInvoiceNumber_ID42>8729267</DisplayInvoiceNumber_ID42>
            <LineQuantityShipped_D_ID35>1</LineQuantityShipped_D_ID35>
            <AckLine_Freight_ID21>22.64</AckLine_Freight_ID21>
        </Line_Info_S4>
    </Main___F4211_F42119_S1>
    <Main___F4211_F42119_S1>
        <Line_Info_S4>
            <AckLineNumber_D_ID1>24</AckLineNumber_D_ID1>
            <LineExtendedPrice_D_ID8>715.00</LineExtendedPrice_D_ID8>
            <_nd_Item_Number_D_ID3>P10512</_nd_Item_Number_D_ID3>
            <DisplayInvoiceNumber_ID42>8729267</DisplayInvoiceNumber_ID42>
            <LineQuantityShipped_D_ID35>1</LineQuantityShipped_D_ID35>
            <AckLine_Freight_ID21>22.64</AckLine_Freight_ID21>
        </Line_Info_S4>
    </Main___F4211_F42119_S1>
    <Main___F4211_F42119_S1>
        <Line_Info_S4>
            <AckLineNumber_D_ID1>62</AckLineNumber_D_ID1>
            <LineExtendedPrice_D_ID8>630.00</LineExtendedPrice_D_ID8>
            <_nd_Item_Number_D_ID3>016799</_nd_Item_Number_D_ID3>
            <DisplayInvoiceNumber_ID42>8729267</DisplayInvoiceNumber_ID42>
            <LineQuantityShipped_D_ID35>1</LineQuantityShipped_D_ID35>
            <AckLine_Freight_ID21>22.64</AckLine_Freight_ID21>
        </Line_Info_S4>
        <Summary_Info_S8>
            <AckExtendedPrice_T_ID2>5285.00</AckExtendedPrice_T_ID2>
            <Freight_T_ID6>181.12</Freight_T_ID6>
            <GrandTotal_T_ID17>5466.12</GrandTotal_T_ID17>
            <DisplayInvoiceNumber_ID39>8729267</DisplayInvoiceNumber_ID39>
        </Summary_Info_S8>
        <Remit_To_S11>
            <Invoice_No__ID19>Invoice No:</Invoice_No__ID19>
            <DisplayInvoiceNumber_ID18>8729267</DisplayInvoiceNumber_ID18>
            <Service_Charge_Message_ID14>Service charge message...</Service_Charge_Message_ID14>
        </Remit_To_S11>
    </Main___F4211_F42119_S1>
</R5942015>

这是 EDI 所需的输出:

<R5942015>
    <Invoices>
        <InvNumber>8729266</InvNumber>
        <InvoiceDate>2016-04-07</InvoiceDate>
        <ShipmentNumber>169638</ShipmentNumber>
        <ShipDate>2016-04-06</ShipDate>
        <CustomerNumber>10779</CustomerNumber>
        <DealerNumber>44014104</DealerNumber>
        <line>
            <ITEMLineNumber>13</ITEMLineNumber>
            <ITEM2ndItemNumber>010799</ITEM2ndItemNumber>
            <QTYShipped>2</QTYShipped>
            <AMTLineExtendedPrice>1230.00</AMTLineExtendedPrice>
            <AMTLandedFreight>54.78</AMTLandedFreight>
        </line>
        <summary>
            <QTYOrdered>2</QTYOrdered>
            <QTYShipped>2</QTYShipped>
            <AMTLandedFreight>54.78</AMTLandedFreight>
            <AMTExtendedPrice>1230.00</AMTExtendedPrice>
            <AMTGrandTotal>1284.78</AMTGrandTotal>
        </summary>
        <messages>
            <MSGServiceCharge>Service charge message...</MSGServiceCharge>
        </messages>
    </Invoices>
    <Invoices>
        <InvNumber>8729267</InvNumber>
        <InvoiceDate>2016-04-07</InvoiceDate>
        <ShipmentNumber>169638</ShipmentNumber>
        <ShipDate>2016-04-06</ShipDate>
        <CustomerNumber>11005</CustomerNumber>
        <DealerNumber>50857355</DealerNumber>
        <line>
            <ITEMLineNumber>3</ITEMLineNumber>
            <ITEM2ndItemNumber>010512</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>665.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>4</ITEMLineNumber>
            <ITEM2ndItemNumber>010512</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>665.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>5</ITEMLineNumber>
            <ITEM2ndItemNumber>010512</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>715.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>11</ITEMLineNumber>
            <ITEM2ndItemNumber>010512</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>665.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>21</ITEMLineNumber>
            <ITEM2ndItemNumber>016799</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>630.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>23</ITEMLineNumber>
            <ITEM2ndItemNumber>010765</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>600.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>24</ITEMLineNumber>
            <ITEM2ndItemNumber>P10512</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>715.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>62</ITEMLineNumber>
            <ITEM2ndItemNumber>016799</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>630.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <summary>
            <QTYOrdered>8</QTYOrdered>
            <QTYShipped>8</QTYShipped>
            <AMTLandedFreight>181.12</AMTLandedFreight>
            <AMTExtendedPrice>5285.00</AMTExtendedPrice>
            <AMTGrandTotal>5466.12</AMTGrandTotal>
        </summary>
        <messages>
            <MSGServiceCharge>Service charge message...</MSGServiceCharge>
        </messages>
    </Invoices>
</R5942015>

这是我在 XSL 样式表运行时实际得到的。第一张发票的明细行、汇总和消息实际上显示在第二张发票的抬头之后。

<R5942015>
    <Invoices>
        <InvNumber>8729266</InvNumber>
        <InvoiceDate>2016-04-07</InvoiceDate>
        <ShipmentNumber>169638</ShipmentNumber>
        <ShipDate>2016-04-06</ShipDate>
        <CustomerNumber>10779</CustomerNumber>
        <DealerNumber>44014104</DealerNumber>
    </Invoices>
    <Invoices>
        <InvNumber>8729267</InvNumber>
        <InvoiceDate>2016-04-07</InvoiceDate>
        <ShipmentNumber>169638</ShipmentNumber>
        <ShipDate>2016-04-06</ShipDate>
        <CustomerNumber>11005</CustomerNumber>
        <DealerNumber>50857355</DealerNumber>
        <line>
            <ITEMLineNumber>13</ITEMLineNumber>
            <ITEM2ndItemNumber>010799</ITEM2ndItemNumber>
            <QTYShipped>2</QTYShipped>
            <AMTLineExtendedPrice>1230.00</AMTLineExtendedPrice>
        </line>
        <summary>
            <QTYOrdered>2</QTYOrdered>
            <QTYShipped>2</QTYShipped>
            <AMTExtendedPrice>1230.00</AMTExtendedPrice>
            <AMTGrandTotal>1284.78</AMTGrandTotal>
        </summary>
        <messages>
            <MSGServiceCharge>Service charge message...</MSGServiceCharge>
        </messages>
        <line>
            <ITEMLineNumber>3</ITEMLineNumber>
            <ITEM2ndItemNumber>010512</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>665.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>4</ITEMLineNumber>
            <ITEM2ndItemNumber>010512</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>665.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>5</ITEMLineNumber>
            <ITEM2ndItemNumber>010512</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>715.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>11</ITEMLineNumber>
            <ITEM2ndItemNumber>010512</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>665.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>21</ITEMLineNumber>
            <ITEM2ndItemNumber>016799</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>630.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>23</ITEMLineNumber>
            <ITEM2ndItemNumber>010765</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>600.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
        <line>
            <ITEMLineNumber>24</ITEMLineNumber>
            <ITEM2ndItemNumber>P10512</ITEM2ndItemNumber>
            <QTYShipped>1</QTYShipped>
            <AMTLineExtendedPrice>715.00</AMTLineExtendedPrice>
            <AMTLandedFreight>22.64</AMTLandedFreight>
        </line>
    </Invoices>
    <Invoices>
        <summary>
            <QTYOrdered>8</QTYOrdered>
            <QTYShipped>8</QTYShipped>
            <AMTExtendedPrice>5285.00</AMTExtendedPrice>
            <AMTGrandTotal>5466.12</AMTGrandTotal>
        </summary>
        <messages>
            <MSGServiceCharge>Service charge message...</MSGServiceCharge>
        </messages>
     </Invoices>  
</R5942015>    

这就是我想出的样式表,试图绕过格式不正确的 XML。同样,XSL 的新手,所以请放轻松:

<xsl:stylesheet version="2.0"
                xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
                xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
                xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ora="http://schemas.oracle.com/xpath/extension"
                xmlns:ehdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.esb.server.headers.ESBHeaderFunctions"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
                xmlns:orcl="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
                xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
                xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
                exclude-result-prefixes="xsl xs msdata xref xp20 bpws ora ehdr orcl ids hwf">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/R5942015"> 
        <xsl:copy>
            <xsl:for-each-group select="Main___F4211_F42119_S1" group-starting-with="Main___F4211_F42119_S1[Header_S2]">
            <Invoices>
                    <xsl:apply-templates select="current-group()"/>
            </Invoices>
            </xsl:for-each-group>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Main___F4211_F42119_S1[Header_S2]">
            <xsl:if test="Header_S2/InvoiceNumber_ID62"><InvNumber><xsl:value-of select="Header_S2/InvoiceNumber_ID62"/></InvNumber></xsl:if>
            <xsl:if test="Header_S2/InvoiceDate_ID107"><InvoiceDate><xsl:value-of select="Header_S2/InvoiceDate_ID107"/></InvoiceDate></xsl:if>
            <xsl:if test="Header_S2/ShipmentNumber_ID70"><ShipmentNumber><xsl:value-of select="Header_S2/ShipmentNumber_ID70"/></ShipmentNumber></xsl:if>
            <xsl:if test="Header_S2/ShipDate_ID11"><ShipDate><xsl:value-of select="Header_S2/ShipDate_ID11"/></ShipDate></xsl:if>
            <xsl:if test="Header_S2/CustomerNumber_ID92"><CustomerNumber><xsl:value-of select="Header_S2/CustomerNumber_ID92"/></CustomerNumber></xsl:if>
            <xsl:if test="Header_S2/DealerNumber_ID6"><DealerNumber><xsl:value-of select="Header_S2/DealerNumber_ID6"/></DealerNumber></xsl:if>
            <xsl:if test="Line_Info_S4"><line>
                <xsl:if test="Line_Info_S4/AckLineNumber_D_ID1"><ITEMLineNumber><xsl:value-of select="Line_Info_S4/AckLineNumber_D_ID1"/></ITEMLineNumber></xsl:if>
                <xsl:if test="Line_Info_S4/_nd_Item_Number_D_ID3"><ITEM2ndItemNumber><xsl:value-of select="Line_Info_S4/_nd_Item_Number_D_ID3"/></ITEM2ndItemNumber></xsl:if>
                <xsl:if test="Line_Info_S4/LineQuantityShipped_D_ID35"><QTYShipped><xsl:value-of select="Line_Info_S4/LineQuantityShipped_D_ID35"/></QTYShipped></xsl:if>
                <xsl:if test="Line_Info_S4/LineExtendedPrice_D_ID8"><AMTLineExtendedPrice><xsl:value-of select="Line_Info_S4/LineExtendedPrice_D_ID8"/></AMTLineExtendedPrice></xsl:if>
                <xsl:if test="Line_Info_S4/AckLine_Freight_ID21"><AMTLandedFreight><xsl:value-of select="Line_Info_S4/AckLine_Freight_ID21"/></AMTLandedFreight></xsl:if>
            </line></xsl:if>
            <xsl:if test="Summary_Info_S8"><summary>
                <xsl:if test="Summary_Info_S8/AckQuantity_T_ID10"><QTYOrdered><xsl:value-of select="Summary_Info_S8/AckQuantity_T_ID10"/></QTYOrdered></xsl:if>
                <xsl:if test="Summary_Info_S8/QuantityShipped_T_ID13"><QTYShipped><xsl:value-of select="Summary_Info_S8/QuantityShipped_T_ID13"/></QTYShipped></xsl:if>
                <xsl:if test="Summary_Info_S8/LandedFreight_T_ID6"><AMTLandedFreight><xsl:value-of select="Summary_Info_S8/LandedFreight_T_ID6"/></AMTLandedFreight></xsl:if>
                <xsl:if test="Summary_Info_S8/AckExtendedPrice_T_ID2"><AMTExtendedPrice><xsl:value-of select="Summary_Info_S8/AckExtendedPrice_T_ID2"/></AMTExtendedPrice></xsl:if>
                <xsl:if test="Summary_Info_S8/GrandTotal_T_ID17"><AMTGrandTotal><xsl:value-of select="Summary_Info_S8/GrandTotal_T_ID17"/></AMTGrandTotal></xsl:if>
            </summary></xsl:if>
            <xsl:if test="Remit_To_S11"><messages>
                <xsl:if test="Remit_To_S11/Service_Charge_Message_ID14"><MSGServiceCharge><xsl:value-of select="Remit_To_S11/Service_Charge_Message_ID14"/></MSGServiceCharge></xsl:if>
            </messages></xsl:if>
    </xsl:template>

    <xsl:template match="Main___F4211_F42119_S1">
            <xsl:if test="Line_Info_S4"><line>
                <xsl:if test="Line_Info_S4/AckLineNumber_D_ID1"><ITEMLineNumber><xsl:value-of select="Line_Info_S4/AckLineNumber_D_ID1"/></ITEMLineNumber></xsl:if>
                <xsl:if test="Line_Info_S4/_nd_Item_Number_D_ID3"><ITEM2ndItemNumber><xsl:value-of select="Line_Info_S4/_nd_Item_Number_D_ID3"/></ITEM2ndItemNumber></xsl:if>
                <xsl:if test="Line_Info_S4/LineQuantityOrdered_D_ID10"><QTYOrdered><xsl:value-of select="Line_Info_S4/LineQuantityOrdered_D_ID10"/></QTYOrdered></xsl:if>
                <xsl:if test="Line_Info_S4/LineQuantityShipped_D_ID35"><QTYShipped><xsl:value-of select="Line_Info_S4/LineQuantityShipped_D_ID35"/></QTYShipped></xsl:if>
                <xsl:if test="Line_Info_S4/LineExtendedPrice_D_ID8"><AMTLineExtendedPrice><xsl:value-of select="Line_Info_S4/LineExtendedPrice_D_ID8"/></AMTLineExtendedPrice></xsl:if>
                <xsl:if test="Line_Info_S4/AckLine_Freight_ID21"><AMTLandedFreight><xsl:value-of select="Line_Info_S4/AckLine_Freight_ID21"/></AMTLandedFreight></xsl:if>
            </line></xsl:if>
            <xsl:if test="Summary_Info_S8"><summary>
                <xsl:if test="Summary_Info_S8/AckQuantity_T_ID10"><QTYOrdered><xsl:value-of select="Summary_Info_S8/AckQuantity_T_ID10"/></QTYOrdered></xsl:if>
                <xsl:if test="Summary_Info_S8/QuantityShipped_T_ID13"><QTYShipped><xsl:value-of select="Summary_Info_S8/QuantityShipped_T_ID13"/></QTYShipped></xsl:if>
                <xsl:if test="Summary_Info_S8/LandedFreight_T_ID6"><AMTLandedFreight><xsl:value-of select="Summary_Info_S8/LandedFreight_T_ID6"/></AMTLandedFreight></xsl:if>
                <xsl:if test="Summary_Info_S8/AckExtendedPrice_T_ID2"><AMTExtendedPrice><xsl:value-of select="Summary_Info_S8/AckExtendedPrice_T_ID2"/></AMTExtendedPrice></xsl:if>
                <xsl:if test="Summary_Info_S8/GrandTotal_T_ID17"><AMTGrandTotal><xsl:value-of select="Summary_Info_S8/GrandTotal_T_ID17"/></AMTGrandTotal></xsl:if>
            </summary></xsl:if>
            <xsl:if test="Header_S2">
            <xsl:if test="Header_S2/InvoiceNumber_ID62"><InvNumber><xsl:value-of select="Header_S2/InvoiceNumber_ID62"/></InvNumber></xsl:if>
            <xsl:if test="Header_S2/InvoiceDate_ID107"><InvoiceDate><xsl:value-of select="Header_S2/InvoiceDate_ID107"/></InvoiceDate></xsl:if>
            <xsl:if test="Header_S2/ShipmentNumber_ID70"><ShipmentNumber><xsl:value-of select="Header_S2/ShipmentNumber_ID70"/></ShipmentNumber></xsl:if>
            <xsl:if test="Header_S2/ShipDate_ID11"><ShipDate><xsl:value-of select="Header_S2/ShipDate_ID11"/></ShipDate></xsl:if>
            <xsl:if test="Header_S2/CustomerNumber_ID92"><CustomerNumber><xsl:value-of select="Header_S2/CustomerNumber_ID92"/></CustomerNumber></xsl:if>
            <xsl:if test="Header_S2/DealerNumber_ID6"><DealerNumber><xsl:value-of select="Header_S2/DealerNumber_ID6"/></DealerNumber></xsl:if>
            <xsl:if test="Remit_To_S11"><messages>
                <xsl:if test="Remit_To_S11/Service_Charge_Message_ID14"><MSGServiceCharge><xsl:value-of select="Remit_To_S11/Service_Charge_Message_ID14"/></MSGServiceCharge></xsl:if>
            </messages></xsl:if>
    </xsl:template>
</xsl:stylesheet>

感谢您查看此问题。如果您看到我之前关于同一主题的问题,我为问题结构不佳表示歉意。

4

1 回答 1

2

我无法遵循您尝试的 XSLT 的逻辑。我建议您尝试一种不同的方法 - 这是一个框架示例:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:key name="line" match="Line_Info_S4" use="DisplayInvoiceNumber_ID42" />
<xsl:key name="summary" match="Summary_Info_S8" use="DisplayInvoiceNumber_ID39" />
<xsl:key name="remit" match="Remit_To_S11" use="DisplayInvoiceNumber_ID18" />

<xsl:template match="/R5942015">
    <xsl:copy>
        <xsl:apply-templates select="Main___F4211_F42119_S1/Header_S2"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="Header_S2">
    <Invoices>
        <InvNumber>
            <xsl:value-of select="InvoiceNumber_ID62" />
        </InvNumber>
        <!-- more fields here -->
        <xsl:apply-templates select="key('line', InvoiceNumber_ID62)"/>
        <xsl:apply-templates select="key('summary', InvoiceNumber_ID62)"/>
        <xsl:apply-templates select="key('remit', InvoiceNumber_ID62)"/>
    </Invoices>
</xsl:template>

<xsl:template match="Line_Info_S4">
    <line>
        <ITEMLineNumber>
            <xsl:value-of select="AckLineNumber_D_ID1" />
        </ITEMLineNumber>
        <!-- more fields here -->
    </line>
</xsl:template>

<xsl:template match="Summary_Info_S8">
    <summary>
        <!-- more fields here -->
        <AMTGrandTotal>
            <xsl:value-of select="GrandTotal_T_ID17" />
        </AMTGrandTotal>
    </summary>
</xsl:template>

<xsl:template match="Remit_To_S11">
    <messages>
        <MSGServiceCharge>
            <xsl:value-of select="Service_Charge_Message_ID14" />
        </MSGServiceCharge>
    </messages>
</xsl:template>

</xsl:stylesheet>

我在这里假设元素的名称是一致的,并且不会从一个输入任意更改到另一个输入。

于 2016-04-29T22:35:18.070 回答