你能帮我吗?
如果"PackingslipId"-"LineItem"-"Line"有差异,我不希望"HeaderInformation"上有"PackingslidId"one_answers"DeliveryDate"。
如果"LineItem"-"Lines"处的"PackingslipId"始终与"HeaderInformation"处的相同,则输出"PackingslidId"one_answers"DeliveryDate"是可以的。
请注意:(我不认为这很重要;也可以是,只有一篇文章("LineItem"-"Lines"-"OrderLineNum"为1(-在这种情况下,"PackingslipId"与"Line"one_answers"HeaderInformation"相同,因此"PackingslidId"one_answers"DeliveryDate"也应该在"HeaderInformation"one_answers"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>
非常感谢
致以最良好的问候Julian
我认为您只需要将这两个模板添加到XSLT 中
<xsl:template match="HeaderInformation[PackingslipId != LineItem/Lines/PackingslipId]/PackingslipId" />
<xsl:template match="HeaderInformation[PackingslipId != LineItem/Lines/PackingslipId]/DeliveryDate" />
或者,如果你想把这两者结合为一,只需添加这个模板
<xsl:template match="HeaderInformation[PackingslipId != LineItem/Lines/PackingslipId]/*[self::PackingslipId or self::DeliveryDate]" />