你能帮我吗?
如果“ PackingslipId”-“ LineItem”-“行”处存在差异,我不希望“ HeaderInformation”上具有“ PackingslipId”和“ DeliveryDate”。
如果“ Lineing”-“行”上的“ PackingslipId”始终与“ HeaderInformation”上的“ PackingslipId”相同,则输出“ PackingslipId”和“ DeliveryDate”就可以。
请注意:(我不是很重要,也很重要;也可以是,只有一篇文章(“ LineItem”-“ Lines”-带“ OrderLineNum” 1)-在这种情况下,为“ PackingslipId”与“行”和“ HeaderInformation”相同,因此“ PackingslipId”和“ DeliveryDate”也应位于“ HeaderInformation”和“ LineItem”上
我的XML:
<?xml version="1.0" encoding="utf-8"?>
<SALESINVOICE>
<Interchange>
<Recipient></Recipient>
<Sender></Sender>
<CreationDate>2018-11-19:07:06:20</CreationDate>
<Test>No</Test>
<Interchange_Control_Number></Interchange_Control_Number>
<HeaderInformation>
<OrigInvoiceNumber>1</OrigInvoiceNumber>
<InvoiceType>INVOIC</InvoiceType>
<InvoiceDate>2018-11-19</InvoiceDate>
<InvoiceNumber>FV1800087</InvoiceNumber>
<CustomerOrderReference></CustomerOrderReference>
<SalesOrderReference></SalesOrderReference>
<SalesOrderDate>2018-11-15T07:22:01</SalesOrderDate>
<PackingslipId>AV1800097</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<Currency>EUR</Currency>
<TaxExempt></TaxExempt>
<Contact />
<TermsOfPayment>
<PaymTermDescription></PaymTermDescription>
<DueDate></DueDate>
</TermsOfPayment>
<CashDiscountConditions />
<WeightAndVolume>
<NetWeight></NetWeight>
<UnifOfWeight></UnifOfWeight>
</WeightAndVolume>
<SupplierAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<CoRegNum></CoRegNum>
<VATNum></VATNum>
</SupplierAddressInformation>
<BuyerAddressInformation>
<Name></Name>
<Country></Country>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</BuyerAddressInformation>
<InvoiceAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</InvoiceAddressInformation>
<DeliveryAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<State></State>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</DeliveryAddressInformation>
<TransportDetails>
<DeliveryTerms></DeliveryTerms>
</TransportDetails>
<LineItem>
<Lines>
<OrderLineNum>1</OrderLineNum>
<PackingslipId>AV1800097</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>2</OrderLineNum>
<PackingslipId>AV1800098</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>3</OrderLineNum>
<PackingslipId>AV1800099</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>4</OrderLineNum>
<PackingslipId>AV1800099</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
</LineItem>
<Totals>
<InvoiceTotal></InvoiceTotal>
<NetAmount></NetAmount>
<VATAmount></VATAmount>
<DiscountAmount></DiscountAmount>
<AllowanceOrChargeAmount></AllowanceOrChargeAmount>
<DueDate></DueDate>
<VAT>
<VATS>
<Percentage></Percentage>
<Type></Type>
<BaseAmount></BaseAmount>
<VATAmount></VATAmount>
</VATS>
</VAT>
</Totals>
</HeaderInformation>
</Interchange>
</SALESINVOICE>
我的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" standalone="yes" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:key name="header_text" match="HeaderText" use="Text"/>
<xsl:key name="line_text" match="LineText" use="concat(../OrderLineNum, '|', Text)"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- no duplilcate on HeaderText and LineText -->
<xsl:template match="HeaderText[generate-id() != generate-id(key('header_text', Text)[1])]" />
<xsl:template match="LineText[generate-id() != generate-id(key('line_text', concat(../OrderLineNum, '|', Text))[1])]" />
<!-- delete PackingslipId on HeaderInformation, if different at Line -->
<xsl:template match="/salesinvoices/lineItem">
<xsl:choose>
<xsl:when test="
count(lines[not(PackingslipId = preceding-sibling::lines/PackingslipId)]) = 1">
<xsl:copy-of select="//HeaderInformation/PackingslipId"/>
<xsl:copy-of select="//HeaderInformation/DeliveryDate"/>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- delete empty nodes -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>
</xsl:stylesheet>
正确的输出应为:(HeaderInformation上没有PackingslipId且没有DeliveryDate,因为LineItem-PackingslipId有所不同)
<?xml version="1.0" encoding="utf-8"?>
<SALESINVOICE>
<Interchange>
<Recipient></Recipient>
<Sender></Sender>
<CreationDate>2018-11-19:07:06:20</CreationDate>
<Test>No</Test>
<Interchange_Control_Number></Interchange_Control_Number>
<HeaderInformation>
<OrigInvoiceNumber>1</OrigInvoiceNumber>
<InvoiceType>INVOIC</InvoiceType>
<InvoiceDate>2018-11-19</InvoiceDate>
<InvoiceNumber>FV1800087</InvoiceNumber>
<CustomerOrderReference></CustomerOrderReference>
<SalesOrderReference></SalesOrderReference>
<SalesOrderDate>2018-11-15T07:22:01</SalesOrderDate>
<Currency>EUR</Currency>
<TaxExempt></TaxExempt>
<Contact />
<TermsOfPayment>
<PaymTermDescription></PaymTermDescription>
<DueDate></DueDate>
</TermsOfPayment>
<CashDiscountConditions />
<WeightAndVolume>
<NetWeight></NetWeight>
<UnifOfWeight></UnifOfWeight>
</WeightAndVolume>
<SupplierAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<CoRegNum></CoRegNum>
<VATNum></VATNum>
</SupplierAddressInformation>
<BuyerAddressInformation>
<Name></Name>
<Country></Country>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</BuyerAddressInformation>
<InvoiceAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</InvoiceAddressInformation>
<DeliveryAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<State></State>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</DeliveryAddressInformation>
<TransportDetails>
<DeliveryTerms></DeliveryTerms>
</TransportDetails>
<LineItem>
<Lines>
<OrderLineNum>1</OrderLineNum>
<PackingslipId>AV1800097</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>2</OrderLineNum>
<PackingslipId>AV1800098</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>3</OrderLineNum>
<PackingslipId>AV1800099</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>4</OrderLineNum>
<PackingslipId>AV1800099</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
</LineItem>
<Totals>
<InvoiceTotal></InvoiceTotal>
<NetAmount></NetAmount>
<VATAmount></VATAmount>
<DiscountAmount></DiscountAmount>
<AllowanceOrChargeAmount></AllowanceOrChargeAmount>
<DueDate></DueDate>
<VAT>
<VATS>
<Percentage></Percentage>
<Type></Type>
<BaseAmount></BaseAmount>
<VATAmount></VATAmount>
</VATS>
</VAT>
</Totals>
</HeaderInformation>
</Interchange>
</SALESINVOICE>
非常感谢
最好的问候 朱利安答案 0 :(得分:1)
我认为您只需要将这两个模板添加到XSLT
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle",
"Acme\\TopBundle\\": "src/Acme/TopBundle", //add
"Acme\\UserBundle\\": "src/Acme/UserBundle", //add
"Acme\\MemberBundle\\": "src/Acme/MemberBundle", //add
"Acme\\AdminBundle\\": "src/Acme/AdminBundle" //add
},
或者,如果您要将这两部分合而为一,只需添加此模板
<xsl:template match="HeaderInformation[PackingslipId != LineItem/Lines/PackingslipId]/PackingslipId" />
<xsl:template match="HeaderInformation[PackingslipId != LineItem/Lines/PackingslipId]/DeliveryDate" />